Coding Help Needed

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:
 

Erel

Administrator
Staff member
Licensed User
B4X:
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.
 

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
 

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?
 

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?
 
Top