problem with understanding!
OK so I am new to this forum but I cannot for the life of me figure this out...
It is for school but I have been working on it for 6 hours and I am stumped. What I am trying to do is fill out a form with certain info, put the info into an array, and write it to a listbox using loops, arrays, and maybe a function if I need one.
This is for VB2010 and here is what I have so far... I think there are ways to make it shorter but I cannot figure it out.... maybe just brain dead from all the coffee I have been drinking!
my stuff Code:
Public Class frmIndex
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
'create arrays when btnSubmit is clicked
Const intMAX_SUBSCRIPT As Integer = 14 'max subscript
Dim intCount As Integer = 1 'loop
Dim intSize As Integer 'counter holder
Dim strFirst(intMAX_SUBSCRIPT) As String 'txtFirst to array()
Dim strLast(intMAX_SUBSCRIPT) As String 'txtLast to array()
Dim strAdd(intMAX_SUBSCRIPT) As String 'txtAdd to array()
Dim strCity(intMAX_SUBSCRIPT) As String 'txtCity to array()
Dim strStates(intMAX_SUBSCRIPT) As String 'txtStates to array()
Dim strZip(intMAX_SUBSCRIPT) As String 'txtZip to array()
Dim strSS1(intMAX_SUBSCRIPT) As String 'txtSS1 to array()
Dim strSS2(intMAX_SUBSCRIPT) As String 'txtSS2 to array()
Dim strSS3(intMAX_SUBSCRIPT) As String 'txtSS23 to array()
'init str array incase!
strFirst(intCount) = String.Empty
strLast(intCount) = String.Empty
strAdd(intCount) = String.Empty
strCity(intCount) = String.Empty
strStates(intCount) = String.Empty
strZip(intCount) = String.Empty
strSS1(intCount) = String.Empty
strSS2(intCount) = String.Empty
strSS3(intCount) = String.Empty
strFirst(intCount) = txtFirst.Text
strLast(intCount) = txtLast.Text
strAdd(intCount) = txtAdd.Text
strCity(intCount) = txtCity.Text
strStates(intCount) = cboStates.Text
strZip(intCount) = txtZip.Text
strSS1(intCount) = txtSS1.Text
strSS2(intCount) = txtSS2.Text
strSS3(intCount) = txtSS3.Text
'create a random object (number)
Dim rand As New Random
'fill the listbox with the info
lstApplicants.Items.Add(strLast(intCount) & ", " & strFirst(intCount) & "; " & strAdd(intCount) & ", " & strCity(intCount) & ", " & strStates(intCount) & " " & strZip(intCount) & "; " & strSS1(intCount) & "-" & strSS2(intCount) & "-" & strSS3(intCount))
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtFirst.Clear()
txtLast.Clear()
txtAdd.Clear()
txtZip.Clear()
txtSS1.Text = ("xxx")
txtSS2.Text = ("xx")
txtSS3.Text = ("xxxx")
cboStates.SelectedIndex = -1
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
I hope i posted this correctly and if I didn't I will try to fix it.
Re: problem with understanding!
You are declaring all variables inside a sub, this way tghey do exist only in this sub, if this sub is done all information is LOST. Declare them in the genral section (above any function or sub).
In the _click event sub you do declare the arrays (initially all elements are empty), set the item number 1 (which isn't the first) to an empty string(which it is already) and then set the same element equal to a .text property of a textbox (I believe). Hopefully this textbox does hold any information at that time, otherwise the array-element will remain an empty string.
After that you create a random number, but you never use it!
Finaly you add all the arrays first element to a ListBox.
do you really want to do that?