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

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




Visual Bassic array help

 
Reply to this topicStart new topic

Visual Bassic array help, Problem involving arrays and input boxes

woodduck
26 Nov, 2007 - 07:39 AM
Post #1

New D.I.C Head
*

Joined: 26 Nov, 2007
Posts: 6


My Contributions
I am having trouble with the following code for the following problem please help???: The code I have come up with will not work

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:
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)=
            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



Attached File(s)
Attached File  arrays_Rodney.zip ( 23.68k ) Number of downloads: 44
User is offlineProfile CardPM
+Quote Post

girasquid
RE: Visual Bassic Array Help
26 Nov, 2007 - 09:06 AM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,294



Thanked: 18 times
Dream Kudos: 725
My Contributions
What exactly is the problem you're having? Can you post some of the error messages you're receiving?
User is offlineProfile CardPM
+Quote Post

woodduck
RE: Visual Bassic Array Help
26 Nov, 2007 - 09:40 AM
Post #3

New D.I.C Head
*

Joined: 26 Nov, 2007
Posts: 6


My Contributions
QUOTE(girasquid @ 26 Nov, 2007 - 10:06 AM) *

What exactly is the problem you're having? Can you post some of the error messages you're receiving?

The error I am getting invoves the input box. It says expression expected on th = sign before the input box code. I have colored it in red on the code. My instructor says I need to ask user how many grades but not sure how to do this.
Thanks
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

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

Be Social

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

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month