Coding Help Needed

Discussion in 'Questions (Windows Mobile)' started by kshetarpal, Nov 18, 2007.

  1. kshetarpal

    kshetarpal Member Licensed User

    I am trying to convert the following code to Basic4PPC:
    I would appreciate any help.

    Sub CommandButton1_Click
    Dim username, ch,checksum,iCount,

    username = owner.text
    For iCount=1 To Len(username) 'encipher the entered number
    ch= Mid(username,iCount,1)
    checksum = Asc(ch)
    Next
    checksum = 34296 + checksum * 3
    While (checksum > 65535)
    checksum = checksum - 65536
    Wend
    While (checksum < 0)
    checksum = checksum + 65536
    Wend
    code.text = checksum

    End Sub

    Amit:sign0085:
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Sub CommandButton1_Click
    username = owner.text
    For iCount=1 To StrLength(username)  'encipher the entered number
       ch =StrAt(username,iCount)
       checksum =  
    Asc(ch)
    Next 
    checksum = 
    34296 + checksum * 3
    Do While (checksum > 65535
        checksum = checksum - 
    65536
    Loop 
    Do While (checksum < 0
        checksum = checksum + 
    65536
    Loop 
    code.text = checksum
    End Sub
    I haven't tested it.
     
  3. kshetarpal

    kshetarpal Member Licensed User

    I get the following error :
    Line number =0
    Error Description:IndexOutOfRangeException
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Change:
    For iCount=1 To StrLength(username)
    To:
    For iCount=0 To StrLength(username)-1

    Strings (and arrays) first index is 0 and not 1.
     
  5. kshetarpal

    kshetarpal Member Licensed User

    It works fine now. I will have more questions as I progress further in this program. Your help has been invaluable.

    Amit
     
  6. forisco

    forisco Member Licensed User

    But at the end of cicle, the variable 'checksum' will be always the ascii of the last character of string! You want obtain (i think) this : 'checksum = checksum + Asc(ch)', right?
     
  7. LineCutter

    LineCutter Active Member Licensed User

    That last addition loop could be either redundant or replaced by a simple IF..THEN (ASCII values are always positive aren't they?
     
Loading...