Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

control array question

Status
Not open for further replies.

LuckyNate

Programmer
Nov 23, 2002
6
US
hi there...it's me again with another question....
I am using a control array of textboxes to enter data which is imported from another form...
What I need is basically a way to test for a null value in txtText(index)
if null i need to copy the data from each field into each txtText(index) with the same index

i.e.
If txtText(index).text=" " then
'copy data code which i already have wired
Else
index=index+1
endif
I've tried this problem a few different ways, and each time i get either an endless loop that does nothing, or it fills in all the txtText(index) with the same data....
Maybe i'm using the wrong loop structure....any suggestion would be great


 
Try using isnull() or len() = 0...

For "Index", use a for next loop. You can find the upper and lower bounds with the ubound() and lbound() functions

Martin
 
Try this:

For index=0 to txtText.ubound

If not txtText(index).text>"" then
'copy data code which i already have wired
end if

index=index+1

Next

Hope this helps Murali Bala
 
Hello,

I have not had much luck in testing for nulls the way you are doing so; I believe you are actually testing for a space. I have had better luck using Trim(txtText(index).text) = "" with no space between the quotes. It's possible that the code is testing for a space, finding one, and so never incrementing your index, so it's always testing the same text box.

Hope this helps!
 
Sorry, please ignore the line
Index=index+1

This should not be there in my code.

Murali Bala
 
OK...so now i know how to determine whether or not the txtText(i).text is null or not...
but the loop still doesnt work right....
its just filling in every textbox in the control array with the same data....
what i need is a way to loop ONLY if the data isnt copied on the first try...
in other words...once the data is copied once....i need to exit the loop....
is this possible to do?
 
Pls Give me info regarding where u are trying to write this code.. in a commandButton Click? in Text1(Index)'s Lost Focus?

All the Best
Praveen Menon
pcmin@rediffmail.com
 

Dim txt1 As TextBox
Dim txt2 As TextBox

For Each txt1 In txtText
If Len(txt1) = 0 Then
For Each txt2 In txtText
'Change below to where you get your data
txt2.Text = rs(txt2.Index).Value 'aryString(txt2.Index)
Next txt2
Exit For
End If
Next txt1 [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
You might also want to consider testing your textbox text to see if it is equal to vbNullString.

If txtTebtBox1.Text = vbNullString then... BlackburnKL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top