Results 1 to 3 of 3

Thread: Need basic help on looping...

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Birmingham
    Posts
    1

    Need basic help on looping...

    Forgive me but I am an old mainframe programmer that uses VB occasionally. Writing a gui for my package and can't figure out something. VB is event driven which is kinda weird to me. I can handle most things but I have a main routine that, if my link configuration has not been setup it shows another form to get the parms, then, when I get back I get the scoop from the registry. There is no getting back though (as I am sure you know). I need to get back to where I was in the routine I was in originally. I have a loop in the main process that looks like this (the timer was put in there to avoid a hard loop but, of course, it does nothing either):

    Public Sub HostConnect()
    Dim gotit As Integer
    Timer2.Interval = 10000 'wait about 15 seconds
    'gotta get our connection parameters, if not there then fetch them
    gotit = 0
    While gotit = 0
    HostName = GetSetting("DMcom", "Host", "name", "notfound")
    HostIP = GetSetting("DMcom", "Host", "name", "notfound")
    HostPort = GetSetting("DMcom", "Host", "name", "notfound")
    If HostName = "notfound" Or HostIP = "notfound" Or HostPort = "notfound" Then
    ConnectSettingsfrm.Show
    If FormLostFocus = True Then
    ' if we lost focus, wait for a bit
    Timer2.Enabled = True
    End If
    Else
    gotit = 1
    End If
    Wend
    ' ok, got parms, now connect
    End Sub

    Sorry to be a bother but I've just got some sort of mental block going here...

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    If i'm understanding you correct, then it should return to where it left off in the preceeding sub, like this example
    VB Code:
    1. Public Sub DoSomething()
    2.  
    3. Dim i As Long
    4.  
    5. For i = 0 To 100
    6.     Debug.Print i
    7. Next i
    8.  
    9. End Sub
    10.  
    11.  
    12. Private Sub Command1_Click()
    13.  
    14. MsgBox "About to start Sub..."
    15. DoSomething
    16. MsgBox "Finished with sub..."
    17.  
    18. End Sub

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    How about this :

    VB Code:
    1. Public Sub HostConnect2()
    2.     Dim EverythingOk As Boolean
    3.     EverythingOk = True
    4.     EverythingOk = InStr((GetSetting("DMcom", "Host", "name", "notfound") & GetSetting("DMcom", "Host", "ip", "notfound") & GetSetting("DMcom", "Host", "port", "notfound")), "notfound") = 0
    5.     If EverythingOk Then
    6.         'connect to server
    7.     Else
    8.         'show screen to get settings from user.
    9.         'allow user to cancel connection from there, or try to connect again
    10.         'the connect option should then call this sub again
    11.     End If
    12. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

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



Click Here to Expand Forum to Full Width