Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    15

    Unanswered: Validating Car rag in access.

    I have got a project to do, and I am having problems with the one area. I want to be able to validate te reg plate fo a car but in one fiel. I can do it in several but all the letters have different rules. I was wondering if anyone could tell me hwo to do it.
    Rules are as follows.
    1st Letter: no I,J,Q,T,U,Z,
    2nd Letter: no I,Q,Z,
    Don't worry about number.
    Last 3 characters: No I or Z
    They only ahve to validate new style reg plte.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Ok, so all you have to do is return true or false as to whether a given string matches your criteria?

    The overview is pretty basic. I would create a public function, most likely in a seperate module so you may call it from anywhere OR reuse it in any application, that's just good programming.

    The function is going to return true or false.

    So what needs to happen to get true or false? You have to evaluate each character of a given string. Therefore it needs to accept a string argument.

    Enough of that:

    Code:
    Public Function ValidatePlate(s As String) As Boolean
    Dim IsValid As Boolean
    Dim Arr As Variant
    'Standard "Priming Variables 101" stuff
    IsValid = True
    Arr = Array("I", "J", "Q", "T", "U", "Z")
    
    'Evaluate the first character and set return value to false if it fails
    For i = 0 To UBound(Arr)
        If Left(s, 1) = Arr(i) Then IsValid = False
    Next i
    
    'Here you could reinitialize your array to contain values for the second char
    'Then you would write another for loop to set your boolean flag to False
    'if the test fails.  Use the MID() function to return the character required.
    
    ValidatePlate = IsValid
    
    End Function
    Last edited by Teddy; 05-03-04 at 10:51.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Teddy: are you going to torture me with that bloody signature forever?

    meanwhile, your array solution works but does a lot of looping.

    since you are torturing me, i am obliged to come up with a counter suggestion:

    if instr("IJQTUZ", left$(nz([testPlateNumber]," "), 1)) > 0 then 'bad news

    if instr("IQZ", mid$(nz([testPlateNumber]," "), 2,1)) > 0 then 'bad news

    if instr("IZ", right$(nz([testPlateNumber]," "), 1)) > 0 then 'bad news

    izy
    currently using SS 2008R2

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Nice!

    Much cleaner solution.



    PS: Happy Monday!!
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •