470,587 Members | 1,780 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,587 developers. It's quick & easy.

Populate array with user inputs

I am trying to populate two arrays. One with combo box and the other with a text input. The combo box has multiple choices of different counties people live in. The text input is for income amount of person that lives in each county. I will later need to break info into Average Household income and Number of House Holds surveyed.

Data will look like the following example:
Average Households Income
Ohio: $30,000.00
Hamilton: 40,000.00
Butler: 20,000.00
Clermont: 30,000.00
Warren: 30,000.00
Kentucky: 35,000.00
Boone: 40,000.00
Campbell: 30,000.00
Kenton: 35,000.00

I will use data loaded into array to figure average income for each state. and then total for each county.

I will also need to get the following data:
Number of HouseHolds Surveyed
Ohio: 5
Hamilton: 2
Butler: 1
Clermont: 1
Warren: 1
Kentucky: 5
Boone: 2
Campbell: 2
Kenton: 1

I will load the array with a button click, each time button is clicked input fields reset and input second set of data for array and that continues. Once I have households data entered I can click another button that will show Average Household Income and then a third button to show Number of households surveyed. I will display each in a message box when button is clicked. Right now I need help loading array. I know how to set arrays up and how to hardcode data into the array, but I have no idea how to make inputs go into an array. I have code started if you would like to see.

Thanks for any help you can give.

Option Strict On

Public Class frmSurvey

'Arrays to hold Houshold income and county
Dim intIncome() As Double 'Array for users income
Dim strCounty() As String 'Array for users county live in

Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
'Populate both arrays from user inputs

'Populating array with incomes from each person surveyed and this array works parallel to the second array strCounty()
'To match up income with person in specific county so that data can add to show total income for each county that was inputted.
For i = 0 To intIncome.Length - 1
intIncome(i) = CDbl(txtIncome.Text)

'Populating array from user input from Combobox selections when submit button is clicked the form resets
'After reset another county is selected. After done with all submits I can then do counts for data totals
For i = 0 To strCounty.Length - 1
strCounty(i) = cboCountyState.Text

'After both arrays are filled next figure out how many people were surveyed in each county through btnSurveyed_Click

'clear combobox and textbox for next input
cboCountyState.Text = ""
End Sub

Private Sub btnSurveyed_Click(sender As Object, e As EventArgs) Handles btnSurveyed.Click
'Calculate total number of houses surveyed

Dim intCount As Integer
Dim strHamilton As String = "Hamilton, OH"

'Search for each occurance of Hamilton, OH in strCounty() array
For i = 0 To strCounty.Length - 1
If strCounty(i) = strHamilton Then
intCount += 1
End If


' I have only worked on counting for Hamilton
MessageBox.Show("Number of Households Surveyed" & vbNewLine &
"Ohio: (total Ohio surveyed)" & vbNewLine &
" Hamilton: " & intCount & vbNewLine &
" Butler: " & vbNewLine &
" Clermont: " & vbNewLine &
" Warren: " & vbNewLine &
End Sub
Dec 6 '16 #1
0 969

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Sven Neuberg | last post: by
2 posts views Thread by Anil | last post: by
1 post views Thread by Scott | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.