5 Replies - 366 Views - Last Post: 19 October 2013 - 07:15 PM Rate Topic: -----

#1 lasmith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-October 13

Arrays & Rich Text Box question

Posted 19 October 2013 - 12:30 PM

Hi, I am taking my first visual basic class and have a question. I have created a handful of arrays to house Student Names and grades. I have one form to type in the names and grades and then a second form that will load those names and grades into a form and then find the average as well as a letter grade.

My Question:

Why isn't the text that I type in on the student data form showing through on my gradebook form? I can get a value to show if I type StudentName(0) = "lasmith" but when I direct it to the rtb is doesn't work. I'm sure it's something I've missed in the book. The only examples I can find are for listing the values in order from an input box or file. I know my code is a bit of a mess I keep trying different things and just want to make sure I'm on the right track.

I really want to learn this stuff so any input would be appreciated.

Thanks,

lasmith

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Arrays & Rich Text Box question

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2876
  • View blog
  • Posts: 9,544
  • Joined: 12-December 12

Re: Arrays & Rich Text Box question

Posted 19 October 2013 - 12:55 PM

You should post relevant code here, wrapped in code tags, rather than just a zip-file which people will be reluctant to download (and which will probably disappear at some point).

In the meantime you could search the tutorials here @DIC. I believe there are a few on passing information between forms. Click the Tutorials link at the top of this page.
Was This Post Helpful? 1
  • +
  • -

#3 lasmith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-October 13

Re: Arrays & Rich Text Box question

Posted 19 October 2013 - 12:59 PM

Public Class frmGradebook

    Private Sub StudentDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StudentDataToolStripMenuItem.Click
        frmStudentData.Show()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        End
    End Sub

    Public Sub LoadScoresToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadScoresToolStripMenuItem.Click

        'Declarations

        Dim strStudentNameArray(4) As String
        Dim shoLetterGrade(4) As Short
        Dim mScores1(4) As Single
        Dim mScores2(4) As Single
        Dim mScores3(4) As Single
        Dim mScores4(4) As Single

        'Inputs/Processing
        'Student Name
        strStudentNameArray(0) = rtbName1.Text
        strStudentNameArray(1) = rtbName2.Text
        strStudentNameArray(2) = rtbName3.Text
        strStudentNameArray(3) = rtbName4.Text
        strStudentNameArray(4) = rtbName5.Text

        rtbGrade1.Text = shoLetterGrade(0)

    'Calculate Average
    'Input
    'Student Names
        rtbAve1.Text = (mScores1(0) + mScores2(0) + mScores3(0) + mScores4(0)) / 4
        rtbAve2.Text = (mScores1(1) + mScores2(1) + mScores3(1) + mScores4(1)) / 4
        rtbAve3.Text = (mScores1(2) + mScores2(2) + mScores3(2) + mScores4(2)) / 4
        rtbAve4.Text = (mScores1(3) + mScores2(3) + mScores3(3) + mScores4(3)) / 4
        rtbAve5.Text = (mScores1(4) + mScores2(4) + mScores3(4) + mScores4(4)) / 4
    End Sub
    'Letter Grades
    ' Determines letter grade

    Public Function GetLetterGrade(ByVal Average As String) As String
        Select Case Average
            Case Is >= 90 : Return "A"
            Case Is >= 80 : Return "B"
            Case Is >= 70 : Return "C"
            Case Is >= 60 : Return "D"
            Case Else : Return "F"
        End Select

    End Function


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        End
    End Sub
End Class

Public Class frmStudentData

    Public Sub TestScores(ByVal bytTest As Byte, ByVal TestScores As Array)
        'Declarations
        Dim mstrStudentNameArray(4) As String
        Dim mshoLetterGrade() As Short = {"A", "B", "C", "D", "F"}
        Dim mbytScores1(4) As Short
        Dim mbytScores2(4) As Byte
        Dim mbytScores3(4) As Byte
        Dim mbytScores4(4) As Byte

        'Test 1
        mbytScores1(0) = rtbNm1Ts1.Text
        mbytScores1(1) = rtbNm2Ts1.Text
        mbytScores1(2) = rtbNm3Ts1.Text
        mbytScores1(3) = rtbNm4Ts1.Text
        mbytScores1(4) = rtbNm5Ts1.Text

        'Test 2
        mbytScores2(0) = rtbNm1Ts2.Text
        mbytScores2(1) = rtbNm2Ts2.Text
        mbytScores2(2) = rtbNm3Ts2.Text
        mbytScores2(3) = rtbNm4Ts2.Text
        mbytScores2(4) = rtbNm5Ts2.Text

        'Test 3
        mbytScores3(0) = rtbNm1Ts3.Text
        mbytScores3(1) = rtbNm2Ts3.Text
        mbytScores3(2) = rtbNm3Ts3.Text
        mbytScores3(3) = rtbNm4Ts3.Text
        mbytScores3(4) = rtbNm5Ts3.Text

        'Test 4
        mbytScores4(0) = rtbNm1Ts4.Text
        mbytScores4(1) = rtbNm2Ts4.Text
        mbytScores4(2) = rtbNm3Ts4.Text
        mbytScores4(3) = rtbNm4Ts4.Text
        mbytScores4(4) = rtbNm5Ts4.Text

    End Sub
   Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        frmGradebook.Show()
        Me.Hide()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        frmGradebook.Show()
        Me.Hide()
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2876
  • View blog
  • Posts: 9,544
  • Joined: 12-December 12

