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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subs and Arrays

Status
Not open for further replies.

cpalermo

ISP
Sep 13, 2001
10
US
Hopefully, someone can help me out here.

I have a control array of 9 textboxes. I want to pass the array of the textbox to a subwhere processing can occur for each instance of textbox.text

The textboxes contain name, address, city, state, etc... in the sub, I want add these to a database. I want to use this sub, as customers will be added from more than one screen.

ie:

From Form1:
=============================
sub cmdAddCustomer_click()
dbCustAdd(textbox1())
end sub
=============================

From Module1
=============================
Sub dbCustAdd(textbox as TextBox)
sqlString = "insert into customers values('"
for each textbox1.text in textbox1
sqlString-sqlString & textbox1.text & "'"
next
db.execute(sqlString)
end sub
==============================
This does not work... can anyone help?

TIA,
Chris

 
Sorry, in a rush here at the moment, so this is merely an information bulletin rather than a solution: a control array is not the same thing as an array of controls. It's just bad terminology from MS. So you can't pass a control array in the same way as you might pass, say, an array of integers.
 
A control array is an object not an array.
sub cmdAddCustomer_click()
dbCustAdd(textbox1) '??? Textbox1 is control array name
end sub
=============================

From Module1
=============================
Sub dbCustAdd(objTxt as object)
Dim txtW As textbox
sqlString = "insert into customers values('"
for each txtw in objTxt
sqlString = sqlString & txtw.text & "'"
next
db.execute(sqlString)
end sub
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Also, ditch the parens on a Sub call or add "Call". Parens are used on function calls around the argument list and around individual arguments that are expressions.
Use
Call dbCustAdd(textbox1)
or
dbCustAdd textbox1 Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top