Welcome to Dream.In.Code
Become a VB Expert!

Join 149,552 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,599 people online right now. Registration is fast and FREE... Join Now!




Input boxes

 
Reply to this topicStart new topic

Input boxes, Input boxes in arrays

woodduck
27 Nov, 2007 - 08:15 AM
Post #1

New D.I.C Head
*

Joined: 26 Nov, 2007
Posts: 6


My Contributions
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??
User is offlineProfile CardPM
+Quote Post

Louisda16th
RE: Input Boxes
27 Nov, 2007 - 08:59 AM
Post #2

 101010101
Group Icon

Joined: 3 Aug, 2006
Posts: 1,812



Thanked: 1 times
Dream Kudos: 755
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

woodduck
RE: Input Boxes
27 Nov, 2007 - 03:01 PM
Post #3

New D.I.C Head
*

Joined: 26 Nov, 2007
Posts: 6


My Contributions
QUOTE(Louisda16th @ 27 Nov, 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.

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.


CODE

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

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Input Boxes
27 Nov, 2007 - 03:05 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
You need to put the InputBox on the same line as the assignment to the array.
CODE

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.
CODE

Private gradeValues(20) As String

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 09:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month