|
-
Jan 16th, 2007, 10:58 AM
#1
Thread Starter
New Member
[2005] Applying ASCII code into VB
How do i apply ASCII code into VB?.. eg. Identifiying a character by its own character or source code.
-
Jan 16th, 2007, 11:02 AM
#2
Frenzied Member
Re: [2005] Applying ASCII code into VB
asc() and chr() still work
-
Jan 16th, 2007, 11:04 AM
#3
Thread Starter
New Member
Re: [2005] Applying ASCII code into VB
 Originally Posted by agmorgan
asc() and chr() still work
Okay. So how do i identify a single character?
-
Jan 16th, 2007, 11:37 AM
#4
Fanatic Member
Re: [2005] Applying ASCII code into VB
To get a single character use
where i is the index of the character you want.
-
Jan 16th, 2007, 11:39 AM
#5
Thread Starter
New Member
Re: [2005] Applying ASCII code into VB
Thanks. So how do i set a Range of index? like from character 40 to 68
-
Jan 16th, 2007, 11:41 AM
#6
Fanatic Member
Re: [2005] Applying ASCII code into VB
String.Substring(i, l)
i is index, l is length
-
Jan 16th, 2007, 11:43 AM
#7
Thread Starter
New Member
Re: [2005] Applying ASCII code into VB
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..
-
Jan 16th, 2007, 11:46 AM
#8
Fanatic Member
Re: [2005] Applying ASCII code into VB
I don't under the question. What is it that you are trying to do?
-
Jan 16th, 2007, 11:49 AM
#9
Thread Starter
New Member
Re: [2005] Applying ASCII code into VB
 Originally Posted by 18experience
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.
-
Jan 16th, 2007, 11:50 AM
#10
Fanatic Member
Re: [2005] Applying ASCII code into VB
Set a range on what? A textbox? Are you trying to stop someone from entering numbers, or anything but uppercase characters?
-
Jan 16th, 2007, 11:51 AM
#11
Thread Starter
New Member
Re: [2005] Applying ASCII code into VB
 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.
-
Jan 16th, 2007, 12:00 PM
#12
Re: [2005] Applying ASCII code into VB
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
Last edited by stimbo; Jan 16th, 2007 at 08:43 PM.
-
Jan 17th, 2007, 09:04 AM
#13
Thread Starter
New Member
Re: [2005] Applying ASCII code into VB
 Originally Posted by stimbo
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.
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..
-
Jan 17th, 2007, 09:14 AM
#14
Re: [2005] Applying ASCII code into VB
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.
-
Jan 17th, 2007, 09:21 AM
#15
Thread Starter
New Member
Re: [2005] Applying ASCII code into VB
 Originally Posted by stimbo
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.
hmm.. kinda understand, but theres a sentence which i dun understant.
Select Case Asc(e.KeyChar)
what does e.keychar means?
-
Jan 17th, 2007, 10:03 AM
#16
Re: [2005] Applying ASCII code into VB
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|