Input boxes

Input boxes in arrays

Page 1 of 1

3 Replies - 2380 Views - Last Post: 27 November 2007 - 04:05 PM Rate Topic: -----

#1 woodduck  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-November 07

Input boxes

Posted 27 November 2007 - 09:15 AM

How would i create an input box that would ask the number of entries into an array. I am having trouble coding this can anyone help??
Is This A Good Question/Topic? 0
  • +

Replies To: Input boxes

#2 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Input boxes

Posted 27 November 2007 - 09:59 AM

Are you saying you want a dynamic array (an array which changes its size as and when you want). Post your code so that we can see if there's a problem in it.
Was This Post Helpful? 0
  • +
  • -

#3 woodduck  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-November 07

Re: Input boxes

Posted 27 November 2007 - 04:01 PM

View PostLouisda16th, on 27 Nov, 2007 - 09:59 AM, said:

Are you saying you want a dynamic array (an array which changes its size as and when you want). Post your code so that we can see if there's a problem in it.

I am getting an expression expected error right here (marked in red) for some reason. I think I need to add a input box that asks the user how many grades they want to add. Just not sure how to do this. Here was my original problem also:

Create an application, save as GradeCalculator, that has the user press a EnterGrades button and enter in values in an input box. As you are entering values, they should be stored in an array.
When you are finished entering grades, have the cancel button return you to the program.
There should be a second button, CalcAvg, that calculates the average score and displays the grades and their average in a label on the form.


Public Class mainForm
	'module-level array
	Private gradeValues As String
	Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
		Me.Close()
	End Sub

	Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click
		'allows users to enter grades
		' stores the grades in the module-level
		' gradeValues array
		For subscript As Integer = 0 To gradeValues.Length - 1
			gradeValues(subscript)[color=#FF0000]=[/color] 
			InputBox("Grade Value:", "Grade Values")

		Next subscript
	End Sub

	Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
		'displays grades and calculated average grade
		Dim gradeValues() As Integer = {}
		Dim gradeAccumulator As Integer
		Dim averageGrade As Double
		' accumulates total grades
		For Each grade As Integer In gradeValues
			gradeAccumulator = gradeAccumulator + grade
		Next grade
		'  displays grades and calculates  average grade
		For Each grade As String In gradeValues
			gradeLabel.Text = gradeLabel.Text & grade & ControlChars.NewLine
		Next grade
		averageGrade = gradeAccumulator / gradeValues.Length
		avggradeLabel.Text = Convert.ToString(averageGrade)



	End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Input boxes

Posted 27 November 2007 - 04:05 PM

You need to put the InputBox on the same line as the assignment to the array.
gradeValues(subscript) = InputBox("Grade Value:", "Grade Values")


You also need to declare the gradeValues as an array, currently it is just a string variable. You are also going to need to specify how large the array is going to be before you can use it.
Private gradeValues(20) As String

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1