I have 6 textboxes in a page and i wish to loop from "textbo1" to "textbox6" and i used this code :

for i=1 to i=6

dim t as new textbox
t=me.findcontrol("textbox" & i)
msgbox (t.text)

i get this error on the "MSGBOX (T.TEXT)" line saying "Object reference not set to an instance of an object." i used the new keyword , but its still the same !!

Thanks in advance!

Recommended Answers

All 3 Replies

Member Avatar


I think you should use the following code to show the message in message box

msgbox.show (t.text)


You have not set the text property of t and therefore calling t.text results in a null exception.this could be the problem.

You may need to cast the returned control as a TextBox

t = CType(me.findcontrol("textbox" & i), TextBox)

you may also want to check and make sure that t is not Nothing before trying to call its Text property. If the control is not found then t will not be set to a value and you'll get the "Object Reference not set..." error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.