vb 2008 code problem

Ok. I need to look at this again then.

Edit: I have no idea what is wrong. From the code it should be working perfectly.
Edit2: Aha! I found you're problem, maybe. When you set it to 1, are you leaving the others blank?

Code:
    Option Explicit
        Dim timer as boolean (This will be a global variable, accessed from everywhere)
    
    Form_load() (there should be something like this when you double click the form)
        timer = true

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim intsec as integer
        Dim intmin as integer
        Dim inthour as integer

        
        intsec = val(sec.text)
        intmin = val(min.text)
        inthour = val(hour.text)

        If timer = true then
            intsec = intsec - 1
            If (intsec = 0 or sec.text = "") and (intmin = 0 or min.text = "") and (inthour = 0 or hour.text = 0) Then
                timer = false
            else if intsec = 0 then
                if intmin > 0 then
                    intmin = intmin - 1
                    intsec = 59
                Else if intmin = 0 and inthour > 0 Then
                    inthour = inthour - 1
                    intmin = 59
                    intsec = 59
                End If
            End If
        end if

        sec.text = intsec
        min.text = intmin
        hour.text = inthour

(Else if might be elseif)
    End Sub
Ok, it's ready. I did some editing so if you saw this before this message update it.

Idk if those ORs I put in will work like that, but if you're leaving the fields blank, then you also need to check to see if they are blank on your code.
 
I got a warning on the following line of the code:

Code:
If (intsec = 0 Or sec.text = "") And (intmin = 0 Or min.text = "") And (inthour = 0 Or hour.text = 0) Then

all the other labels weren't blank
 
Code:
    Option Explicit
        Dim timer as boolean (This will be a global variable, accessed from everywhere)
    
    Form_load() (there should be something like this when you double click the form)
        timer = true

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim intsec as integer
        Dim intmin as integer
        Dim inthour as integer

        
        intsec = val(sec.text)
        intmin = val(min.text)
        inthour = val(hour.text)

        If timer = true and sec.text != "" and min.text != "" and hour.text != "" then
            intsec = intsec - 1
            If intsec = 0 and intmin = 0 and inthour = 0 Then
                timer = false
            else if intsec = 0 then
                if intmin > 0 then
                    intmin = intmin - 1
                    intsec = 59
                Else if intmin = 0 and inthour > 0 Then
                    inthour = inthour - 1
                    intmin = 59
                    intsec = 59
                End If
            End If
        end if

        sec.text = intsec
        min.text = intmin
        hour.text = inthour

(Else if might be elseif)
    End Sub

"!=" = is not equal to
Try to find out how to test whether text is numeric on not. This way you only accept numerical information. Also tell the user to input 0 even if they don't want hours.
 
Code:
sec.text ![COLOR="Navy"]=[/COLOR] ""
identifier expected error

and was this script tested in visual basic
 
not equals in vb is denoted as "<>" not "!=", your in C land buddy. Might want to fix those up.
 
this is the codes i entered and now when i set it to 1 min it goes to 1 min -1 sec then stops

Code:
Dim timer As Boolean

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        timer = True
    End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim intsec As Integer
        Dim intmin As Integer
        Dim inthour As Integer


        intsec = Val(Sec.Text)
        intmin = Val(Min.Text)
        inthour = Val(Hour.Text)

        If timer = True Then
            intsec = intsec - 1
            If timer = True And Sec.Text <> "" And Min.Text <> "" And Hour.Text <> "" Then
                timer = False
            ElseIf intsec = 0 Then
                If intmin > 0 Then
                    intmin = intmin - 1
                    intsec = 59
                ElseIf intmin = 0 And inthour > 0 Then
                    inthour = inthour - 1
                    intmin = 59
                    intsec = 59
                End If
            End If
        End If

        Sec.Text = intsec
        Min.Text = intmin
        Hour.Text = inthour

    End Sub
 
No. I don't have VB. That might be C++ lol. I get confused all the time. Try <> instead of !=

Sorry, don't this any errors in the code man. I could be blindly missing something. Check to see if all your outputs are correctly assigned.
 
Back
Top Bottom