Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys, am having a problem with my project. wat i want to do is display disable the button if there count is greater than equals to 2. but need to do so if busNumber = txtbusNumber.text and date = txtDay.text and count = txtCount.text.
all this are stored in the database.. i can retrieve them all even the count is working.
this is the code i have so far.

VB
if txtBusNumber.Text = "AT01" And cmbDay.Text = "Monday" And txtCount.Text >= 2 Then
            txtNotification.Text = ""
            btnConfirm.Enabled = False
            txtNotification.Text = "Sorry Bus from " & cmbDepart.Text & " to " & cmbDestination.Text & " is fully booked"
        Else
            btnConfirm.Enabled = True
            txtNotification.Text = "Ticket Available"

        End If


please help.. thanks
Posted
Updated 23-Aug-12 1:10am
v4

I assume this does not compile ? You should use int.TryParse to work out if txtCount.Text is a number, then if it is, you can compare it. I don't understand the rest of your question, is there more you're asking here ? What is busNumber ? If it's a variable, why not compare to it ?
 
Share this answer
 
Comments
Member 9254084 23-Aug-12 7:05am    
am using init... just want to be able to disable the confirm button if count >=2
Christian Graus 23-Aug-12 7:09am    
I still don't get your issue. Is txtCount.Text returning a number ? I don't think it will, and hence your issue. If it is, you don't have an issue, it should work. So, if you have an issue, int.TryParse is the solution
Member 9254084 23-Aug-12 7:15am    
ok, the thing is, if i just used :
if txtCount >= 2 then
btnConfirm.enabled = false
end if

it works.. but the moment i want to extend the if statement to include :

if txtCount.text >= 2 AND cmbDay.text = "Monday AND txtBusNumber.text = "AT01"

it wont work... the buttton does not disable
Christian Graus 23-Aug-12 7:18am    
Ah, now we get to it. VB.NET is idiotic, so I knew it MIGHT return a number. It may still blow up if there's no number in your textbox. Did you use your debugger to see what was going on ? If you don't know how, you should learn, but MsgBox("-" + cmbDat.text + "-") will show you the text thats being compared, the extra - are to show if the issue is leading or trailing spaces. I recommend doing this : if txtBusNumber.Text.Trim() = "AT01" and cmbDay.text.trim() = "Monday"... This removes trailing spaces that are meaningless to humans, but will stop this comparison from working as you hope
Member 9254084 23-Aug-12 7:15am    
txtCount returns a number...
you need to replace txtCount.Text >= 2 with "Convert.ToInt32(txtCount.Text) >= 2"
 
Share this answer
 
Comments
Christian Graus 23-Aug-12 7:09am    
This will blow up if there's no number in txtCount.Text. That's why you always use int.TryParse
Dim count As Integer
count = Convert.ToInt32(txtCount.Text)
If (count >= 3) And cmbDay.Text = "Monday" And txtBusNumber.Text = "AT02" Then
btnConfirm.Enabled = False

txtNotification.Text = "Bus Fully Booked"

End If


not under init, but under command
 
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