Re: Arrays & Rich Text Box question

Posted 19 October 2013 - 01:07 PM

After a quick look I can't see anywhere where you are attempting to read, or pass, information between the two forms?

This tutorial is very good, although in C#.
Was This Post Helpful? 0
  • +
  • -

#5 lasmith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-October 13

Re: Arrays & Rich Text Box question

Posted 19 October 2013 - 06:52 PM

Okay so I have done some more work and am hoping that you may be able to help me figure out why the zeroes for the Average. I realize now what you meant by not passing anything through. Hopefully this is a little better?

Public Class frmGradebook
    'Declarations
    Public gstrStudentNameArray(4) As String
    Public gstrLetterGrade() As String = {"A", "B", "C", "D", "F"}
    Public gScores1(4) As Integer
    Public gScores2(4) As Integer
    Public gScores3(4) As Integer
    Public gScores4(4) As Integer
    Public gscores5(4) As Integer
    Public gTotal(4) As Integer
    Private Sub StudentDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StudentDataToolStripMenuItem.Click
        frmStudentData.Show()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        End
    End Sub

    Public Sub LoadScoresToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadScoresToolStripMenuItem.Click

        'Inputs/Processing
        'Student Name
        gstrStudentNameArray(0) = txtName1.Text
        gstrStudentNameArray(1) = txtName2.Text
        gstrStudentNameArray(2) = txtName3.Text
        gstrStudentNameArray(3) = txtName4.Text
        gstrStudentNameArray(4) = txtName5.Text

        txtName1.Text = frmStudentData.rtbName1.Text
        txtName2.Text = frmStudentData.rtbName2.Text
        txtName3.Text = frmStudentData.rtbName3.Text
        txtName4.Text = frmStudentData.rtbName4.Text
        txtName5.Text = frmStudentData.rtbName5.Text
      
        'Get Average
        txtAverage1.Text = gTotal(0)
        txtAverage2.Text = gTotal(1)
        txtAverage3.Text = gTotal(2)
        txtAverage4.Text = gTotal(3)
        txtAverage5.Text = gTotal(4)

        'Get Letter Grade for Student 1
        If txtAverage1.Text >= 90 Then
            txtGrade1.Text = "A"
            If txtAverage1.Text >= 80 Then
                txtGrade1.Text = "B"
                If txtAverage1.Text >= 70 Then
                    txtGrade1.Text = "C"
                    If txtAverage1.Text >= 60 Then
                        txtGrade1.Text = "D"
                        If txtAverage1.Text < 60 Then
                            txtGrade1.Text = "F"
                        End If
                    End If
                End If
            End If
        End If

        'Get Letter Grade for Student 2
        If txtAverage2.Text >= 90 Then
            txtGrade2.Text = "A"
            If txtAverage2.Text >= 80 Then
                txtGrade2.Text = "B"
                If txtAverage2.Text >= 70 Then
                    txtGrade2.Text = "C"
                    If txtAverage2.Text >= 60 Then
                        txtGrade2.Text = "D"
                        If txtAverage2.Text < 60 Then
                            txtGrade2.Text = "F"
                        End If
                    End If
                End If
            End If
        End If

        'Get Letter Grade for Student 3
        If txtAverage3.Text >= 90 Then
            txtGrade3.Text = "A"
            If txtAverage3.Text >= 80 Then
                txtGrade3.Text = "B"
                If txtAverage3.Text >= 70 Then
                    txtGrade3.Text = "C"
                    If txtAverage3.Text >= 60 Then
                        txtGrade3.Text = "D"
                        If txtAverage3.Text < 60 Then
                            txtGrade3.Text = "F"
                        End If
                    End If
                End If
            End If
        End If
        'Get Letter Grade for Student 4
        If txtAverage4.Text >= 90 Then
            txtGrade4.Text = "A"
            If txtAverage4.Text >= 80 Then
                txtGrade4.Text = "B"
                If txtAverage4.Text >= 70 Then
                    txtGrade4.Text = "C"
                    If txtAverage4.Text >= 60 Then
                        txtGrade4.Text = "D"
                        If txtAverage4.Text < 60 Then
                            txtGrade4.Text = "F"
                        End If
                    End If
                End If
            End If
        End If
        'Get Letter Grade for Student 5
        If txtAverage5.Text >= 90 Then
            txtGrade5.Text = "A"
            If txtAverage5.Text >= 80 Then
                txtGrade5.Text = "B"
                If txtAverage5.Text >= 70 Then
                    txtGrade5.Text = "C"
                    If txtAverage5.Text >= 60 Then
                        txtGrade5.Text = "D"
                        If txtAverage5.Text < 60 Then
                            txtGrade5.Text = "F"
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        End
    End Sub
