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

IMEI checksum help

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

    IMEI checksum help

    hi to all,

    i have a code from visual basic that i would like to convert to xbasic but i dont know how to. here is the code...

    Code:
    Function Checksum(IMEI)
      On Error Resume Next
      Table = Array(Array(0, 8, 6, 4, 2, 9, 7, 5, 3, 1), Array(0, 9, 8, 7, 6, 5, 4, 3, 2, 1))
      Position = 1
      For I = 1 To 14
      Checksum = Checksum + Table(Position)(Mid(IMEI, I, 1))
    
      If Position = 1 Then
         Position = 0
      Else
         Position = 1
      End If
      Next I
     
      Do While Checksum >= 10
      Checksum = Checksum - 10
      Loop
    
    End Function
    if there's anyone on the board that has a working IMEI checksum function, please help.

    or someone who can convert the above vb code to xbasic

    thanks a lot in advance
    Francis

    #2
    Re: IMEI checksum help

    Here is a sample function:
    Code:
    FUNCTION IMEI_Valid AS L (IMEI AS C )
    ln=len(IMEI)
    dim x as c=""
    for i=1 to ln
    x=x+substr(IMEI,i,1)+crlf()
    next
    x=crlf_to_comma(x)
    x=*reverse_words(x,",")
    dim k as n
    dim cksm as n
    for i=1 to ln
    	k=val(word(x,i,","))
    	cksm=cksm+if(mod(i,2)=0,k*2,k)
    	next
    IMEI_Valid=if(mod(cksm,10)=0,.t.,.f.)
    END FUNCTION
    Code:
    ?imei_valid("1234567890")
    = .T.

    Comment


      #3
      Re: IMEI checksum help

      hi gabriel,

      thanks for the sample...
      i tried testing the sample with a valid imei, it gave a false result.

      here is the detailed instructions on how to compute the 15th digit of the imei that i took from a forum i searched on the net.

      Code:
      The last number of the IMEI is called the Check Digit and is defined using a formula 
      called "Luhn formula", thus sometimes the last digit is called the Luhn Check Digit and 
      does not necessarily always set to 0.
      
      This check digit is computed in three steps as follows:
      
      Given:
      14 most significant digits of the IMEISV without the SVN which are the 
      6-digit TAC, 
      2-digit FAC, 
      6-digit SNR and are labelled as follows:
      
      TAC = D14 D13 ... D9 (with D9 the least significant digit of TAC);
      FAC = D8 D7 (with D7 the least significant digit of FAC); and
      SNR = D6 D5 ... D1 (with D1 the least significant digit of SNR).
      
      Example IMEI: [ 490154 20 323751 ? ] (ignore the last digit)
      
      FAC: 490154
      
      D14:4
      D13:9
      D12:0
      D11:1
      D10:5
      D09:4
      ----------
      TAC: 20
      
      D08:2
      D07:0
      ----------
      SNR: 323751
      
      D06:3
      D05:2
      D04:3
      D03:7
      D02:5
      D01:1
      
      CHK: ?
      
      Computation of CHK from the IMEI proceeds as follows:
      ================================================== ====
      
      Step 1: 
      Double the values of the odd labelled digits D1, D3, D5 ... D13 of the IMEI.
      490154 20 323751
      ------------------
      .D14:4=4
      *D13:9x2=18
      .D12:0=0
      *D11:1x2=2
      .D10:5=5
      *D09:4x2=8
      .D08:2=2
      *D07:0x2=0
      .D06:3=3
      *D05:2x2=4
      .D04:3=3
      *D03:7x2=14
      .D02:5=5
      *D01:1x2=2
      //================================================== ============================
      Step 2: Add together the individual digits of all the seven numbers obtained in 
      Step 1,
      
      1+8 + 2 + 8 + 0 + 4 + 1+4 + 2 = 30
      
      and then add this sum to the sum of all the even labelled digits 
      D2, D4, D6 ... D14 of the IMEI.
      4 + 0 + 5 + 2 + 3 + 3 + 5 = 22
      
      The result is:
      30 + 22 = 52
      or
      4 + 1+8 + 0 + 2 + 5 + 8 + 2 + 0 + 3 + 4 + 3 + 1+4 + 5 + 2 = 52
      //================================================== ===========================
      Step 3: If the number obtained in Step 2 ends in 0, then set CHK to be 0. 
      If the number obtained in Step 2 does not end in 0, then set CHK to be 
      that number subtracted from the next higher number which does end in 0.
      
      Since 52 ends in "2", CHK can't be set to "0". The next higher number that does 
      end in "0" after 52 is 60, so we set:
      
      CHK = 60 - 52 = 8
      
      So the IMEI number is: 490154203237518 and it ends in 8.
      
      P.S. The IMEI number sampled above is fictios and does not reflect nor intended for
      an existing IMEI number.
      here is a valid imei: 352526032177436

      can you try to convert this again in xbasic?
      i will try also to convert this based on your first function.

      tia
      Francis

      Comment


        #4
        Re: IMEI checksum help

        I meant this only as a sample for you to modify according to whichever formula is used.
        When I get a little more time, I will apply our formula.

        Comment


          #5
          Re: IMEI checksum help

          hi to all,

          gabriel, thanks for the sample code.

          i came up with this function based on posted pseudo code.

          Code:
          'Date Created: 01-Aug-2010 01:09:31 PM
          'Last Updated: 16-Aug-2010 01:37:53 PM
          'Created By  : fdd
          'Updated By  : fdd
          
          FUNCTION IMEI_Valid AS L (IMEI AS C)
          
          	dim ln as n = 0
          	dim d1 as n = 0
          	dim d2 as n = 0
          	dim d3 as n = 0
          	dim d4 as n = 0
          	dim d5 as n = 0
          	dim d6 as n = 0
          	dim d7 as n = 0
          	dim d8 as n = 0
          	dim d9 as n = 0
          	dim d10 as n = 0
          	dim d11 as n = 0
          	dim d12 as n = 0
          	dim d13 as n = 0
          	dim d14 as n = 0
          	dim d15 as n = val(substr(IMEI,15,1))
          	dim x as c=""	
          	
          	ln = len(imei)-1
          	for i=1 to ln
          	x=substr(IMEI,i,1)
          
          	if i = 1 then
          	    d1 = val(x)
          	elseif i = 2 then
          		d2 = val(x)
          	elseif i = 3 then
          		d3 = val(x)
          	elseif i = 4 then
          		d4 = val(x)
          	elseif i = 5 then
          		d5 = val(x)
          	elseif i = 6 then
          		d6 = val(x)
          	elseif i = 7 then
          		d7 = val(x)
          	elseif i = 8 then
          		d8 = val(x)
          	elseif i = 9 then
          		d9 = val(x)
          	elseif i = 10 then
          		d10 = val(x)
          	elseif i = 11 then
          		d11 = val(x)
          	elseif i = 12 then
          		d12 = val(x)
          	elseif i = 13 then
          		d13 = val(x)
          	elseif i = 14 then
          		d14 = val(x)
          	end if
          	
          	next
          	
          	d1 = d1 * 2
          	d3 = d3 * 2
          	d5 = d5 * 2
          	d7 = d7 * 2
          	d9 = d9 * 2
          	d11 = d11 * 2
          	d13 = d13 * 2
          
          	dim vFinal as n
          
          	if len(alltrim(str(d1))) = 2 then	
          	    dim dtmp as c = ""
          		dim dtmp1 as c = ""
          		dim dtmp2 as c = ""
          		dim fin1 as n
          		dim fin2 as n
          		dim tmpfinal as n		
          		if len(alltrim(str(d1))) then
          			dtmp = alltrim(str(d1))
          			dtmp1 = substr(dtmp,1,1)
          			dtmp2 = substr(dtmp,2,1)
          			tmpfinal = val(dtmp1) + val(dtmp2)
          			d1 = tmpfinal
          		end if 
          	elseif len(alltrim(str(d3))) = 2 then
          	    dim dtmp as c = ""
          		dim dtmp1 as c = ""
          		dim dtmp2 as c = ""
          		dim fin1 as n
          		dim fin2 as n
          		dim tmpfinal as n		
          		if len(alltrim(str(d3))) then
          			dtmp = alltrim(str(d3))
          			dtmp1 = substr(dtmp,1,1)
          			dtmp2 = substr(dtmp,2,1)
          			tmpfinal = val(dtmp1) + val(dtmp2)
          			d3 = tmpfinal
          		end if 
          	elseif len(alltrim(str(d5))) = 2 then
          	    dim dtmp as c = ""
          		dim dtmp1 as c = ""
          		dim dtmp2 as c = ""
          		dim fin1 as n
          		dim fin2 as n
          		dim tmpfinal as n		
          		if len(alltrim(str(d5))) then
          			dtmp = alltrim(str(d5))
          			dtmp1 = substr(dtmp,1,1)
          			dtmp2 = substr(dtmp,2,1)
          			tmpfinal = val(dtmp1) + val(dtmp2)
          			d5 = tmpfinal
          		end if 
          	elseif len(alltrim(str(d7))) = 2 then
          	    dim dtmp as c = ""
          		dim dtmp1 as c = ""
          		dim dtmp2 as c = ""
          		dim fin1 as n
          		dim fin2 as n
          		dim tmpfinal as n		
          		if len(alltrim(str(d7))) then
          			dtmp = alltrim(str(d7))
          			dtmp1 = substr(dtmp,1,1)
          			dtmp2 = substr(dtmp,2,1)
          			tmpfinal = val(dtmp1) + val(dtmp2)
          			d7 = tmpfinal
          		end if 
          	elseif len(alltrim(str(d9))) = 2 then
          	    dim dtmp as c = ""
          		dim dtmp1 as c = ""
          		dim dtmp2 as c = ""
          		dim fin1 as n
          		dim fin2 as n
          		dim tmpfinal as n		
          		if len(alltrim(str(d9))) then
          			dtmp = alltrim(str(d9))
          			dtmp1 = substr(dtmp,1,1)
          			dtmp2 = substr(dtmp,2,1)
          			tmpfinal = val(dtmp1) + val(dtmp2)
          			d9 = tmpfinal
          		end if 
          	elseif len(alltrim(str(d11))) = 2 then
          	    dim dtmp as c = ""
          		dim dtmp1 as c = ""
          		dim dtmp2 as c = ""
          		dim fin1 as n
          		dim fin2 as n
          		dim tmpfinal as n		
          		if len(alltrim(str(d11))) then
          			dtmp = alltrim(str(d11))
          			dtmp1 = substr(dtmp,1,1)
          			dtmp2 = substr(dtmp,2,1)
          			tmpfinal = val(dtmp1) + val(dtmp2)
          			d11 = tmpfinal
          		end if 
          	elseif len(alltrim(str(d13))) = 2 then
          	    dim dtmp as c = ""
          		dim dtmp1 as c = ""
          		dim dtmp2 as c = ""
          		dim fin1 as n
          		dim fin2 as n
          		dim tmpfinal as n		
          		if len(alltrim(str(d13))) then
          			dtmp = alltrim(str(d13))
          			dtmp1 = substr(dtmp,1,1)
          			dtmp2 = substr(dtmp,2,1)
          			tmpfinal = val(dtmp1) + val(dtmp2)
          			d13 = tmpfinal
          		end if 
          	
          	end if	
          	
          	vFinal = d1 + d3 + d5 + d7 + d9 + d11 + d13 + d2 + d4 + d6 + d8 + d10 + d12 + d14
          	dim rem as n
          	rem = mod(vFinal, 10)
          	
              if  rem = 0 then
                  if d15 = 0 then
          			msgbox(vSystem_name, "IMEI is valid")
          		end if	
          	else
          		dim hul as n
          		dim notzero as n
          		hul = 10*int(vFinal/10)
          		notzero = (hul + 10) - vFinal
          		if	d15 = notzero then
          			msgbox(vSystem_name, "IMEI is valid")
          		else
          			cancel()
          			msgbox(vSystem_Name, "Invalid IMEI. Please enter the correct IMEI to continue.",UI_ATTENTION_SYMBOL+UI_OK)						    
          		end if
              end if
          
          END FUNCTION
          can someone help assess if the function complied the pseudo code?
          I'm not getting the correct last digit. it seems like the pseudo code is not correct. :( (i took that from a vb forum)

          is there anyone knows how to calculate the cellphone's imei?

          thanks in advance
          Francis

          Comment


            #6
            Re: IMEI checksum help

            I think part of your problem is that in your first step you are doubling the digits starting from the left instead of the right. (according to the article in wikipedia) That is, d1 should be substr(IMEI,14,1) So in your code you should be doubling d2,d4,d6,d8,d10,d12,d14.

            This what I came up with. I think it works. I left the test message boxes in so you can see what is happening.
            Code:
            FUNCTION IMEI_Valid AS L (IMEI AS C)
            'Description: This function checks a 15 digit IMEI code for a correct check digit.
                'There is also a 16 digit code which is a IMEISV. It does not have a check digit.
                IMEI_Valid = .f.
                IMEI = remspecial(IMEI)
                If len(IMEI) <> 15 then
                    exit function
                end if
                
                
                dim expression as C = ""
                dim exp_calc as C = ""
                dim exp_len as N
                dim exp_sum as N
                dim chkdigitn as N
                'Create a string of digits by doubling in value every second original digit.
                expression =    substr(IMEI,1,1)+ (val(substr(IMEI,2,1))*2) + \
                                substr(IMEI,3,1)+ (val(substr(IMEI,4,1))*2) + \
                                substr(IMEI,5,1)+ (val(substr(IMEI,6,1))*2) + \
                                substr(IMEI,7,1)+ (val(substr(IMEI,8,1))*2) + \
                                substr(IMEI,9,1)+ (val(substr(IMEI,10,1))*2) + \
                                substr(IMEI,11,1)+ (val(substr(IMEI,12,1))*2) + \
                                substr(IMEI,13,1)+ (val(substr(IMEI,14,1))*2)
                msgbox("After doubling every other digit",expression) 'For testing
                
                'create an expression in character format inserting a '+' between each digit in the result from above
                exp_len = len(expression)
                For dgt = 1 to exp_len
                    exp_calc = exp_calc + substr(expression,dgt,1)
                    If dgt < exp_len then      'If dgt is not less than exp_len then it is the last digit so don't add a '+'
                        exp_calc = exp_calc + "+"
                    end if
                Next
                msgbox("expression to sum up resulting digits",exp_calc)  'For testing
                
                'evaluate the expression
                exp_sum = eval(exp_calc)
                
                msgbox(""+exp_sum)   'For testing
                
                chkdigitn = 10 - mod(exp_sum,10)
                if chkdigitn = 10 then
                    chkdigitn = 0
                end if
                
                If chkdigitn = val(substr(IMEI,15,1)) then
                    IMEI_Valid = .t.
                end if
                msgbox("Final","This IMEI is "+IMEI_Valid)   'For testing
                
                
            END FUNCTION
            Tim Kiebert
            Eagle Creek Citrus
            A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

            Comment


              #7
              Re: IMEI checksum help

              tim,

              big thanks....

              i owe you another beer... :)

              thanks!
              Francis

              Comment


                #8
                Re: IMEI checksum help

                Your welcome.

                Let us know if it behaves consistently.
                Tim Kiebert
                Eagle Creek Citrus
                A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                Comment


                  #9
                  Re: IMEI checksum help

                  I am posting this information in case someone at some point needs to check Canadian health card numbers.

                  In Canada a MOD 10 Check Digit is added to the Health Card Number used by several provinces. The Health Card Number (HCN) is a provincially issued number and ID card that is used to track health care services insured or paid for by the provincial government. It is the primary ID for many health care information systems, one of which I find myself working with now.

                  With a few modifications the code provided by Tim Kiebert was modified to work with Ontario and Nova Scotia HCN. It may work with other provinces but they where not tested.

                  Thanks Tim for the original code it is much more efficient then anything I could come up with. I was envisioning loops with lots of branching.


                  Code:
                  FUNCTION HCN_Valid AS L (HCN AS C )
                  	'Description: This function checks a 10 digit Health Card Numer for a correct check digit.
                      HCN_Valid = .f.
                      HCN = remspecial(HCN)
                      If len(HCN) <> 10 then
                          exit function
                      end if
                      
                      dim expression as C = ""
                      dim exp_calc as C = ""
                      dim exp_len as N
                      dim exp_sum as N
                      dim chkdigitn as N
                      'Create a string of digits by doubling in value every second original digit.
                      expression = 	(val(substr(HCN,1,1))*2) + substr(HCN,2,1) + \
                      				(val(substr(HCN,3,1))*2) + substr(HCN,4,1) + \
                  					(val(substr(HCN,5,1))*2) + substr(HCN,6,1) + \
                  					(val(substr(HCN,7,1))*2) + substr(HCN,8,1) + \
                  					(val(substr(HCN,9,1))*2)
                  
                      '!Debug stuff
                      'msgbox("After doubling every other digit: ",expression)
                      
                      'create an expression in character format inserting a '+' between each digit in the result from above
                      exp_len = len(expression)
                      For dgt = 1 to exp_len
                          exp_calc = exp_calc + substr(expression,dgt,1)
                          If dgt < exp_len then      'If dgt is not less than exp_len then it is the last digit so don't add a '+'
                              exp_calc = exp_calc + "+"
                          end if
                      Next
                      '!Debug Stuff
                      'msgbox("expression to sum up resulting digits: ",exp_calc)
                      
                      'evaluate the expression
                      exp_sum = eval(exp_calc)
                      
                      '!Debug stuff
                      'msgbox("Sum of numbers: "+exp_sum)
                      
                      chkdigitn = 10 - mod(exp_sum,10)
                      if chkdigitn = 10 then
                          chkdigitn = 0
                      end if
                      
                      If chkdigitn = val(substr(HCN,10,1)) then
                          HCN_Valid = .t.
                      end if
                      
                      '!Debug Stuff
                      'msgbox("Final","This HCN is "+HCN_Valid)
                      
                  END FUNCTION

                  Comment

                  Working...
                  X