Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > help with crashing loop


Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2002, 01:58 AM
[PL]Iconkill
Guest
 
Posts: n/a
Default help with crashing loop


hello
i am having trouble with a program i am writing
it is to remind me to let my dog in when i let her out because i forget to let her in some times and she gets mad
anyway the program crashes when i hit the comand button
i think the problem is with the do until loop
i have been using VB for a while but i have avoided the do until and the do while loops because i know they are good at crashing computers

my code looks like this

Dim vartime1, vertime2, vertime3

Private Sub Command1_Click()
'get currant time in seconds after midnight
vartime1 = Val(Timer)
'set time for timer to stop...
'for this application it is a set time of 10 min
'or 600 seconds
vartime2 = Val(vertime1) + 600
'make sure program will work over midnight
If vertime2 > 86400 Then
vertime3 = Val(vertime2) - 86400
Else
vertime3 = Val(vertime2)
End If
'make form1 invisible so it is not in the way
'timer will be running the the background
Form1.Visible = False
'us a do until loop till vertime3 = timer
Do Until Val(vertime3) = Val(Timer)
Loop
'make form2 visible
Form2.Visible = True
End Sub

if i just used bad syntax (not that i ever do ) and someone knows how to fix it that would be cool

but if it is just a imposible idea and it is not fixable and it cant be done that way i would like to know how it can be done

thanks in advance for all your help
Reply With Quote
  #2  
Old 04-03-2002, 02:07 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

First put "Option Explicit" at the top of your code, this makes sure you can only use dimmed variables

You mixed vartime* and vertime*

Better don't use variants:
Code:
Dim vartime1 As Long, vartime2 As Long, vartime3 As Long
In that case there is no need for all Val() functions.

Instead of
Form2.Visible = True
use
Form2.Show

Also don't check for =, but for <=
Reply With Quote
  #3  
Old 04-03-2002, 02:22 AM
[PL]Iconkill
Guest
 
Posts: n/a
Default

thankyou
you are the best
i am ashamed of my slef for making such lame errors and not seeing them but i am glad you picked them up


p.s.
in your expert opinion do you think this method of timing is accurate ????
Reply With Quote
  #4  
Old 04-03-2002, 02:30 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

Looks OK to me.

tip: put a DoEvents in the DO UNTIL ... LOOP, otherwise it may take all computer time...
Reply With Quote
  #5  
Old 04-03-2002, 07:15 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Of course, a simple Sleep API call could save a bunch of code here.
__________________
Posting Guidelines
Reply With Quote
  #6  
Old 04-03-2002, 07:45 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Code:
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Sleep
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #7  
Old 04-06-2002, 12:19 AM
[PL]Iconkill
Guest
 
Posts: n/a
Default

thanks guys the sleep comand works great

dosn't take up as many resourses as my first attempt

and there is so much less code

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->