Getting a result to do multiple things in VB.Net

Soldato
Joined
30 Dec 2004
Posts
4,681
Location
Bromley, Kent
As title really.
Code:
Public Class BetweenNumberAdd
    Dim number As Integer
    Dim firstnumber As Integer
    Dim startnumber As Integer
    Dim endnumber As Integer


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If startnumber = 0 Then
            Exit Sub

        End If
        If endnumber = 0 Then
            Exit Sub

        End If

        For firstnumber = startnumber To endnumber

            number = number + firstnumber

        Next firstnumber

        MessageBox.Show(number)

    End Sub

    Private Sub startnumberbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startnumberbox.TextChanged
        startnumber = Val(startnumberbox.Text)

    End Sub

    Private Sub endnumberbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles endnumberbox.TextChanged
        endnumber = Val(endnumberbox.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        startnumberbox.Text = " "
        endnumberbox.Text = " "
        number = "0"
        firstnumber = "0"
        startnumber = "0"
        endnumber = "0"
    End Sub
End Class

That's my code at the moment which works for my all mighty number cruncher. I'm not looking to optimize or make it more efficient at the moment.

When the loop scans the values in box 1 and two, if the boxes are blank then it stops the loop, but what i want to happen is exactly this, but also have a message box pop up to say something like "first box empty" on the top box and "second box empty" on the second box, I can't seem to work out how to make the pop up appear in the same snippet of code where the value is checked due to it executing the Exit Sub command.

Hope that makes sense, if not just say.

Thanks all

- Pea0n
 
OK I have just had a go and unfortunately they don't seem to be what I'm after exactly, although I appreciate the replies.

What it is I need to do is with this bit:
Code:
  If startnumber = 0 Then
            Exit Sub

        End If
Basically, when the loop finds that the number is zero then I want it to only then cancel the subroutine and also display the error. At the moment the code cancels it, but it doesn't pop up the message box. I can of course modify it to make the pop up box, but then the subroutine won't cancel and its this that I can't seem to get both to do in one process. of course if both boxes match the criteria, i.e. first box is say 6 and second box is 13 then in theory nothing should pop up

Hope that makes sense, cheers!

- Pea0n
 
OK for a start, the string.empty command was one I was searching for the other day, perfect thanks :)

As for the other code, you sir are a genius, thanks for that.

Is there any recommended reading material for using the xxx.yyy.xxx.aaa.bbb definitions, i.e. string.empty.contains (random one, probably doesn't mean anything)? Like what they do, how to find one that does what you want and how to construct them and use them for getting data, preferably some kind of book I can purchase?

Thanks again!

- Pea0n
 
Back
Top Bottom