Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two (I think simple) questions for a school project I am working on... 1

Status
Not open for further replies.

Tonyn2002

Technical User
Dec 19, 2001
11
US
I need to figure out in VB how to check a character in a string - a certain position.

Such as
string - "abcdefg"
Need to check position 1 (a) and 3 (c).

Was thinking something like (position what ever the correct code to use)
for I = 1 to len(strStringToCheck) Step 1
position(I, strStringToCheck) 'position(pos number, string)
Loop

I have tried the left property, but that takes all from the left. I mean on "abcdefg", left("abcdefg", 3) would return "abc" - but I need to just get the character in pos 3 "c"

Now the second I need to figure out is ASCII values.
Want to try a couple of things one of which will check what key is pressed on Form_Click(), and if that key is lets say "enter" (I belive 13 in ASCII, don't remember anymore lol) something happens.
Also to convert ASCII number values to charater outputs.


This is for a school project I am finishing up on, so any help is appreciated. When I was using/learning C++ these two things were easy to figure out. But am fairly new to VB so I ask your help :)


Thanks in advance,
Tony
 
For the first problem use the mid function, works like
mid (string that's being searched, startposition , lenght)

In your case startposition is either 1 or 3 and lenght is always 1 (1 character)

The second problem:
the chr command converts ascii numbers to characters. use the keypress event to intercept keystrokes in ascii form, like when you press the enter key on a form:
Private Sub Form_KeyPress(KeyAscii As Integer)
if keyascii = 13 then
msgbox "you pressed enter"
end if
End Sub

Hope this helps.
 
hey tonyn,

now make painkiller explain AscB, AscW, ChrB, ChrW.

and why do we need this unicode format that cuts our memory in half?

john
 
to find out what ASCII code each key has, try the following:

set up a text box called 'txtinput' and label called 'laboutput'

get the code for the text box as follows:
Private sub txtinput_keypress
laboutput.caption=keyascii
' writes out the ascii code for the key that has just been
' pressed in the txtinput box. works for all keys, except
' esc and arrows
End Sub

Off hand, 8 is delete
13 is enter
48 to 57 are the numbers 0 to 9
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top