Click to See Complete Forum and Search --> : Manipulating individual character's ASCII values


Sabec
June 14th, 2001, 09:37 AM
I was wondering if there's a command to manipulate the ascii value of specific characters in visual basic. It's a fairly simple process in other more complex languages.

The problem that I have is that I am making a curriculum for a summer camp teaching grade 6-8 students the basics of programming. The project I wanted to do was to write a simple encode/decode program in visual basic that the kids could create a windowed exe file they could execute at home but the best way I know how to encode a basic text message is to manipulate the ascii value. If there's any more project ideas out there or another way to encode that would be welcome as well as letting me know if there is a way to maniuplate character ascii values.

shree
June 14th, 2001, 10:06 AM
It's fairly simple in VB too. Just assign the string to a byte array. You process every other byte (Each character requires two bytes in Unicode).

As an example, here is an example from one of my earlier posts that checks whether a character is alphabetic or not. You can modify it to suit you.

Private Function isalpha(str as string) as Boolean
Dim ByteArr() as Byte
Dim i as Integer
Dim AllAlpha as Boolean
ByteArr = str
AllAlpha = true
for i = 0 to UBound(ByteArr) step 2
If Not (((ByteArr(i) >= 65) And (ByteArr(i) <= 90)) Or ((ByteArr(i) >= 97) And (ByteArr(i) <= 122))) then
AllAlpha = false
Exit for
End If
next
isalpha = AllAlpha
End Function

Private Sub Command1_Click()
MsgBox isalpha("Hello")
End Sub