PDA

Click to See Complete Forum and Search --> : shorten arg number ?? {Sorted by Edneeis}


Pirate
Jan 19th, 2003, 06:05 PM
I dunno how to explain this but I will try to be clear :
how can I declare array of textbox . I prefer you look at what I am trying to do :

Public Function Save(ByVal txt1 As TextBox, ByVal txt2 As TextBox, ByVal txt3 As TextBox, ByVal txt4 As TextBox, ByVal txt5 As TextBox, ByVal txt6 As TextBox, ByVal comb1 As ComboBox, ByVal comb2 As ComboBox)

MyAdapter.Fill(MyDataset, "MyTab")
Dim MyDataRow As DataRow = MyDataset.Tables("MyTab").NewRow
MyDataRow("C_URL") = txt1.Text
MyDataRow("C_Category") = comb1.Text
MyDataRow("C_language") = comb2.Text
MyDataRow("C_username") = txt3.Text
. txt4.Text
. txt5.Text
. txt6.Text
End Function

' Call it like so :

Save(TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, ComboBox1, ComboBox2)


is there another way to shorten this by declaring a collection of textbox ? Is it possible or Do I need to sleep ?:rolleyes:

Pirate
Jan 19th, 2003, 06:06 PM
I hate this .It looks horrible.Isn't it ?:confused:

Pirate
Jan 20th, 2003, 12:06 PM
anyone had a look at this ??

Pirate
Jan 20th, 2003, 04:56 PM
not even a word !!

nswan
Jan 20th, 2003, 05:33 PM
i did try pirate but to no avail!

and by all means that doesn't mean it can't be done!

Pirate
Jan 20th, 2003, 05:38 PM
I am not quite sure of doing this but I am guessing this has a way that shorten the number of args .Maybe using Collection method .dunno really .

Edneeis
Jan 20th, 2003, 07:24 PM
Public Function Save(ByVal ctrls() As Control)

'MyAdapter.Fill(MyDataset, "MyTab")
Dim MyDataRow As DataRow = MyDataset.Tables("MyTab").NewRow
MyDataRow("C_URL") = ctrls(0).Text
MyDataRow("C_Category") = ctrls(1).Text
MyDataRow("C_language") = ctrls(2).Text
MyDataRow("C_username") = ctrls(3).Text
ctrls(4).Text()
ctrls(5).Text()
ctrls(6).Text()
End Function

' Call it like so :
Dim ctrls() As Control = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, ComboBox1, ComboBox2}
Save(ctrls)

Pirate
Jan 20th, 2003, 08:00 PM
Edneeis you are the best !:)
That's what I am after . Thank You !

Edneeis
Jan 20th, 2003, 08:40 PM
No problem, anytime.

It is shorter but its not perfect. For instance the order that the controls are added to the array effect their index. So if you change the order you fill the array and the values will be changing fields. But for a quick answer it works.

Pirate
Jan 20th, 2003, 08:54 PM
:D No worries , It's working fine . I tested it many times , it's :cool: . thanx

hellswraith
Jan 20th, 2003, 09:23 PM
I would create a structure and pass it in to the function. Passing controls pointers around just seems sloppy unless you are actually going to edit that controls properties. Later on down the road, using a structure might lessen the bugs if you start changing things.

Or, why don't you create the function to accept strings as arguments?

Pirate
Jan 20th, 2003, 09:33 PM
Originally posted by hellswraith
I would create a structure and pass it in to the function. Passing controls pointers around just seems sloppy unless you are actually going to edit that controls properties. Later on down the road, using a structure might lessen the bugs if you start changing things.

Or, why don't you create the function to accept strings as arguments?

I've not tried this before "Passing struc to function".if you have any example explains this I would be grateful .;)

in my case ,fast way to write the content of the textboxes and comboboxes directly to DB rather than storing them in variables and then to the DB.