CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: option buttons

  1. #1
    Guest

    option buttons

    hi vbguru

    there r 2 opt butns with in a frame and 2 without a frame on design form here i want to select one among the
    with in frame one from without a frame
    give me suitable example

    give me advtgs & disadvantage of collection s over arrayss
    with example ?


  2. #2
    Join Date
    Oct 1999
    Location
    S.W. Wyoming
    Posts
    25

    Re: option buttons

    You can, in code, select an option button regardless of whether it resides within or outside of a frame, by setting its "Value" property to "True". The within/without issue only dictates which other options buttons will be automatically switched to "False" when one of the group is clicked, or has its Value property set to true. Example:


    MyButton.Value = true




    will "click" the desired button no matter where it resides (inside a frame, or not).

    As for collections vs. arrays, the difference is night and day: an array can only contain elements of a single type (though that type may be a user-defined data type containing an admixture of other data types), whereas a collection may contain ANY object (typically created by a class module) whatever. Examples:


    Type MyType
    Dim AnInt as Intger
    Dim AString as string
    End Type
    private MyArray(1 to 100) as MyType
    MyArray(5).AnInt = 5
    MyArray(6).AString = "This is a string"




    The above array can contain ONLY objects of type "MyType". Or, if the array was declared "As Integer", can contain only integers. Or, if "As String", only strings. Etc.
    On the other hand, let us assume you have designed a financial statement (in OOP form). You may have created class modules to define objects of the classes "AccountLine", "HeaderLine", "BlankLine", "TotalLine", etc. Then, your financial statement could, conceivably consist of a collection of these different classes; each is different, with its own encapsulated data and methods. Yet the "Financial Statement" collection can hold them all. No examples here: it would take a lot of code to demonstrate. But, hopefully, the explanation will suffice.



    Reid Allen Robbins
    2205 E. Teton Blvd.
    Green River, WY 82935

  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: option buttons

    Collections need not be Complex stuff with Financial statements :-)
    Following the same example of UDT, you can make a collection like this:

    dim pColectn as Collection
    dim i as integer, szStr as string
    set pColectn = new Collection
    i = 4
    pColectn.Add i ' Element 1 : Note Collections go From 1 to N
    szStr = "Some string"
    pColectn.Add szStr ' Element 2
    i = 5
    pColectn.Add i ' Element 3
    ' Note the difference here :
    i = 6
    pColectn.Add i ' Element 4
    i = 7
    pColectn.Add i ' Element 5
    i = 8
    pColectn.Add i ' Element 6
    szStr = " string 2"
    pColectn.Add szStr ' Element 7

    for i = 1 to pColectn.Count
    Debug.print pColectn.Item(i)
    next i

    set pColectn = nothing
    '
    'should give you a debug print of:
    4
    string 1
    5
    6
    7
    8
    string 2



    Suddenly, if you choose to: you can have something like:
    dim pCls as SomeClass
    set pCls = New Class
    pCls.Prop1 = something ''.. and

    pColectn.Add pCls ' for 7th Element!!!

    That is the power of collections. It gives big enough rope...to hang oneself:-)

    Simply said: An array is type of 'similar elements', while a Collection can contain a collection of vertually anything with what ever intermixing, incl regular types , classes etc.
    But you cannot add an UDT to a collection, AFAIK.


    RK

  4. #4
    Join Date
    Jun 1999
    Location
    virginia
    Posts
    16

    Re: option buttons

    Arrays are faster than collections. The advantage of collections is that they can be added to with an id and selected using that id which makes collections simple to retrieve data (if stored with an id). Unless you need this then use arrays. Such as:
    collection.Add Text1.Text, Id ==> where id = what you want to identify this by.
    To retrieve the data for id use:
    collection.Item("id")

    A varient array can hold many different types and can be changed from string to integer to single, etc. They too are slow and take up more space then typed arrays. Such as:

    Dim MyArray(10) as Variant
    MyArray(1)="This is Text"
    MyArray(1)=123 ==> Has changed text to an integer

    Hope this rambling helps.


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

Featured