|
-
Nov 23rd, 2005, 01:29 PM
#1
Thread Starter
Addicted Member
Please help with Storing values into Array
Hello, I have checked the Visual Basic libraries to see how VB declares and uses Arrays. I know how to declare and store values into the array from going through the samples they have in the sample libraries. But I am not sure if the values that I'm storing into the array are in the format that I want them to be in. The example which I have followed stores strings, but I want to store numerical values inside of my array.
I have arranged a 3x5 array of checked boxes in my ChildForm, and I want to store the state of the checked boxes into an array: Here is the algorithm that I think would work but dont think it is very efficient. Maybe I can have this in a for loop or something that can check the status of the entire amount of the 3x5 array of checked boxes and store the values into the myArray all in one shot when I press the Finished button. I have included this code and it gives me errors, (tons of them), can anyone help... I have attached a file to give a visual of what I am planing to do. Can anyone help please
Dim myArray As New ArrayList
For X = 1 to 15
if(CheckedBoxX.checked) then
myArray.Add[X] = 1
Else
myArray.Add[X] = 0
End if
Next X
=============Here is my code=====================
Public Class ParentForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents btnUDC_1 As System.Windows.Forms.Button
Friend WithEvents btnUDC3 As System.Windows.Forms.Button
Friend WithEvents btnUDC2 As System.Windows.Forms.Button
Friend WithEvents btnUDC1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.StatusBar1 = New System.Windows.Forms.StatusBar
Me.Panel1 = New System.Windows.Forms.Panel
Me.btnUDC1 = New System.Windows.Forms.Button
Me.btnUDC3 = New System.Windows.Forms.Button
Me.btnUDC2 = New System.Windows.Forms.Button
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'StatusBar1
'
Me.StatusBar1.Location = New System.Drawing.Point(0, 416)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Size = New System.Drawing.Size(744, 22)
Me.StatusBar1.TabIndex = 1
Me.StatusBar1.Text = "Time:"
'
'Panel1
'
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel1.Controls.Add(Me.btnUDC1)
Me.Panel1.Controls.Add(Me.btnUDC3)
Me.Panel1.Controls.Add(Me.btnUDC2)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Right
Me.Panel1.Location = New System.Drawing.Point(648, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(96, 416)
Me.Panel1.TabIndex = 4
'
'btnUDC1
'
Me.btnUDC1.Location = New System.Drawing.Point(8, 16)
Me.btnUDC1.Name = "btnUDC1"
Me.btnUDC1.TabIndex = 10
Me.btnUDC1.Text = "UDC #1"
'
'btnUDC3
'
Me.btnUDC3.Location = New System.Drawing.Point(8, 96)
Me.btnUDC3.Name = "btnUDC3"
Me.btnUDC3.TabIndex = 2
Me.btnUDC3.Text = "UDC #3"
'
'btnUDC2
'
Me.btnUDC2.Location = New System.Drawing.Point(8, 56)
Me.btnUDC2.Name = "btnUDC2"
Me.btnUDC2.TabIndex = 1
Me.btnUDC2.Text = "UDC #2"
'
'ParentForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(744, 438)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.StatusBar1)
Me.IsMdiContainer = True
Me.Name = "ParentForm"
Me.Text = "Character Window"
Me.Panel1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub ParentForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private mintNumForms As Integer = 0 'To Track the number of Windows open
Private theKid As New ucdDialog 'saves the status of the ucdDialog window
Private Sub btnUDC1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUDC1.Click
Dim temp As Boolean 'Setting the temp variable to a boolean to check the status of the checked boxes
Dim myArray As New ArrayList 'Declaring an Array that will store the state of the checked boxes
mintNumForms = 1
Call WriteStatus()
Call myArray()
With theKid
.ShowDialog()
.Text = "User Defined 1 " & CStr(Me.numForms)
temp = theKid.CheckBox1.Checked
End With
End Sub
Private Sub myArray() 'Storing each state of the CheckBox into myArray
Dim myArray As New ArrayList
Dim X As Integer
For X = 1 To 15 'Checking the status of all the CheckBox
If (CheckedBoxX.checked) Then
myArray.Add([X] = 1)
Else
myArray.Add([X] = 0)
End If
Next X
End Sub
Friend ReadOnly Property numForms() As Integer
Get
Return mintNumForms
End Get
End Property
Private Sub WriteStatus()
'StatusBar1.Text = "Number of Child forms: " & mintNumForms.ToString
End Sub
End Class
=======================================================
Last edited by Srig007; Nov 23rd, 2005 at 02:48 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|