Results 1 to 12 of 12

Thread: shorten arg number ?? {Sorted by Edneeis}

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    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:
    1. 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)  
    2.  
    3. MyAdapter.Fill(MyDataset, "MyTab")
    4. Dim MyDataRow As DataRow = MyDataset.Tables("MyTab").NewRow
    5. MyDataRow("C_URL") = txt1.Text
    6. MyDataRow("C_Category") = comb1.Text
    7. MyDataRow("C_language") = comb2.Text
    8. MyDataRow("C_username") = txt3.Text
    9. .                         txt4.Text
    10. .                         txt5.Text
    11. .                         txt6.Text
    12. End Function
    13.  
    14. ' Call it like so :
    15.  
    16. 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.

  2. #2

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I hate this .It looks horrible.Isn't it ?
    Last edited by Pirate; Jan 19th, 2003 at 07:28 PM.

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    anyone had a look at this ??

  4. #4

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    not even a word !!

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    i did try pirate but to no avail!

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

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Public Function Save(ByVal ctrls() As Control)
    2.  
    3.         'MyAdapter.Fill(MyDataset, "MyTab")
    4.         Dim MyDataRow As DataRow = MyDataset.Tables("MyTab").NewRow
    5.         MyDataRow("C_URL") = ctrls(0).Text
    6.         MyDataRow("C_Category") = ctrls(1).Text
    7.         MyDataRow("C_language") = ctrls(2).Text
    8.         MyDataRow("C_username") = ctrls(3).Text
    9.         ctrls(4).Text()
    10.         ctrls(5).Text()
    11.         ctrls(6).Text()
    12.     End Function
    13.  
    14.         ' Call it like so :
    15.         Dim ctrls() As Control = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, ComboBox1, ComboBox2}
    16.         Save(ctrls)

  8. #8

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Edneeis you are the best !
    That's what I am after . Thank You !

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  10. #10

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    No worries , It's working fine . I tested it many times , it's . thanx

  11. #11
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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?

  12. #12

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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
  •  



Click Here to Expand Forum to Full Width