Closed Thread
Results 1 to 5 of 5

Thread: Simple help please.

  1. #1
    Skel is offline Learning Programmer
    Join Date
    May 2007
    Posts
    33
    Rep Power
    0

    Simple help please.

    Well basically i need to use the GoTo command but by getting a value from a textbox first.

    for example:

    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
    So basically i need it to look what is in text1.text and go to that part in the code.

    Sorry if you don't understand, ive done my best =/

    Thankyou

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    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:

    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
    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.

    Hope I Helped
    Last edited by TcM; 11-05-2007 at 03:01 PM.

  4. #3
    Skel is offline Learning Programmer
    Join Date
    May 2007
    Posts
    33
    Rep Power
    0
    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.

  5. #4
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Well, ok I will try to modify it when I'll get the chance. BTW what about using case?

  6. #5
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    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)

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 10-13-2011, 08:52 PM
  2. I'm stumped by this simple, simple code...
    By scottbomb in forum Java Help
    Replies: 6
    Last Post: 03-10-2011, 08:35 PM
  3. Simple 2D Example
    By OutcastOrange in forum C and C++
    Replies: 10
    Last Post: 09-20-2009, 03:19 PM
  4. The simple are often the best
    By Rudd in forum General Programming
    Replies: 0
    Last Post: 11-10-2008, 11:46 PM
  5. Very Simple Help ... Im sure
    By amped designs in forum PHP Development
    Replies: 7
    Last Post: 10-30-2008, 12:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts