Results 1 to 4 of 4

Thread: Need Help Immediately, If there is anyone that can Help, Pleeeease Help me!

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    8

    Unhappy

    Can anyone tell me what I am doing wrong? And Tell me what I should have as the right code

    Read the following instructions, my code is below it.


    The third button will bring the user to a form that allows entry of Student marks into a file. Upon indicating that the user has completed entering marks for one student have the program calculate the average mark, display that mark in a message box and then clear the screen to allow for a new student.
    The must also be a button to allow return to main menu.
    My code is:

    Private Sub cmdAddToFile_Click()

    Dim strName As String
    Dim intMarks As Integer
    strName = txtStudentName.Text
    intMarks = Val(txtMark.Text)


    'Open file to add student marks to it (append)

    If IsNumeric(txtStudentName.Text) Then
    MsgBox "Please Enter Text, not a number", vbOKOnly, "Error"
    Else
    If txtStudentName.Text <> "" Then
    If IsNumeric(txtMark.Text) And Val(txtMark.Text) >= 0 And Val(txtMark.Text) <= 100 Then
    Open "C:\My Documents\StudentMarks.txt" For Append As #1
    Write #1, strName, intMarks
    Close #1
    Else
    MsgBox "Please enter a number from 1 to 100"
    End If
    txtMark.Text = ""
    txtMark.SetFocus
    Else
    MsgBox "Please Enter Student Name", vbOKOnly, "Error"
    txtStudentName.SetFocus
    End If
    End If


    End Sub

    Private Sub cmdAverage_Click()
    'Displays student average mark in a Message box and student name in a label
    'Totals Student marks
    'Give an average in a message box
    Dim msngTotal As Long
    Dim mintCount As Integer

    Open "C:\My Documents\StudentMarks.txt" For Input As #1

    Do Until strName = txtStudentName.Text
    Input #1, strName, intMarks
    lblTitle.Caption = strName
    Loop
    If strName = txtStudentName.Text Then
    msngTotal = msngTotal + intMarks
    mintCount = mintCount + 1
    MsgBox ("Your Mark is:" & " " & msngTotal / mintCount)

    End If




    Close #1


    txtMark.Text = ""
    txtMark.SetFocus
    End Sub

    Private Sub cmdDone_Click()
    Dim msngTotal As Long
    Dim mintCount As Integer

    Dim strYesNo As String
    strYesNo = MsgBox("Are you done entering Student Marks?", vbYesNo + vbQuestion, "Confirm Done Entering Marks?")
    If strYesNo = vbYes Then

    Open "C:\My Documents\StudentMarks.txt" For Input As #1
    Do Until EOF(1)
    Input #1, strName, intMarks
    lblTitle.Caption = strName
    Loop
    Close #1
    Call cmdAverage_Click
    End If



    End Sub
    -.)

  2. #2
    AIS_DK
    Guest
    Before looking through the code I would like to know what kind of error i'm looking for.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    8

    Unhappy Can anyone tell me what I am doing wrong?

    Can anyone tell me what I am doing wrong? And Tell me what I should have as the right code. When I try my code, I am not getting the average make for one student it is averaging all the marks in the file. Please help me. I think my main mistake is in the Private Sub cmdAverage_Click() command.


    Read the following instructions, my code is below it.


    Create a form that allows entry of Student marks into a file. Upon indicating that the user has completed entering marks for one student have the program calculate the average mark, display that mark in a message box and then clear the screen to allow for a new student. It should also display the students name, need to validate numbers, and text entered, and only enter numbers greater than 0 and less than 100.


    My code is:

    Private Sub cmdAddToFile_Click()

    Dim strName As String
    Dim intMarks As Integer
    strName = txtStudentName.Text
    intMarks = Val(txtMark.Text)


    'Open file to add student marks to it (append)

    If IsNumeric(txtStudentName.Text) Then
    MsgBox "Please Enter Text, not a number", vbOKOnly, "Error"
    Else
    If txtStudentName.Text <> "" Then
    If IsNumeric(txtMark.Text) And Val(txtMark.Text) >= 0 And Val(txtMark.Text) <= 100 Then
    Open "C:\My Documents\StudentMarks.txt" For Append As #1
    Write #1, strName, intMarks
    Close #1
    Else
    MsgBox "Please enter a number from 1 to 100"
    End If
    txtMark.Text = ""
    txtMark.SetFocus
    Else
    MsgBox "Please Enter Student Name", vbOKOnly, "Error"
    txtStudentName.SetFocus
    End If
    End If

    End Sub



    Private Sub cmdAverage_Click()
    'Displays student average mark in a Message box and student name in a label
    'Totals Student marks
    'Give an average in a message box
    Dim msngTotal As Long
    Dim mintCount As Integer

    Open "C:\My Documents\StudentMarks.txt" For Input As #1

    Do Until strName = txtStudentName.Text
    Input #1, strName, intMarks
    lblTitle.Caption = strName
    Loop
    If strName = txtStudentName.Text Then
    msngTotal = msngTotal + intMarks
    mintCount = mintCount + 1
    MsgBox ("Your Mark is:" & " " & msngTotal / mintCount)

    End If
    Close #1


    txtMark.Text = ""
    txtMark.SetFocus
    End Sub



    Private Sub cmdDone_Click()
    Dim msngTotal As Long
    Dim mintCount As Integer

    Dim strYesNo As String
    strYesNo = MsgBox("Are you done entering Student Marks?", vbYesNo + vbQuestion, "Confirm Done Entering Marks?")
    If strYesNo = vbYes Then

    Open "C:\My Documents\StudentMarks.txt" For Input As #1
    Do Until EOF(1)
    Input #1, strName, intMarks
    lblTitle.Caption = strName
    Loop
    Close #1
    Call cmdAverage_Click
    End If

    End Sub
    -.)

  4. #4
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    The mistake is in the cmdAverage_Click.

    You need to look more closely at the loop, where it's loading from the file to produce the average. It doesn't quite encompass everything you need.
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

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