Split A Value and then perfom Test

Johnkl

New member
Local time
Today, 02:36
Joined
Aug 29, 2002
Messages
28
Hi everyone

I was wondering if anyone can help me with this.

I have a field called AFM which value is always 9 digits length.

I want to
1st : to reverse the order of the numbers
2nd: to multiply each value
3rd : to sum the muliplication
4th : to divide the sum
5th : to do a check to the division

an example is like this
AFM = 012345678

1st:8
2nd : 8*0=0
1st:7
2nd:7*2=14
1st:6
2nd:6*4=24
1st:5
2nd 5*8=40
1st:4
2nd:4*16=64
1st:3
2nd:3*32=96
1st:2
2nd:2*64=128
1st:1
2nd:1*128=128
1st:0
2nd:0*256=0

3rd :=Sum(0+14+24+40+64+96+128+128+0)=494
4th :494/11=44.90909
5th:44.90909*11=494
6th: If(5th<=4th);If(3rd-5th)=1stMyltiplyNo Then Correct else wrong)

Can anyone help me out?

Kind regards
John
 
I want to evaluate if the AFM number is correct or not.

Kind regards
 
Hi

still not quite sure why you need to do this but ...

1. convert number to a string and use VBA to reverse it one char at a time

2. carry out calcs as required

good luck
 
Hi

still not quite sure why you need to do this but ...

1. convert number to a string and use VBA to reverse it one char at a time

2. carry out calcs as required

good luck



Look the AFM is a number given from the authorities and this is the algorithm to evaluate if the number is correct...
I'm not sure about the below code because I'm getting an error Type Mismatch

Private Sub AFM_BeforeUpdate(Cancel As Integer)
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
Dim ANo As Integer
Dim BNo As Integer
Dim CNo As Integer
Dim DNo As Integer
Dim ENo As Integer
Dim FNo As Integer
Dim GNo As Integer
Dim HNo As Integer
Dim INo As Integer
Dim Multiply As Integer
Dim Divide As Integer
Dim Mult1stNo As Integer
Dim Mult2ndNo As Integer
Dim Mult3rdNo As Integer
Dim Mult4thNo As Integer
Dim Mult5thNo As Integer
Dim Mult6thNo As Integer
Dim Mult7thNo As Integer
Dim Mult8thNo As Integer
Dim Mult9thNo As Integer
Dim SumMult As Integer


ANo = Mid(Me.AFM, 9, 1)
BNo = Mid(Me.AFM, 9 - 1)
CNo = Mid(Me.AFM, 9 - 2)
DNo = Mid(Me.AFM, 9 - 3)
ENo = Mid(Me.AFM, 9 - 4)
FNo = Mid(Me.AFM, 9 - 5)
GNo = Mid(Me.AFM, 9 - 6)
HNo = Mid(Me.AFM, 9 - 7)
INo = Mid(Me.AFM, 9 - 8)

Mult1stNo = ANo * 0
Mult2ndNo = BNo * 2
Mult3rdNo = CNo * 4
Mult4thNo = DNo * 8
Mult5thNo = ENo * 16
Mult6thNo = FNo * 32
Mult7thNo = GNo * 64
Mult8thNo = HNo * 128
Mult9thNo = INo * 256

SumMult = Mult1stNo + Mult2ndNo + Mult3rdNo + Mult4thNo + Mult5thNo + Mult6thNo + Mult7thNo + Mult8thNo + Mult9thNo
Multiply = SumMult * 11
Divide = Multiply / 11


If (Multiply <= Divide) And (SumMult = Mult1stNo) Then

strMsg = "Ôï ÁÖÌ åéíáé ëáíèáóìÝíï."
intStyle = vbOKOnly
strTitle = "Can't Delete Record"
MsgBox strMsg, intStyle, strTitle
Cancel = True
End If


End Sub
 
The key that would help is to know WHERE it stops and gives you that error (the line should be highlighted in yellow). If you can tell us where that error is occuring we might be able to tell you why it's occuring.
 
Is the field that is associated with Me.AFM an number or text?
 
Give this a shot instead:

ANo=CInt(Mid(Me.AFM,9,1))
 

Users who are viewing this thread

Back
Top Bottom