PDA

View Full Version : Usage of The ASC Keyword



Michael Clease
26-05-2007, 10:39
2 Examples which is better?

Example1


' Usage of the ASC Instruction example
'
' Return Values of a string
'
' Written by Abraxas

' Will show a box with
' String to check
'
' HELLO
'
'Current Char H Value 72
'Current Char E Value 69
'Current Char L Value 76
'Current Char L Value 76
'Current Char O Value 79

DIM MyString as STRING VAlue = "HELLO"
Dim sMsg as String
DIM StrPos as Long Value 1 ' Position of Current Character
DIM CharVal as Byte value 0

sMsg = "String to check " & $CRLF & $CRLF & MyString & $CRLF & $CRLF

For StrPos = 1 to Len(MyString) ' Loop for the length of the string
CharVal = Asc (MyString,StrPos)
sMsg += " Current Char " & Mid$(MyString,StrPos,1) & " Value " & CharVal & $CRLF
Next

MsgBox 0, sMsg

Example2


DIM MyString as STRING VAlue = "HELLO"
Dim sMsg as String
DIM StrPos as Long Value 1 ' Position of Current Character

sMsg = "String to check " & $CRLF & $CRLF & MyString & $CRLF & $CRLF

For StrPos = 1 to Len(MyString) ' Loop for the length of the string
sMsg += " Current Char " & Mid$(MyString,StrPos,1) & " Value " & Asc (MyString,StrPos) & $CRLF
Next

MsgBox 0, sMsg

ErosOlmi
27-05-2007, 01:22
First one but without variable init because they will already initialized by the script when needed.

Thanks
Eros