+ Reply to Thread
Results 1 to 7 of 7

Thread: Object Arrays

  1. #1
    DarkAngel is offline VB.NET Forum Newbie DarkAngel is on a distinguished programming path ahead
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2010
    Age
    24
    Posts
    5
    Reputation
    0

    Default Object Arrays

    In the old days of VB6 when attempting to copy an object and paste it, it asks if you would like to turn the object into an object array (good for using labels (in an object array) to display an array of numbers).

    It no longer asks me if I would like to make Object Arrays (As im using VB 2010). Can someone help me out? I dont see anything regarding this on MSDN.

  2. #2
    Anxious117 is offline VB.NET Forum Newbie Anxious117 is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5
    Join Date
    Feb 2010
    Age
    23
    Posts
    4
    Reputation
    0

    Default

    in Visual Basic.Net you have to declare the array yourself like for example
    Dim myNum(5) as Integer
    this declares the array with an Integer data type then
    give each element of the array a value
    myNum(0) = 1
    myNum(1) = 2
    myNum(2) = 3
    myNum(3) = 4
    myNum(4) = 5

  3. #3
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    10,843
    Reputation
    1443

    Default

    You can refer to each control in the Controls collection by Integer index or String index (Name). All containers act as their own collections of controls.

    Events can be handled for multiple controls (Handles this.Click, that.Click) something you can write manually, or set up directly from the Designer (events view in Properties window), or assign dynamically in code with AddHandler. In the event handler the 'sender' parameter refer to the control object that raised the event.

    You can also declare a regular array variable (as Anxious117 said) and keep references to your array of controls here, but usually the Controls collection and the common event handling makes that redundant. Arrays are also generally less flexible and usable than collections that have great support in .Net.

  4. #4
    DarkAngel is offline VB.NET Forum Newbie DarkAngel is on a distinguished programming path ahead
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2010
    Age
    24
    Posts
    5
    Reputation
    0

    Default

    I looked up on msdn the collections class a you had suggested
    How to: Create a Collection of Objects

    Perhaps Im not reading or understanding this right. What I would like to do is make an array of 64 labels Ie DataL(i) that hold a single bit (I would assume to use an Integer variable type). Upon clicking a button, a 64 bit string entered by a user in datatextbox.text would be stored bit by bit into the array of labels (from 0-63) for easy bit viewing. This would allow me to monitor (as I modify and permutate) the bits to attempt to encrypt the 64bit bitstream. The 2 primary things holding me back at the moment is.
    1) I do not know how to create object arrays in 2010
    2) I dont remember how to select specific bits in strings (ie refer to the 34th bit in a 64 bit string) though im currently looking at the "GetChar" function. Is there a better function for doing this?

  5. #5
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    10,843
    Reputation
    1443

    Default

    BitArray Class (System.Collections) would probably be preferred to work with. Some System.Text.Encoding to GetBytes of string.

  6. #6
    DarkAngel is offline VB.NET Forum Newbie DarkAngel is on a distinguished programming path ahead
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2010
    Age
    24
    Posts
    5
    Reputation
    0

    Default

    Mmm, Im not sure I can assign an array of labels as a "bitarray"

    Ill look up System.Text.Encoding to see if it applys

    Edit : I have no desire to change the string to different encoding methods. I plan to keep it as a string. I just want to be able to do the following

    0100101000101

    store the 5th bit of the above string ("1") into the array DataL(4)

    as for the array of labels. I want to say the array Data(4) = DataL(4)
    Last edited by DarkAngel; 02-23-2010 at 2:25 PM.

  7. #7
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    10,843
    Reputation
    1443

    Default

    Here is a basic sample:
    Code:
    Dim s As String = "hi"
    Dim ba As New BitArray(System.Text.Encoding.UTF8.GetBytes(s))
    For i As Integer = 0 To ba.Length - 1
        Dim lbl As New Label
        With lbl
            .AutoSize = True
            .Name = "Ba" & i.ToString
            .Text = If(ba(i), "1", "0")
        End With
        Me.FlowLayoutPanel1.Controls.Add(lbl)
    Next
    The controls can now be referred to as Me.FlowLayoutPanel1.Controls(3) or Me.FlowLayoutPanel1.Controls("Ba3").

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts