A command that's been around since the beginning of the language -- but also one that has expanded and evolved to make it much more flexible and powerful for modern programmers.
What is it? ASC is a simple little command which lets us to either set/get the ASCII value to/from a string character.
How do we use it?
To get a value, it's a simple function call like: value = ASC(a$, position)
To set a value, it's a simple sub call such as: ASC(a$, position) = 97
A simple example to showcase these methods a little:
What is it? ASC is a simple little command which lets us to either set/get the ASCII value to/from a string character.
How do we use it?
To get a value, it's a simple function call like: value = ASC(a$, position)
To set a value, it's a simple sub call such as: ASC(a$, position) = 97
A simple example to showcase these methods a little:
Code: (Select All)
Screen _NewImage(800, 600, 32)
a$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'Back in the days of QB45, this is how folks made use of ASC:
For i = 1 To Len(a$)
temp$ = Mid$(a$, i, 1)
Print temp$; " = "; Asc(temp$)
Next
Sleep
'Then, along came QB64 with its first improvement!
'the ability to specify which byte we wanted!
For i = 1 To Len(a$)
Locate i, 20
Print Mid$(a$, i, 1); " = "; Asc(a$, i)
Next
Sleep
'Did you notice that we didn't actually need to use MID$ to get a single character anymore?
'Instead, we just specified which character we wanted to get the ASC value of, out of our string.
'And, as if that improvement wasn't enough, a SUB ASC was written for QB64!
temp$ = a$ 'a perfect match
For i = 1 To Len(a$)
Asc(temp$, i) = Asc(a$, Len(a$) - i + 1)
Next
Print
Print temp$
Sleep
'Notice how we just used ASC to assign characters to our string, based entirely off their ASCII value?
Cls
Print "ASC";
_Delay .5: Print ".";
_Delay .5: Print ".";
_Delay .5: Print "."
Print "Not the same old command that cavemen used to use when programming!"
Print
Print "You can now specify which byte you want the ASCII value of..."
Print "and you can now assign characters to a string with just their ASCII value."