help with progress bar and timer controls..

qaisqais

Member
Joined
Mar 29, 2010
Messages
14
Programming Experience
Beginner
hi, im trying to get a progress bar to countdown a specified time in minutes from a textbox. what ive got is a mainmenu form, which has an options button opening an options form, and setting the work shift timer is one of the options, which leads to a another form requesting the shift time in minutes which should then be used to handle the progress bar on the mainmenu form. (hopefully thats not too confusing)

Main Menu Code
VB.NET:
Public Class MainMenu
   
    Private Sub MainMenu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Clock.Interval = 1 * 1000 ' this = 1 second
        Me.Clock.Enabled = False
    End Sub

    Private Sub btnOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOption.Click
        Options.Show()
    End Sub
End Class

Shift Timer Set Code
VB.NET:
Public Class ShiftTimerSet
    Dim timCount As Integer
   
    Private Sub Clock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainMenu.Clock.Tick
        On Error Resume Next
        timCount = timCount + 1
        MainMenu.ProgressBar1.Value = MainMenu.ProgressBar1.Value + 1
        If timCount >= MaskedTextBox1.Text * 60 Then
            MainMenu.ProgressBar1.Value = MainMenu.ProgressBar1.Maximum
            MsgBox("Your Shift Is Over")
            MainMenu.Clock.Enabled = False
            timCount = 0
            MainMenu.ProgressBar1.Value = 0
        End If
    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        MainMenu.ProgressBar1.Minimum = 0
        MainMenu.ProgressBar1.Maximum = MaskedTextBox1.Text * 60
        MainMenu.ProgressBar1.Value = 0
        MainMenu.Clock.Enabled = True
    End Sub
  
End Class

That's what i've got at the moment, i tried making this code referring to an online example, however it's not working, this bit in the shift forms code comes underlined blue
VB.NET:
'Handles MainMenu.Clock.Tick'
am i not allowed to do that? if so what do i do to make this work! im very confused
 
You cannot use Handles except for member variables declared in the current type with the WithEvents keyword. The Timer (which is a component, not a control) is declared in the MainMenu class and that's the only place it should be used. You handle its Tick event in that form and you update the Ui of that form in that form.
 
to be honest i didn't really understand your response, i'm not very good at programming nor very knowledgeable at all(this is for my school coursework), how do i go about rectifying the problem? thanks!
 
Back
Top