|
-
Jan 19th, 2003, 07:05 PM
#1
Thread Starter
Sleep mode
shorten arg number ?? {Sorted by Edneeis}
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 :
VB Code:
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 ?
Last edited by Pirate; Jan 20th, 2003 at 09:03 PM.
-
Jan 19th, 2003, 07:06 PM
#2
Thread Starter
Sleep mode
I hate this .It looks horrible.Isn't it ?
Last edited by Pirate; Jan 19th, 2003 at 07:28 PM.
-
Jan 20th, 2003, 01:06 PM
#3
Thread Starter
Sleep mode
anyone had a look at this ??
-
Jan 20th, 2003, 05:56 PM
#4
Thread Starter
Sleep mode
-
Jan 20th, 2003, 06:33 PM
#5
Fanatic Member
i did try pirate but to no avail!
and by all means that doesn't mean it can't be done!
-
Jan 20th, 2003, 06:38 PM
#6
Thread Starter
Sleep mode
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 .
-
Jan 20th, 2003, 08:24 PM
#7
VB Code:
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)
-
Jan 20th, 2003, 09:00 PM
#8
Thread Starter
Sleep mode
Edneeis you are the best !
That's what I am after . Thank You !
-
Jan 20th, 2003, 09:40 PM
#9
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.
-
Jan 20th, 2003, 09:54 PM
#10
Thread Starter
Sleep mode
No worries , It's working fine . I tested it many times , it's . thanx
-
Jan 20th, 2003, 10:23 PM
#11
PowerPoster
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?
-
Jan 20th, 2003, 10:33 PM
#12
Thread Starter
Sleep mode
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|