Need help with visual basic please

I've tried so hard by myself and I've just ended up confusing myself as it's my first time using vb.
I didn't want to waste anyones time but I'm sorry I just don't know what to do..

How would I code this?

I want to make a progress bar that runs when a button is clicked.
However there is also a checkbox and textbox that affect the whole thing.

If the checkbox is checked and there are characters in the text box, the button works and starts the progress bar.
If the checkbox isn't checked and/or the textbox is empty, an error message comes up when the button is pressed.


I can almost code it but I get stuck at[code] Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If String.IsNullOrEmpty(TextBox1.Text) Then
Button1.Enabled = False
Button1.Enabled = True
End If

If CheckBox1.Checked = False Then
Button1_Click(MsgBox("Error. The checkbox must be ticked"))[/code]

As you probably know, that isn't right but I just don't know what to do next :(

Please help thankyou so much.


  • You don't really need the checkbox_changed event, though I would leave in the first bit that disables the button, doesn't hurt, just delete the rest. You'll need to use the button click event, something like this should suffice:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Const ErrMessage1 As String = "Error: You have not entered any text"
    Const ErrMessage2 As String = "Error: You have not ticked the box"
    If String.IsNullOrEmpty(TextBox1.Text) Then GoTo Err1
    If CheckBox1.Checked = False Then GoTo Err2
    [color=Green]'If you have made it this far there are no errors, so run code...[/color]
    Exit Sub
    Exit Sub
    End Sub

    By the way, you may want to use a timer and public variables to know when to change the progress bar. Hope this helps, Dai

    Do or do not, there is no try. |
  • This is helpful but only the error message for the checkbox works :s
  • never mind I forgot the textbox i wanted filled was textbox2 not textbox1

    and after using your coding, it worked perfectly! thanks so much

    however i had to delete the const. errmessage part for it to work

    anyway thanks so much!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!