i have here a code for my enlistment module..this code is for the available slot. for example i have set 10 as available slot and when i enlist a student 10 will become 9 and so on..my problem is when it reach zero because i can still enlist but the available slot becomes -1...how do i solve this?

   Public Sub auto()

    Dim x As Integer
    x = TextBox3.Text
    TextBox3.Text = Format(x - 1)

End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
auto()

        MessageBox.Show("Enlisted", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
        If TextBox3.Text = "0" Then
            MessageBox.Show("Slots are full", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

   end sub     

How about checking to see if it is less than zero?

if Integer.Parse(TextBox3.Text) < 0 then '...'

Hi jhedonghae,
Always try to debug your code by observing flow of control in the code. After reading your post I think following code you need

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim x As Integer
    x = TextBox3.Text
    If x <= 0 Then
        MessageBox.Show("Slots are full", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        TextBox3.Text = Format(x - 1)
        MessageBox.Show("Enlisted", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
End Sub

Edited 4 Years Ago by Sahil89

This question has already been answered. Start a new discussion instead.