Results 1 to 7 of 7

Thread: Collections... <RESOLVED>

  1. #1

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Arrow Collections... <RESOLVED>

    Hiya doin vb ppl?

    Ok, got a lot of questions here... I just moved from vb6 to vb.net... and was wondering about a lot of stuff!!!

    K, first of all, in VB6 there were collections...

    for instance, you could have 60 textbox with the same name
    and do a quick call with formulas for the index... for example:

    VB Code:
    1. For tmpval = 1 To 20 Step 2
    2.         txtBox(tmpval).Text = "Number: " & Str(tmpval * 2)
    3. Next tmpval
    4. For tmpval = 1 To 20
    5.         If txtBox(tmpval).Text = "" Then txtBox(tmpval).Text = "Unknown number!"
    6. Next tmpval
    ... you get the idea... now the collection (index property) IS NO MORE!!!!!!! How can I manipulate my objects with formulas now... ???

    And if you have any tips on other problems I might encounter coz Im moving from vb6 to .net, please post em rigt away.... plus I noticed that vb.net had a lot of "friends" everywhere!!! like as friendly and stuff... uh, WHAT? lol, post me back ppl!

    Oh yeah, I was also wondering how you could notice if an object is loaded...?

    because my method, well, sucks:
    I try to load an object, if an error occurs, and the error corresponds with the object bering allready loaded, than it resumes and continue another proces... but this method causes the program to do an error and isn't effective to my opinion, is there any other logical way to do it??? (I did that in vb6, now im lost with the index/collection disapearing and stuff...!)
    Last edited by Ruku; Nov 10th, 2003 at 10:26 AM.

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The collections thing you mention are commonly referred to as Control Arrays. The lack of them in .NET is like the first stubbling block of all converters from VB6, but good news this question comes up all the time. Just do a quick search for 'Control Array' in the .NET section and you will get lots of helpful advise. The general bit is to use AddHandler or the Handles keyword to catch events for multiple controls in the same event handler.

    Although to do the code you showed you'd just have to make a big ass array of the controls you want and then run the exact same code. Something like this:
    VB Code:
    1. 'make control array
    2. Dim txtBox() As TextBox={TextBox1,TextBox2,TextBox3,TextBox4,TextBox%,TextBoxYouGetThePicture}
    3. For tmpval = 1 To 20 Step 2
    4.         txtBox(tmpval).Text = "Number: " & (tmpval * 2).ToString
    5. Next
    6. For tmpval = 1 To 20
    7.         If txtBox(tmpval).Text = "" Then txtBox(tmpval).Text = "Unknown number!"
    8. Next
    The bigger question should be why the heck do you need 60 textboxess.


    I'm not sure what you mean by the object being 'loaded'. You can check if it is nothing just like in VB6.

  3. #3

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Originally posted by Edneeis
    The collections thing you mention are commonly referred to as Control Arrays. The lack of them in .NET is like the first stubbling block of all converters from VB6, but good news this question comes up all the time. Just do a quick search for 'Control Array' in the .NET section and you will get lots of helpful advise. The general bit is to use AddHandler or the Handles keyword to catch events for multiple controls in the same event handler.

    Although to do the code you showed you'd just have to make a big ass array of the controls you want and then run the exact same code. Something like this:
    VB Code:
    1. 'make control array
    2. Dim txtBox() As TextBox={TextBox1,TextBox2,TextBox3,TextBox4,TextBox%,TextBoxYouGetThePicture}
    3. For tmpval = 1 To 20 Step 2
    4.         txtBox(tmpval).Text = "Number: " & (tmpval * 2).ToString
    5. Next
    6. For tmpval = 1 To 20
    7.         If txtBox(tmpval).Text = "" Then txtBox(tmpval).Text = "Unknown number!"
    8. Next
    The bigger question should be why the heck do you need 60 textboxess.


    I'm not sure what you mean by the object being 'loaded'. You can check if it is nothing just like in VB6.
    lol, the 60 textboxes was just an example.... and for loaded... I just mean to check if the object with the array allready exists... for instance, making a sub creating an object with a free array...

    checking from 1 to 60... finding 2 doesn't exists, create txtBox(2)... get it? And im not sure if there was a way to do it in vb6...

    And there is no quicker way to add objects in an array?!?!
    VB Code:
    1. Dim txtBox() As TextBox={TextBox1,TextBox2, ...]

    So if I need 43243291823 objects I have to input them all one by one in the code????? There must be another way to load a bunch of objects... no?

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sure you can load the array via a loop if you want.
    VB Code:
    1. 'load all textboxes that or on the form itself NOT another container
    2. Dim al as New ArrayList
    3. For Each txt As TextBox In Me.Controls
    4.   'if the textbox isn't already in the array then load it
    5.   If Not al.Contains(txt) Then al.Add(txt)
    6.   'of course in this example none will be since I just initialized the array
    7.   'before the loop
    8. Next
    9. 'to return a type specific array from an arraylist use ToArray
    10. Dim txt() As TextBox=al.ToArray(gettype(TextBox))
    You can use the contains method or any ICollection object to see if something is already in it. The thing to keep in mind with this is that you will be checking specific instances for a match.

  5. #5

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Originally posted by Edneeis
    Sure you can load the array via a loop if you want.
    VB Code:
    1. 'load all textboxes that or on the form itself NOT another container
    2. Dim al as New ArrayList
    3. For Each txt As TextBox In Me.Controls
    4.   'if the textbox isn't already in the array then load it
    5.   If Not al.Contains(txt) Then al.Add(txt)
    6.   'of course in this example none will be since I just initialized the array
    7.   'before the loop
    8. Next
    9. 'to return a type specific array from an arraylist use ToArray
    10. Dim txt() As TextBox=al.ToArray(gettype(TextBox))
    You can use the contains method or any ICollection object to see if something is already in it. The thing to keep in mind with this is that you will be checking specific instances for a match.
    Ahhh, now were talkin! Thx, that really helps a lot of problems I had trouble with!!! But for the object loaded statment, what could I do?

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If loaded and already in the array are the same thing then the Contains method takes care of it. Contains checks the array for an object. If loaded means intialized to an instance then test if it is Nothing.

  7. #7

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Alrit

    Originally posted by Edneeis
    If loaded and already in the array are the same thing then the Contains method takes care of it. Contains checks the array for an object. If loaded means intialized to an instance then test if it is Nothing.
    Thanks, I guess that shuts me up... for the moment

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

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