Question Object Arrays

DarkAngel

Member
Joined
Feb 19, 2010
Messages
5
Programming Experience
1-3
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.
 
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
 
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.
 
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?
 
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:
Here is a basic sample:
VB.NET:
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").
 
Back
Top