End Class
Public Class frmStudentData
    'Declarations
    Public gstrStudentNameArray(4) As String
    Public gshoLetterGrade() As String = {"A", "B", "C", "D", "F"}
    Public gScores1(4) As Integer
    Public gScores2(4) As Integer
    Public gScores3(4) As Integer
    Public gScores4(4) As Integer
    Public gscores5(4) As Integer
    Public gTotal(4) As Integer


    Public Sub TestScores(ByVal bytTest As Byte, ByVal TestScores As Array)
        'Declarations

        Dim gTotal(4) As Integer
        Dim StudentGrades(4)

        'Student 1 Scores

        gScores1(0) = CInt(rtbNm1Ts1.Text)
        gScores2(0) += CInt(rtbNm1Ts2.Text)
        gScores3(0) += CInt(rtbNm1Ts3.Text)
        gScores4(0) += CInt(rtbNm1Ts4.Text)
        'Student 2 Scores
        gScores1(1) = CInt(rtbNm2Ts1.Text)
        gScores2(1) += CInt(rtbNm2Ts2.Text)
        gScores3(1) += CInt(rtbNm2Ts3.Text)
        gScores4(1) += CInt(rtbNm2Ts4.Text)
        'Student 3 Scores
        gScores1(2) = CInt(rtbNm3Ts1.Text)
        gScores2(2) += CInt(rtbNm3Ts2.Text)
        gScores3(2) += CInt(rtbNm3Ts3.Text)
        gScores4(2) += CInt(rtbNm3Ts4.Text)
        'Student 4 Scores
        gScores1(3) = CInt(rtbNm4Ts1.Text)
        gScores2(3) += CInt(rtbNm4Ts2.Text)
        gScores3(3) += CInt(rtbNm4Ts3.Text)
        gScores4(3) += CInt(rtbNm4Ts4.Text)
        'Student 5 Scores
        gScores1(4) = CInt(rtbNm5Ts1.Text)
        gScores2(4) += CInt(rtbNm5Ts2.Text)
        gScores3(4) += CInt(rtbNm5Ts3.Text)
        gScores4(4) += CInt(rtbNm5Ts4.Text)

        gTotal(0) = ((gScores1(0) + gScores2(0) + gScores3(0) + gScores4(0)) / 4)
        gTotal(1) = ((gScores1(1) + gScores2(1) + gScores3(1) + gScores4(1)) / 4)
        gTotal(2) = ((gScores1(2) + gScores2(2) + gScores3(2) + gScores4(2)) / 4)
        gTotal(3) = ((gScores1(3) + gScores2(3) + gScores3(3) + gScores4(3)) / 4)
        gTotal(4) = ((gScores1(4) + gScores2(4) + gScores3(4) + gScores4(4)) / 4)

    End Sub
   Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        frmGradebook.Show()
        Me.Hide()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        frmGradebook.Show()
        Me.Hide()
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2876
  • View blog
  • Posts: 9,544
  • Joined: 12-December 12

Re: Arrays & Rich Text Box question

Posted 19 October 2013 - 07:15 PM

txtName1.Text = frmStudentData.rtbName1.Text

This is attempting to read from the static (default) Form instance frmStudentData, not the currently running instance.

I provided a tutorial-link above, otherwise you could search "vb.net pass data between forms" or similar.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1