English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
0

I am writing a console application in visual basic. I am writing code that checks the value of a key pressed. If the key presses is not one that I specified, then the console displays an error message. However, I would like it to be able to go back to the beginning of the sub, so that the user can try making another choice. I tried using a do, loop, until statement, but it would not catch the invalid keys, and it misidentified the correct keys as bad ones. I just want to know how to have the program return to the beginning of the sub (in my case sub main()). Thanks in advance!

2007-02-10 16:59:08 · 3 answers · asked by nohscompclub3 1 in Computers & Internet Programming & Design

3 answers

use the keypress event to check the ascii value of each key(keyAscii) as it is pressed. If the value is an invaliid one then set keyAscii = 0 (null) which will cancel the key press. You can also show a message box telling the use an invalid key was pressed and/or change the background color of the textbox to give the user some feedback as to why the charcter is not being entered into the textbox

2007-02-10 17:12:01 · answer #1 · answered by MarkG 7 · 0 0

create a section at the begining of ur sub like

sub abc()
on error goto myerr
start:
[ code.....]


exit sub
myerr:

[use error handling and then send it back to start again]
goto start
end sub

cheers

2007-02-11 01:05:03 · answer #2 · answered by Evilz S 1 · 0 0

create a LINE LABEL by giving the top of the procedure a name with a colon, and use the GOTO statement


Private Sub Do_Something()
PROC_TOP:

Processing code

GOTO PROC_TOP

...

END SUB

2007-02-11 01:48:03 · answer #3 · answered by Richard H 7 · 0 0

fedest.com, questions and answers