Infinity error!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gordontbh
    New Member
    • May 2007
    • 1

    #1

    Infinity error!

    Hey I am new to visual basic, well I started yesterday, I trying to create a project that works out the values for attendance. I was wondering is anyone could help me, my code worked fine until added sub routines into it, now the values at the end that are supposed to be % values, just display infinity%, rather than the actual value., would be a big help if you could have a look.


    Here is my code:

    Code:
    Public Class Form1
        Dim TotalSessions As Integer
        Dim StudentName As String
        Dim MissedSessions As Integer, bln As Boolean
        Dim LateSessions As Integer
        Dim TotalMissed As Single
        Dim TotalLate As Single
        Dim Response As String
        Dim DayName As String
        Dim ValidateLate As Single
    
    
    Sub Studentname()
            Do
                StudentName = InputBox("Please Enter Student Name!")
                Response = InputBox("Is the student name " & StudentName & " correct? (Y/N)")
            Loop Until ((Response = "Y") Or (Response = "y"))    
    End Sub
    
    Sub Missedsessions()
            MissedSessions = InputBox("Please enter the number of sessions that " & StudentName & " missed!")
            If (MissedSessions >= 1) And (MissedSessions <= 32) Then
                MessageBox.Show("Missed Sessions = " & MissedSessions)
    
            Else
                Do
                    MissedSessions = InputBox("Incorrect!! Value must be between 1 and 32" & vbCrLf & "Please enter the number of sessions that " & StudentName & " missed!")
                Loop Until ((MissedSessions >= 1) And (MissedSessions <= 32))
    
            End If    
    End Sub
    
    Sub Latesessions()
    ValidateLate = (32 - MissedSessions)
            LateSessions = InputBox("Please enter the number of sessions that " & StudentName & " arived late!")
            If (LateSessions >= 1) And (LateSessions <= 32) And (LateSessions < ValidateLate) Then
                MessageBox.Show("Sessions Late = " & LateSessions)
    
            Else
                Do
                    LateSessions = InputBox("Incorrect!! Value must be between 1 and " & ValidateLate & vbCrLf & "Please enter the number of sessions that " & StudentName & " missed!")
                Loop Until ((LateSessions >= 1) And (LateSessions <= 32) And (LateSessions < ValidateLate))
    
            End If    
    End Sub
    
    Sub Prepare()
    TotalMissed = (MissedSessions / TotalSessions) * 100
            TotalLate = (LateSessions / TotalSessions) * 100    
    End Sub
    
    Sub Display()
    txtDisplay.AppendText(StudentName & " missed " & TotalMissed & "% of possible sessions!" & vbCrLf & StudentName & " attended " & TotalLate & "% of sessions late!" & vbCrLf)    
    End Sub
    
        Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
            Call Studentname()
            Call Missedsessions()
            Call Latesessions()
            Call Prepare()
            Call Display()
        End Sub
    
    End Class
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    That's because any number divided by zero is infinity.

    In the Prepare routine, you are dividing by zero then multiplying by 100. So you are actually showing 100 times infinity. :)

    Comment

    Working...