Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Coding Help Needed


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-18-2007, 06:33 AM
Junior Member
 
Join Date: Nov 2007
Posts: 17
Default Coding Help Needed

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
Reply With Quote
  #2 (permalink)  
Old 11-18-2007, 06:59 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,335
Default

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.
Reply With Quote
  #3 (permalink)  
Old 11-18-2007, 07:14 AM
Junior Member
 
Join Date: Nov 2007
Posts: 17
Default

I get the following error :
Line number =0
Error Description:IndexOutOfRangeException
Reply With Quote
  #4 (permalink)  
Old 11-18-2007, 07:31 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,335
Default

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.
Reply With Quote
  #5 (permalink)  
Old 11-18-2007, 08:14 AM
Junior Member
 
Join Date: Nov 2007
Posts: 17
Smile

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

Amit
Reply With Quote
  #6 (permalink)  
Old 11-18-2007, 10:20 AM
Junior Member
 
Join Date: Oct 2007
Location: Italy
Posts: 25
Default

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?
Reply With Quote
  #7 (permalink)  
Old 11-18-2007, 09:44 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 119
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
WebBrowser & HTML help needed tsteward Questions & Help Needed 0 10-23-2008 10:34 AM
Help needed converting a VB6 Project Drewpeu Questions & Help Needed 11 10-15-2008 07:13 PM
Coding Question MLenet Questions & Help Needed 3 09-08-2008 07:40 PM
XML-support needed Frank Questions & Help Needed 2 01-29-2008 07:56 PM
Owner Info help needed kshetarpal Questions & Help Needed 3 11-18-2007 05:36 AM


All times are GMT. The time now is 06:47 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0