Results 1 to 11 of 11

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017

    Visual Basic help with program

    I earlier posted about a question for the project, and here I am confused again. I am still just learning Visual Basic, and our teacher barely explained loops and how to use them. This is the program:

    Create a Class Marks program that prompts the user for the number of students in the class. When the user clicks OK, the program should randomly generate a 9-digit student number that begins with "071" and marks between 30 and 100, and output the students number, marks and class average in a listbox control.

    My code so far:

    Dim total As Integer = Val(TextBox1.Text)
            Dim randomNumber As New Random
            Dim firstthree As String = "071"
            Dim first As Integer = randomNumber.Next(0, 9)
            Dim second As Integer = randomNumber.Next(0, 9)
            Dim third As Integer = randomNumber.Next(0, 9)
            Dim fourth As Integer = randomNumber.Next(0, 9)
            Dim fifth As Integer = randomNumber.Next(0, 9)
            Dim sixth As Integer = randomNumber.Next(0, 9)
            Dim grade As Integer = randomNumber.Next(30, 100)
            Dim studentNumber As String = firstthree & "-" & first & second & third & "-" & fourth & fifth & sixth
            Dim counter As Integer = 0
            If total = 5 Then
                Do While counter < 5
                    Marks.Items.Add(studentNumber & vbTab & grade)
                    counter += 1
            End If
    I'm still working on my code, I'm still learning so my code may not be the greatest. An issue I currently have is when I add the "studentNumber" and "grade" to the listbox they're all the same generated number when it should be all different. I don't know how to add up the grades in the listbox to find the average, so I have no idea on that part. ]If someone could help with that issue and also help with developing the code and program it would be a blessing.


    [![enter image description here][2]][2]

    [1]: https://i.stack.imgur.com/pgZlH.png
    [2]: https://i.stack.imgur.com/bsmUh.png
    Last edited by Shaggy Hiker; Nov 9th, 2017 at 04:06 PM. Reason: Added CODE tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.