Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

VIN Checkdigit Calculation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    VIN Checkdigit Calculation

    Vehicle Identificaton Numbers consist of 17 numbers and letters. The ninth position in the VIN is a check digit to insure that the VIN is valid. I would like to incorporate this check digit into field rules to insure accurate data entry. Right now I am requiring duplicate entry but using the check digit would be more elegant.

    The problem is that the check digit computation is quite convoluted. First each letter in the VIN must be converted to a numerical value. Then each number is multiplied by a weight factor based upon its position in the VIN. Then the all of the results are added and the total us divided by 11. The remainder is the Check Digit. Whew.
    (I found the detailed instructions in Wikipedia.)

    Has anyone devised a way to do this in Alpha?

    #2
    Re: VIN Checkdigit Calculation

    The Similar Threads link at the bottom of this post, and a search, indicate that no one has posted a user defined function to do this. A udf is the usual method to perform this sort of calculation.

    See what this does for you (meets USA-Canada specifications I believe)

    Code:
    FUNCTION vin_chk AS C (vin AS C )
    	IF len(alltrim(vin))<>17
    		vin_chk = ""
    		exit function
    	END IF
    	in = "a,b,c,d,e,f,g,h,j,k,l,m,n,p,r,s,t,u,v,w,x,y,z"
    	in = stritran(in,",",crlf())
    	out = "1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8"
    	out = stritran(out,",",crlf())
    	vin_val = stritran_multi(vin,in,out)
    	vin_val = mask(vin_val," , , , , , , , , , , , , , , , , ")
    	vin_wt = "8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2"
    	prodsum = 0
    	FOR i =1 TO 8
    		prodsum = prodsum+(val(word(vin_val,i))*val(word(vin_wt,i)))
    	NEXT i
    	FOR x =10 TO 17
    		prodsum = prodsum+(val(word(vin_val,x))*val(word(vin_wt,x)))
    	NEXT x
    	rslt = mod(prodsum,11)
    	vin_chk = if(rslt<10,alltrim(str(rslt)),"X")
    END FUNCTION
    Usage is

    Code:
    ? vin_chk("1M8GDM9A*KP042788")
    = "X"
    where the * can be anything. In a validation situation I think you would want to test for

    substr(somevinnumber,9,1) = vin_chk(somevinnumber)
    Last edited by Stan Mathews; 02-22-2007, 03:32 PM. Reason: corrected function
    There can be only one.

    Comment


      #3
      Re: VIN Checkdigit Calculation

      Wow! You are the man! It seems to work perfectly. My only question is: did you cobble that together on the fly, or did you have that stashed away somewhere in you bag of tricks?

      Thanks!

      Comment


        #4
        Re: VIN Checkdigit Calculation

        Originally posted by NickH214 View Post
        Wow! You are the man! It seems to work perfectly. My only question is: did you cobble that together on the fly, or did you have that stashed away somewhere in you bag of tricks?

        Thanks!
        Knocking that out was just something to do during/instead of lunch.
        There can be only one.

        Comment


          #5
          Re: VIN Checkdigit Calculation

          Holly mac!..
          I never knew VIN has this many information! I thought it's just like a number on a cereal box!

          It's like the DNA of a car!

          I ignore the board for a couple of days and someone sneaks in a pretty slick question!

          Allright then, how about this "simple" approach:
          Code:
          dim vin as c="1m8GDM9AXKP042788"
          dim x as c="abcdefgh jklmn p r stuvwxyz"
          dim y as c="123456789X"
          
          ?if(substr(y,mod(8*(mod(atc(substr(vin,1,1),x),9)+at(substr(vin,1,1),y)+mod(atc(substr(vin,11,1),x),9) +at(substr(vin,11,1),y))+7*(mod(atc(substr(vin,2,1),x),9) +at(substr(vin,2,1),y)+mod(atc(substr(vin,12,1),x),9) +at(substr(vin,12,1),y))+6*(mod(atc(substr(vin,3,1),x),9) +at(substr(vin,3,1),y)+mod(atc(substr(vin,13,1),x),9)+at(substr(vin,13,1),y))+5*(mod(atc(substr(vin,4,1),x),9) +at(substr(vin,4,1),y)+mod(atc(substr(vin,14,1),x),9) +at(substr(vin,14,1),y))+4*(mod(atc(substr(vin,5,1),x),9) +at(substr(vin,5,1),y)+mod(atc(substr(vin,15,1),x),9) +at(substr(vin,15,1),y))+3*(mod(atc(substr(vin,6,1),x),9) +at(substr(vin,6,1),y)+mod(atc(substr(vin,16,1),x),9) +at(substr(vin,16,1),y))+2*(mod(atc(substr(vin,7,1),x),9)+at(substr(vin,7,1),y)+mod(atc(substr(vin,17,1),x),9) +at(substr(vin,17,1),y))+10*mod(atc(substr(vin,8,1),x),9) +at(substr(vin,8,1),y)+9*mod(atc(substr(vin,10,1),x),9)+at(substr(vin,10,1),y),11),1)=substr(vin,9,1),"Valid VIN","Invalid VIN")
          = "Valid VIN"
          Last edited by G Gabriel; 02-23-2007, 04:04 AM.

          Comment


            #6
            Re: VIN Checkdigit Calculation

            ..and.. another approach:

            Put this code on your OnDepart event of the VIN field

            Code:
            dim x as c="abcdefgh jklmn p r stuvwxyz"
            dim y as c="123456789X"
            dim z as n=8
            dim vt as n=0
            while z>1 
            vt=vt+z*(mod(atc(substr(vin->vin,9-z,1),x),9)+at(substr(vin->vin,9-z,1),y)+mod(atc(substr(vin->vin,19-z,1),x),9) +at(substr(vin->vin,19-z,1),y))
            z=z-1
            end while
            if substr(y,mod(var->vt+10*mod(atc(substr(vin->vin,8,1),x),9)+at(substr(vin->vin,8,1),y)+9*mod(atc(substr(vin->vin,10,1),x),9)+at(substr(vin->vin,10,1),y),11),1)substr(vin->vin,9,1)
            	ui_msg_box("Caution.............!","Invalid VIN number....",UI_OK+ UI_FIRST_BUTTON_DEFAULT+ UI_STOP_SYMBOL)
            	end if
            Last edited by G Gabriel; 02-23-2007, 07:13 AM.

            Comment


              #7
              Re: VIN Checkdigit Calculation

              ..something like this..

              I believe there is one more simpler approach lurking in the back of my mind, but, I am out of caffeine right now..
              Last edited by G Gabriel; 05-11-2007, 05:16 AM.

              Comment


                #8
                Re: VIN Checkdigit Calculation

                Hi all,

                I just found out some interesting information that will affect the scripts in this thread.



                ....the Year of the vehicle is the 8th character from the RIGHT which is the
                10th char from the LEFT.

                it has to be changed as the years go by.
                For instance, few know that the VIN allowance is actually 22 chars., not the

                17 we all use for the last 27 yrs. So, conceivably it could become 18-22 chars long.

                They do not use zeros for the Yr Char, Just O's. Anyway, the 2000 was "Y" and (Z was skipped as a confusion for 2) then the 2001 began numeric @ 1. We've been on the #=the Year ever since

                Prior to that, the Alphabet was used beginning in 1980 when this all started
                with "A"=1980. Some Alpha's were skipped because they could be confused as numeric in the field, such as I, O, etc.
                So, we'll likely see an add'l character added beginning in 2010....


                Tom McCann
                Just thought those of you who are using VIN numbers in their applications should be aware of this so as not to caught off gaurd when it happens (less than 2 years as 2008 cars are now being produced!).
                Mike
                __________________________________________
                It is only when we forget all our learning that we begin to know.
                It's not what you look at that matters, it's what you see.
                Henry David Thoreau
                __________________________________________



                Comment


                  #9
                  Re: VIN Checkdigit Calculation

                  Here's something I used for a number of years but it was last used in July 2000 in A5v4. I'm certain that it worked for Chrysler vehicles because it was used regularly for at least 3 years for the warranty reports I had to supply them. That was before commands like stritran() and others even existed so the code is rather clumsy by today's standard. Also, since my script was written for A5v4, the arrays use parenthesis rather than square brackets.

                  I only present it to show some other checks I found necessary to protect data entry and/or to make it easier. (Calculating things in a database is easy. Making it work as easily as possible for users who often enter bad data is the tricky part.)

                  Putting the calculation itself into a user defined function as Stan did is a much better idea. (But I did write it about 10 years ago so I have learned a bit since then.)

                  This script was used in the CanWrite event of the VIN field.
                  Code:
                  DIM SHARED a_field_value as c
                  DIM VIN(17) as c
                  DIM av(17) as n
                  DIM w(17) as n
                  DIM p(17) as n
                  '--- THIS SCRIPT IS TO VERIFY THE CHRYSLER  VIN NUMBER
                  FUNCTION value_assigned as n ( vin_in as c )
                   IF val( vin_in ) > 0
                    value_assigned = val( vin_in )
                   ELSE
                    SELECT
                    CASE ut( vin_in ) = "0"
                     value_assigned = 0
                    CASE ut( vin_in ) = "A"
                     value_assigned = 1
                    CASE ut( vin_in ) = "B"
                     value_assigned = 2
                    CASE ut( vin_in ) = "C"
                     value_assigned = 3
                    CASE ut( vin_in ) = "D"
                     value_assigned = 4
                    CASE ut( vin_in ) = "E"
                     value_assigned = 5
                    CASE ut( vin_in ) = "F"
                     value_assigned = 6
                    CASE ut( vin_in ) = "G"
                     value_assigned = 7
                    CASE ut( vin_in ) = "H"
                     value_assigned = 8
                    CASE ut( vin_in ) = "J"
                     value_assigned = 1
                    CASE ut( vin_in ) = "K"
                     value_assigned = 2
                    CASE ut( vin_in ) = "L"
                     value_assigned = 3
                    CASE ut( vin_in ) = "M"
                     value_assigned = 4
                    CASE ut( vin_in ) = "N"
                     value_assigned = 5
                    CASE ut( vin_in ) = "P"
                     value_assigned = 7
                    CASE ut( vin_in ) = "R"
                     value_assigned = 9
                    CASE ut( vin_in ) = "S"
                     value_assigned = 2
                    CASE ut( vin_in ) = "T"
                     value_assigned = 3
                    CASE ut( vin_in ) = "U"
                     value_assigned = 4
                    CASE ut( vin_in ) = "V"
                     value_assigned = 5
                    CASE ut( vin_in ) = "W"
                     value_assigned = 6
                    CASE ut( vin_in ) = "X"
                     value_assigned = 7
                    CASE ut( vin_in ) = "Y"
                     value_assigned = 8
                    CASE ut( vin_in ) = "Z"
                     value_assigned = 9
                    END SELECT
                   END IF
                  END FUNCTION
                  '--------------------------------------------------------------
                  ' CHECK LENGTH OF VIN NUMBER AND WARN IF UNUSUAL.
                  '--------------------------------------------------------------
                  field_length = len( trim( a_field_value ))
                  IF field_length > 10 .and. field_length < 17
                   ui_beep()
                   ui_msg_box( "*** WARNING ***", "Unusual VIN length of " + ltrim(str(field_length)) + " characters.  CORRECT IF NECESSARY.", 48 )
                  ELSE IF field_length > 17
                   ui_beep()
                   ui_msg_box( "*** WARNING ***", "VIN length of " + ltrim(str(field_length)) + " characters is greater than the normal max of 17 characters.  PLEASE VERIFY & CORRECT IF NECESSARY.", 48 )
                  ELSE IF field_length = 9
                   ui_beep()
                   ui_msg_box( "*** WARNING ***", "VIN length of 9 characters means that the first character is only a check digit.  PLEASE VERIFY & CORRECT IF NECESSARY.", 48 )
                  END IF
                  '--------------------------------------------------------------
                  ' ADDITIONAL CHECKS REQUIRE THE FULL 17 CHARACTER VIN.
                  '--------------------------------------------------------------
                  IF len(trim( a_field_value )) <> 17
                   END
                  END IF
                   
                  DIM sum as n
                  sum = 0
                  FOR x = 1 to 17
                   vin(x) = substr( a_field_value, x, 1 )
                   av(x) = value_assigned( VIN(x) )
                   SELECT
                   CASE x < 10
                    w(x) = 9 - x
                   CASE x >= 10
                    w(x) = 19 - x
                   END SELECT
                   IF w(x) = 1
                    w(x) = 10
                   END IF
                   p(x) = av(x) * w(x)
                   sum = sum + p(x)
                  'ui_msg_box( "Position "+ltrim(str(x)), "Char=" + VIN(x)+": Value="+ltrim(str(av(x)))+": Weight="+ltrim(str(w(x)))+": Product="+ltrim(str(p(x)))+": Sum="+ltrim(str(sum)) )
                  NEXT x
                  test = mod( sum, 11 )
                  'ui_msg_box( "TEST VALUE", ltrim(str( test )) )
                  'ui_msg_box( "VIN VALUE", ltrim(str( val(VIN(9) )) ))
                  IF test <> val( VIN(9) )
                   FOR x = 1 to 50
                    ui_beep()
                   NEXT x
                   ui_msg_box( "*** WARNING *** VIN ERROR", "This VIN number is not correct.  The check digit does not match the calculated value.", 16 )
                  END IF
                  END'

                  Comment


                    #10
                    Re: VIN Checkdigit Calculation

                    I just run the VinChecker & if it's ok I fill a calc field with "VIN OK" in Green/White.
                    If it fails I fill it with "VIN Error" in Red/White then force them back to the VIN fields.
                    I help them by splitting the VIN into 2 (9 & 8 chr) Fields & applied different colors to the input values, and it auto-advanced to the 2nd field so they never realized it was 2 fields.
                    Still do.
                    I have no idea what the VIN was on my first car that I paid cash for ($40); could a been "48PLY4D6CYL" for all I know.
                    Nah, too explicit.
                    First Love

                    Comment


                      #11
                      Re: VIN Checkdigit Calculation

                      Really really dumb question.....

                      Is there an EASY way to copy the code snippets that appear in these newsgroup posts??

                      Really nice looking, and the scroll is a nice touch, but very hard to copy code to notepad????

                      TIA, keep up the GOOD work!

                      Bill
                      Regards from Washington State,
                      Bill
                      Licensed NERD

                      Comment


                        #12
                        Re: VIN Checkdigit Calculation

                        click and drag then ctrl-v??

                        Comment

                        Working...
                        X