How do i apply ASCII code into VB?.. eg. Identifiying a character by its own character or source code.
Printable View
How do i apply ASCII code into VB?.. eg. Identifiying a character by its own character or source code.
asc() and chr() still work
Okay. So how do i identify a single character?Quote:
Originally Posted by agmorgan
To get a single character use
where i is the index of the character you want.VB Code:
[I]String[/I].Chars(i)
Thanks. So how do i set a Range of index? like from character 40 to 68
String.Substring(i, l)
i is index, l is length
hmm.. i think my question is not clear.
I wanna ask how do i set a range of character for ASCII. like from A-Z..
I don't under the question. What is it that you are trying to do?
I'm sorry if i cant make myself clear. I am trying to find set a range for ASCII code. Like from Char A - Z is 65 - 90.. so how do i apply in VB coding to set the range.Quote:
Originally Posted by 18experience
Set a range on what? A textbox? Are you trying to stop someone from entering numbers, or anything but uppercase characters?
Erm. an input.. The task is simple. To check every input its character. So i decided to use ASCII codes to check every single inputs.Quote:
Originally Posted by 18experience
Think you want to check out the KeyDown and KeyPress events of the text box. Go read about it on MSDN
VB Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _ Handles TextBox1.KeyPress Select Case Asc(e.KeyChar) Case Is = 97 MessageBox.Show("Pressed a") Case Is = 65 MessageBox.Show("Pressed A") Case Is >= 100 MessageBox.Show("ASC value greater than or equal to 100 found") Case 10 To 20 MessageBox.Show("Case ASC value ranging from 10 to 20 found") Case Else MessageBox.Show("Unknown number - not specified") End Select End Sub
Erm.. i dun understand the source code but thanks for the effort. What i want to know is to check every single character in a string.Quote:
Originally Posted by stimbo
eg. if user input Hello!
the source code will take out H and check whats ASCII code does it belong. After checking H, and is a true value, it will proceed to e and check whats its ASCII code value and if its true, the loop will go on for the rest of the words. If all true, it will tell the user its correct.
I think i am requesting too much.. but i really do hope you guys will help me. Thanks for the effort helping me..
My last post covers almost everything you want to actually do...
You need to loop through the string taking each character at a time:
VB Code:
For Each chr As Char In Me.TextBox1.Text 'Or a string instead of textbox Next
Then within that loop check for character you are looking for - use my other code to get ASC value for it and it's done.
Quote:
Originally Posted by stimbo
hmm.. kinda understand, but theres a sentence which i dun understant.
Select Case Asc(e.KeyChar)
what does e.keychar means?
See the bit on the KeyPress Event Sub that says:
VB Code:
ByVal e As System.Windows.Forms.KeyPressEventArgs
The e (which is arbitrary I believe) is the value of the argument passed by the event (Or something like that).
So you examine 'e.KeyChar' which is the Select Case bit, you are looking at the KeyChar property of the event that happened and convert it from it's initial character value into it's ASCII value using the Asc(chr here).
I hope that makes sense. If you didn't have Asc in front and instead only had e.KeyChar then it would give you the actual letter you pressed. The .KeyChar tells it what information from 'e' it wants. Remove the KeyChar bit and you will see the intellisense gives you lots of other properties that you could get.