Problems

I am having some problems that I can't seem to figure out.  First of all....make a form with 2 text boxes and one button.  Put a number in the first one and not in the second one.  Now what is supposed to happen when you click the button is make the second text box have a 0 in it, but it doesn't, vb has an error.  Here is the code for that:

Private Sub Command1_Click()
If Text1.Text = "" And Text2.Text = "" Then
int1 = MsgBox("You must enter a time!", vbCritical + vbOKOnly, "Error")
'Check to see if there is nothing in the 2 text boxes
Else:
If Text2.Text >= 60 Then
int1 = MsgBox("Must be between 0 and 59", vbCritical + vbOKOnly, "Error")
Else:
Text1.Enabled = False
Text2.Enabled = False
Timer1.Enabled = True
    Timer1.Interval = 1000
'if there is #s then enable timer
If Text1.Text = "" Then
Text1.Text = 0
If Text1.Text = " " Then
Text1.Text = 0
If Text2.Text = "" Then
Text2.Text = 0
If Text2.Text = " " Then
Text2.Text = 0
'make sure a text box has atleast a 0

End If
End If
End If
End If
End If
End If
End Sub

The second problem I am having is, I want my program to count down to 0 using hours, minutes, and seconds.  I can have it count down the seconds (because I have this in the timer and I have the timer's interval set at 1 second.  But, I can't seem to get it so it will count down the minute and hours in the same timer.  What I need to do is like every 60 interval count down 1.   Anyways, here is my code for that:

Private Sub Timer1_Timer()

abc = abc - 1
    res = res + 1
    If res >= (Text1.Text * 60 + Text2.Text) * 60 Then
    'count + 1 every second
    End
End If
If abc <= -60 Then
abc = 0
End If
x = (Text1.Text * 60 + Text2.Text) - 1
  y = x \ 60      'hours
  z = x Mod 60    'minutes
  a = abc + 60    'seconds
Form1.Caption = "hrs." & y & " min." & z & " sec." & a
End Sub

Also, I have this in the general declarations:

Dim res As Integer
Dim abc As Integer

Well...I hope you can help!  Oh yea, I have vb 5.0

Some of this code might not work, so email me if you have problems at mrcool4444@hotmail.com and I will send it to you in a file.
mrcool4444Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MaximkaConnect With a Mentor Commented:
try to write this code
  if trim(text1.text)=vbnullstring then
        text1.text=0
  end if
  if trim(text2.text)= vbnullstring then
       text2.text=0
  end if

but You have to put it before the
checking
  If text1.text >=60 then ...

Your error occures becouse
you had written text1.text=0 after
the checking text1.text >60 and it realy
type mismatch .
0
 
Jon_RaymondCommented:
As to your first question.  What errors do you get, and on what line.  I expect that you should be checking for a null value.  Instead of

If Text1.Text = "" And Text2.Text = "" Then

try this

If (ISNULL(Text1.Text) And ISNULL(Text2.Text)) OR (Text1.Text = "" And Text2.Text = "") Then
0
 
Jon_RaymondCommented:
do you get any error in your timer code.  You might need to convert the textbox values into number values:

CDBL(Text1.Text) * 60
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mrcool4444Author Commented:
Oh, sorry, I get the error in this line:

If Text2.Text >= 60 Then

and it says type mismach error.  Just try putting it into vb and you will see.
0
 
TTCommented:
You could try to put a Trim$ function :
Trim$(Text1.Text) = "" while check for
empty text box.

and, whenever u would like to compare
the content of text box to a numeric
value, convert it to numeric type first
: cdbl(Text2.Text) >= 60  

and , u may change your if...Then statement to :
 If trim$(Text1.Text) = "" Then
     Text1.Text = 0
     If trim$(Text2.Text) = "" Then
        Text2.Text = 0
        'make sure a text box has  
        ' atleast a 0
      End If
 End If
0
 
Jon_RaymondCommented:
Yes, type mismatch indicates that you must convert from text to number. use:
CDBL(Text1.Text) to convert to a double numeric type.
0
 
mrcool4444Author Commented:
Okay, I really appreciate everyones help, but none of this stuff you are telling me will work, try puting my code into vb and try it!
0
 
mrcool4444Author Commented:
Got that part, the only thing is I still have a problem!  I need to know how to make this work:

Private Sub Timer1_Timer()

abc = abc - 1
    res = res + 1
    If res >= (Text1.Text * 60 + Text2.Text) * 60 Then
    'count + 1 every second
    End
End If
If abc <= -60 Then
abc = 0
End If
x = (Text1.Text * 60 + Text2.Text) - 1
  y = x \ 60      'hours
  z = x Mod 60    'minutes
  a = abc + 60    'seconds
Form1.Caption = "hrs." & y & " min." & z & " sec." & a
End Sub

Also, I have this in the general declarations:

Dim res As Integer
Dim abc As Integer

I need it to display how many hours, minutes, and seconds are left.  I have the seconds working, but not the minutes and hours.  I don't know how to make it count down minutes or hours in a timer that its interval is set at 1000(1 second).  
0
 
MaximkaCommented:
Don't use timer for this,
just write some thing like this code

dim vTimer as variant


vTimer = timer

' her goes your code that you want to
' count it time and then

vTimer = timer - vTimer

' so in vTimer now You have time in
' seconds that take you code

0
 
mrcool4444Author Commented:
Actually, I got my count thing to work.  I used the timer.
0
All Courses

From novice to tech pro — start learning today.