Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > Checking if text and combo boxes have data
 

Checking if text and combo boxes have data

This is not working.

Could someone please help me out.

If txtCreate.Text = "" Or cmbLeague.SelectedIndex = -1 Or cmbHomeOff.SelectedIndex = -1 Or cmbHomeDef.SelectedIndex = -1 Or cmbAwayOff.SelectedIndex = -1 Or cmbAwayDef.SelectedIndex = -1 Then

... give error

Else

... do something

end if

DTHMTLGOD  Saturday, September 23, 2006 2:09 AM

always use the length property for textual input.

if txtCreate.Text.Length = 0............'and so on

as for the combobox's, what you have done is correct - but this is only if the selected item is not selected (the index)

so over all, this should work:

If Me.txtCreate.Text.Length = 0 Or Me.cmbLeague.SelectedIndex = -1 Or Me.cmbHomeOff.SelectedIndex = -1 Or Me.cmbHomeDef.SelectedIndex = -1 Or Me.cmbAwayOff.SelectedIndex = -1 Or Me.cmbAwayDef.SelectedIndex = -1 Then

... give error

Else

... do something

end if

however, if you want to check if there CONTAINS items in the combobox's, then use the items property and look at the count property:

 

Me.cmbLeague.Items.Count = 0

so having this implemented in the solution:

If Me.txtCreate.Text.Length = 0 Or Me.cmbLeague.Items.Count = 0 Or Me.cmbHomeOff.Items.Count = 0 Or Me.cmbHomeDef.Items.Count = 0 Or Me.cmbAwayOff.Items.Count = 0 Or Me.cmbAwayDef.Items.Count = 0 Then

... give error

Else

... do something

end if

if it's still not working, please tell us what's happening

ahmedilyas  Saturday, September 23, 2006 2:16 AM

always use the length property for textual input.

if txtCreate.Text.Length = 0............'and so on

as for the combobox's, what you have done is correct - but this is only if the selected item is not selected (the index)

so over all, this should work:

If Me.txtCreate.Text.Length = 0 Or Me.cmbLeague.SelectedIndex = -1 Or Me.cmbHomeOff.SelectedIndex = -1 Or Me.cmbHomeDef.SelectedIndex = -1 Or Me.cmbAwayOff.SelectedIndex = -1 Or Me.cmbAwayDef.SelectedIndex = -1 Then

... give error

Else

... do something

end if

however, if you want to check if there CONTAINS items in the combobox's, then use the items property and look at the count property:

 

Me.cmbLeague.Items.Count = 0

so having this implemented in the solution:

If Me.txtCreate.Text.Length = 0 Or Me.cmbLeague.Items.Count = 0 Or Me.cmbHomeOff.Items.Count = 0 Or Me.cmbHomeDef.Items.Count = 0 Or Me.cmbAwayOff.Items.Count = 0 Or Me.cmbAwayDef.Items.Count = 0 Then

... give error

Else

... do something

end if

if it's still not working, please tell us what's happening

ahmedilyas  Saturday, September 23, 2006 2:16 AM

You can use google to search for other answers

Custom Search

More Threads

• How to scan Folders into a TreeView?
• VBS to Telnet to Server and Pass Variables for User and Password??
• Trouble installing/Finding Reportviewer contol to VB Express 2008
• Can't run copy of vb project
• Total dummy - compiling
• Project Settings: Data Source/ Connection String
• I can't use my own program!
• Decision Tree Problem - Won't Load Function
• Problem with using combobox1 output to textbox1 input as a text instead of a character.
• msgbox prompt to save only if new or changed info