|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VB: checking textboxes if empty
halu again,
i have a problem dealing with my code. this i think is simple but i can't make it happen. i'm a newbie to this thing. hehe... i'm trying to check an array of textboxes if one is empty. this is the flow. textboxes are put to array, let's say: Friend txt() As TextBox = {txtLastName, txtFirstName, txtMI, txtAddress, txtHomePhone, txtCellularPhone} then i want to check if one of textboxes is empty. here is my code: Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim i As Integer = 0 Try While (i < txt.Length) And (Not txt(i).Text = String.Empty) i += 1 End While Catch ex As Exception MsgBox(ex.Message) End Try If i < txt.Length Then MsgBox("There's an empty textbox") End If End Sub the problem is, it gets an exception with an error of: Object reference not set to an instance of an object. this is what i get when i try to click the add button... need help, ayan |
|
#2
|
|||
|
|||
|
i try this but to no success.
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim txt() As TextBox = {txtLastName, txtFirstName, txtMI, txtAddress, txtHomePhone, txtCellularPhone} Dim i As Integer = 0 Try While i < txt.Length And (Not (txt(i).Text = String.Empty)) i = i + 1 End While Catch ex As Exception MsgBox(ex.Message) End Try If i < txt.Length Then MsgBox("There's an empty textboxe(s)") End If End Sub i think i can't make this code work. it's just similar in other languages. the logic, you know. but this is not fair. huhuhuhu... i can't make it work. i did a C code. check people. it works. void main(){ char c[]={'a','b','c',' ','e','f'}; int i; for(i=0;i<strlen(c)-1&&c[i]!=' ';i++); if(i<strlen(c)) printf("there's a space\n"); } by the way, the problem, in the above code (Visual Basic.NET) is an exception (again...) it says about: index was outside the bounds of the array i think i can't make it. thanks anyway... good luck to all member, ayan |
|
#3
|
|||
|
|||
|
halu,
i solved it. but the fact is i have a "not good idea". i hope this code helps to someone. this is the way i solved it. Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim txt() As TextBox = {txtLastName, txtFirstName, txtMI, txtAddress, txtHomePhone, txtCellularPhone} Dim i As Integer = 0 Dim flag As Integer = 0 While i < txt.Length And flag = 0 If txt(i).Text = String.Empty Then flag = 1 End If i += 1 End While If flag Then MsgBox("There is/are empty textbox(es).") End If End Sub i set something like flag for a purpose of knowing if there's an empty textbox. thanx. and oh, if anybody has some better ideas, can i have it? hehe... just a thought. but if so, thanx... still needing help, ayan |
|
#4
|
|||
|
|||
|
halu again,
i solved it. it just i encounter something in the net. check this site... www.programmersheaven.com hehehe... i made a groupbox and check every control in the groupbox... this is it. Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim c As Control For Each c In GroupBox1.Controls If c.Text = String.Empty Then MsgBox("Please Enter the " & c.Name, MsgBoxStyle.Information, "Note") c.Focus() Exit Sub End If Next End Sub thanx people... thanx for everything... member, ayan |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > VB: checking textboxes if empty |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|