Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help with visual basic please

Pure1108Pure1108 Posts: 4Member
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
Else
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.

Comments

  • DaiMitnickDaiMitnick Posts: 77Member
    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:

    [code]
    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]
    RunRoutineThatHappensAfterClickingTheButton()
    Exit Sub
    Err1:
    MsgBox(errmessage1)
    Exit Sub
    Err2:
    MsgBox(ErrMessage2)
    End Sub
    [/code]

    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. |
    ------------------------------------------
  • Pure1108Pure1108 Posts: 4Member
    This is helpful but only the error message for the checkbox works :s
  • Pure1108Pure1108 Posts: 4Member
    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.