Well basically i need to use the GoTo command but by getting a value from a textbox first.
for example:
So basically i need it to look what is in text1.text and go to that part in the code.Code:dim a as integer Private Sub Command1_Click() a = val(text1.text) if text1.text = a then GoTo [WHATEVER NUMBER a EQUALS HERE]: 1: msgbox "Skip this" GoTo home: 2: msgbox "Skip this" GoTo home 3: msgbox "Skip this" GoTo home 4: msgbox "STOP HERE BECAUSE TEXT1.TEXT = 4" GoTo home home: End sub -------------------------------------------- Private Sub Form_Load() text1.text = 4 End Sub
Sorry if you don't understand, ive done my best =/
Thankyou![]()
Well It is very basic, here is a simple code I made in 30 seconds, should work fine. I don't know what was wrong with your code.. perhaps because you made text1.text = 4 instead of a = 4? or because you used val.. Well I don't know but this code works:
With this code if in Text1 you insert a letter it will generate an error, to avoid that error dim the variables as string instead of integer.. It's up to you or you can use the on error event.Code:Dim a As Integer Dim b As Integer Private Sub Command1_Click() If Text1.Text = a Then GoTo 4 If Text1.Text = b Then GoTo 1 Exit Sub 1: MsgBox "Text is b" Exit Sub 4: MsgBox "Text is a" End Sub Private Sub Form_Load() a = 4 b = 1 End Sub
Hope I Helped
Last edited by TcM; 11-05-2007 at 03:01 PM.
Sorry it didn't really help, the code i gave was just an example, i have a lot more than 2 'GoTo:' statements and i don't want to use a huge amount of 'If' statements.
I need the way of doing the following:
Code:If text1.text <> 0 Then GoTo val(text1.text) End if
So if text1.text = 1 then it will GoTo 1:
I hope you understand.
Well, ok I will try to modify it when I'll get the chance. BTW what about using case?
Well after some testing I came to the conclusion that I don't think it is possible! Because the GoTo command works in a way that the GoTo should be a label! You cannot say GoTo VariableNumber! Because it will search for a Label name VariableNumber and not the value of the variable VariableNumber.. So as far as my knowledge can take me, I don't think that it is possible without if or case. If you do find another method then please do post it here as it might help others (including me)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks