Link to home
Start Free TrialLog in
Avatar of eeyorg
eeyorg

asked on

Visual Basic Time Limit

My problem is that I want to create a time limit in visual basic, but I don't know how. I want something like this:

if lblStatus = "yes" more than the time limit Then
lblstatus = "message"
end if

incase you don't get what i'm saying; for lblstatus = "yes", if it stays as "yes" for more than 10seconds, then I want it to change to "no".

hope that helps

I just want something like this and I'm sure its not that hard, so please help me. Thanks.
Avatar of sirbounty
sirbounty
Flag of United States of America image

Not sure I understand precisely what you're doing, but...

1) Drop a timer control on your form
2) Set its interval (property) to 1000
3) Double-click the timer control to get the associated sub...

Dim intTime
Private Sub Timer1_Timer()
  If lblStatus="yes" and intTime > 30 Then
    lblStatus="Time's up!"
  End If
End Sub
Avatar of eeyorg
eeyorg

ASKER

can you explain to me what's 30 in intTime > 30 and is intTime dim as string, or just dim
Labels can't be changed by the user...only by the coder via code.

So could you please explain in more detail what you are doing?...and how the label gets changed?...

Avatar of eeyorg

ASKER

k, its like this:

i'm connecting to a http site and sometimes it takes too long to get information, so what i want is the time limit to let me reconnect to the server.

say if i connect to the server and i'm connected, but don't get any information, thats where the time limit comes in. if i am connected for more than 10seconds, then the time limit would activate and have me reconnect again. if i wasn't connected for more than 10seconds, i would have no need for the time limit.

hope that clears up things better.
Ok...as sirbounty said, use a Timer control.

Set the Interval property to 10000 (ten thousand) which is ten seconds.  Set the Enabled property to FALSE.

When you connect, enable the Timer:

    Timer1.Enabled = True

When the Timer fires, ten seconds are up:

    Private Sub Timer1_Timer()
        ' ten seconds are up...do something in here...
    End Sub

If you receive data then turn off the Timer so it doesn't fire:

    Timer1.Enabled = False

*** BUT *** I don't work with HTTP stuff so this may be moot if the call to get data is a blocking call.  If this is the case then the code will just stop until data is received or the function itself times out due to some internal setting.  The Timer would just never fire...

Are you using Winsock Control, Winsock API, INET Control or IE Control to request the site?
Avatar of eeyorg

ASKER

i'm using winsock
Avatar of eeyorg

ASKER

i mean winsock control
So then do exactly what idle_mind suggested, put a timer.enable in your Winsock_Connect event, then put a timer.enabled = false in a data_received event.
 Private Sub Timer1_Timer()
         timer1.enabled = false
         do
         doevents: winsock1.close
         loop until winsock1.state = 0
         winsock1.connect '/use old server and port and try again
       
    End Sub
Is it possible to use Wend.  I don't know http either, but I know it works with create object.  For example...this code will increment x by 1 every second while it is waiting for the page to load.  If x gets to 10 before the page loads, then you can put code there to do something.  If you can convert this to whatever you are doing, then it should work.  Here is the code:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub OpenIe
Dim oIE as Object
dim x as integer
oIE = CreateObject("InternetExplorer.Application")
        oIE.Visible = True
        oIE.Navigate (WebAddress)
        While oIE.Busy
           Sleep 1000
           x = x + 1
           if x = 10 then
                 '10 seconds are up.  Do something here
           End if
         Wend ' wait for page to load...
End Sub


:-)
ah
The problem with using sleep api is that it hangs the application.
ASKER CERTIFIED SOLUTION
Avatar of DinitSoftwares
DinitSoftwares

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial