Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have label that will show based on timer I set in combo.box

But I want to include checkbox in the condition

meaning if my checkbox have check my condition will not work in the program

What I have tried:

VB
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Dim currentTime As DateTime = DateTime.Now
        Dim BreakTime1 As DateTime = DateTime.ParseExact(cmB1.Text, 
"HH:mm:ss", CultureInfo.InvariantCulture)
        Dim BreakTime2 As DateTime = DateTime.ParseExact(cmB2.Text, 
"HH:mm:ss", CultureInfo.InvariantCulture)

         If currentTime >= BreakTime1 And currentTime <= BreakTime2 And Counter >= 10 Then
            Form1.LblBreak.Visible = True
            Form1.lblRun.Visible = False
            Form1.lblMStop.Visible = False
        End If
Posted
Updated 8-Aug-23 21:55pm
v2

1 solution

You can query the Checked property of the checkbox - see CheckBox.Checked Property (System.Windows.Forms) | Microsoft Learn[^]

Either wrap the whole thing in a test e.g.
VB
If Not chkBox.Checked Then
         If currentTime >= BreakTime1 And currentTime <= BreakTime2 And Counter >= 10 Then
            Form1.LblBreak.Visible = True
            Form1.lblRun.Visible = False
            Form1.lblMStop.Visible = False
        End If
      End If
or include it in the original e.g.
VB
If Not chkBox.Checked And currentTime >= BreakTime1 And currentTime <= BreakTime2 And Counter >= 10 Then
            Form1.LblBreak.Visible = True
            Form1.lblRun.Visible = False
            Form1.lblMStop.Visible = False
        End If
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900