Results 1 to 2 of 2

Thread: problem with understanding!

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    2

    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:
    1. Public Class frmIndex
    2.  
    3.     Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    4.         'create arrays when btnSubmit is clicked
    5.         Const intMAX_SUBSCRIPT As Integer = 14 'max subscript
    6.         Dim intCount As Integer = 1   'loop
    7.         Dim intSize As Integer       'counter holder
    8.         Dim strFirst(intMAX_SUBSCRIPT) As String    'txtFirst to array()
    9.         Dim strLast(intMAX_SUBSCRIPT) As String     'txtLast to array()
    10.         Dim strAdd(intMAX_SUBSCRIPT) As String      'txtAdd to array()
    11.         Dim strCity(intMAX_SUBSCRIPT) As String     'txtCity to array()
    12.         Dim strStates(intMAX_SUBSCRIPT) As String   'txtStates to array()
    13.         Dim strZip(intMAX_SUBSCRIPT) As String      'txtZip to array()
    14.         Dim strSS1(intMAX_SUBSCRIPT) As String      'txtSS1 to array()
    15.         Dim strSS2(intMAX_SUBSCRIPT) As String      'txtSS2 to array()
    16.         Dim strSS3(intMAX_SUBSCRIPT) As String      'txtSS23 to array()
    17.  
    18.         'init str array incase!
    19.  
    20.             strFirst(intCount) = String.Empty
    21.             strLast(intCount) = String.Empty
    22.             strAdd(intCount) = String.Empty
    23.             strCity(intCount) = String.Empty
    24.             strStates(intCount) = String.Empty
    25.             strZip(intCount) = String.Empty
    26.             strSS1(intCount) = String.Empty
    27.             strSS2(intCount) = String.Empty
    28.             strSS3(intCount) = String.Empty
    29.  
    30.             strFirst(intCount) = txtFirst.Text
    31.             strLast(intCount) = txtLast.Text
    32.             strAdd(intCount) = txtAdd.Text
    33.             strCity(intCount) = txtCity.Text
    34.             strStates(intCount) = cboStates.Text
    35.             strZip(intCount) = txtZip.Text
    36.             strSS1(intCount) = txtSS1.Text
    37.             strSS2(intCount) = txtSS2.Text
    38.             strSS3(intCount) = txtSS3.Text
    39.  
    40.             'create a random object (number)
    41.             Dim rand As New Random
    42.  
    43.             'fill the listbox with the info
    44.             lstApplicants.Items.Add(strLast(intCount) & ", " & strFirst(intCount) & "; " & strAdd(intCount) & ", " & strCity(intCount) & ", " & strStates(intCount) & " " & strZip(intCount) & "; " & strSS1(intCount) & "-" & strSS2(intCount) & "-" & strSS3(intCount))
    45.  
    46.     End Sub
    47.  
    48.     Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    49.         txtFirst.Clear()
    50.         txtLast.Clear()
    51.         txtAdd.Clear()
    52.         txtZip.Clear()
    53.         txtSS1.Text = ("xxx")
    54.         txtSS2.Text = ("xx")
    55.         txtSS3.Text = ("xxxx")
    56.         cboStates.SelectedIndex = -1
    57.  
    58.     End Sub
    59.  
    60.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    61.         Me.Close()
    62.     End Sub
    63.  
    64.  
    65. End Class

    I hope i posted this correctly and if I didn't I will try to fix it.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    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?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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