.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 22nd, 2004, 03:26 AM
ayan ayan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 27 ayan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old January 22nd, 2004, 03:48 AM
ayan ayan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 27 ayan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old January 22nd, 2004, 08:41 PM
ayan ayan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 27 ayan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old January 23rd, 2004, 11:12 PM
ayan ayan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 27 ayan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > VB: checking textboxes if empty


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT