Connecting Tech Pros Worldwide Help | Site Map

VBA reference question

David
Guest
 
Posts: n/a
#1: Nov 13 '05
I am trying to create a function that will test certian criteria of a field
and return the corisponding code that i have set for example:

Function NIXIECode(str As String) As String

Dim num As Integer
Dim Code1 As String
Dim Code2 As String
Dim Code3 As String

num = 1
Code = "Code"
Code1 = "House Number Missing"
Code2 = "First Name Does Not Match"
Code3 = "Surnames Do Not Match"

Do While num < 24

If Mid(str, num, 1) <> " " Then NIXIECode = "Code" & num

num = num + 1

Loop

My problem is in the "Then" statement. I want NIXIECode to equal the codes
that I have set and not "Code1". What syntax do I need to use? I hope this
is clear and thatnks in advance.

David


MGFoster
Guest
 
Posts: n/a
#2: Nov 13 '05

re: VBA reference question


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


You could use an array of Code(1-3) instead of separate variables for
each code. E.g.:

Dim num As Integer
Dim Code(1-3) As String

Code = "Code"
Code(1) = "House Number Missing"
Code(2) = "First Name Does Not Match"
Code(3) = "Surnames Do Not Match"

' ... you'll have to assign Code(4) thru Code(23) since the
' loop goes up to num = 23.

num = 1

Do While num < 24

If Mid(str, num, 1) <> " " Then
NIXIECode = Code(num)
Exit Do ' once found you don't need to loop anymore
End If

num = num + 1

Loop

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQQ59kIechKqOuFEgEQITswCfZtju0m3xJMCrhb6Gn0oF2m 9EAR8AnRFZ
fxNzYCuuIl4B8Srl1X/6ds3j
=08Cr
-----END PGP SIGNATURE-----


David wrote:[color=blue]
> I am trying to create a function that will test certian criteria of a field
> and return the corisponding code that i have set for example:
>
> Function NIXIECode(str As String) As String
>
> Dim num As Integer
> Dim Code1 As String
> Dim Code2 As String
> Dim Code3 As String
>
> num = 1
> Code = "Code"
> Code1 = "House Number Missing"
> Code2 = "First Name Does Not Match"
> Code3 = "Surnames Do Not Match"
>
> Do While num < 24
>
> If Mid(str, num, 1) <> " " Then NIXIECode = "Code" & num
>
> num = num + 1
>
> Loop
>
> My problem is in the "Then" statement. I want NIXIECode to equal the codes
> that I have set and not "Code1". What syntax do I need to use? I hope this
> is clear and thatnks in advance.[/color]

Closed Thread