By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Infinity error!

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim TotalSessions As Integer
  3.     Dim StudentName As String
  4.     Dim MissedSessions As Integer, bln As Boolean
  5.     Dim LateSessions As Integer
  6.     Dim TotalMissed As Single
  7.     Dim TotalLate As Single
  8.     Dim Response As String
  9.     Dim DayName As String
  10.     Dim ValidateLate As Single
  11.  
  12.  
  13. Sub Studentname()
  14.         Do
  15.             StudentName = InputBox("Please Enter Student Name!")
  16.             Response = InputBox("Is the student name " & StudentName & " correct? (Y/N)")
  17.         Loop Until ((Response = "Y") Or (Response = "y"))    
  18. End Sub
  19.  
  20. Sub Missedsessions()
  21.         MissedSessions = InputBox("Please enter the number of sessions that " & StudentName & " missed!")
  22.         If (MissedSessions >= 1) And (MissedSessions <= 32) Then
  23.             MessageBox.Show("Missed Sessions = " & MissedSessions)
  24.  
  25.         Else
  26.             Do
  27.                 MissedSessions = InputBox("Incorrect!! Value must be between 1 and 32" & vbCrLf & "Please enter the number of sessions that " & StudentName & " missed!")
  28.             Loop Until ((MissedSessions >= 1) And (MissedSessions <= 32))
  29.  
  30.         End If    
  31. End Sub
  32.  
  33. Sub Latesessions()
  34. ValidateLate = (32 - MissedSessions)
  35.         LateSessions = InputBox("Please enter the number of sessions that " & StudentName & " arived late!")
  36.         If (LateSessions >= 1) And (LateSessions <= 32) And (LateSessions < ValidateLate) Then
  37.             MessageBox.Show("Sessions Late = " & LateSessions)
  38.  
  39.         Else
  40.             Do
  41.                 LateSessions = InputBox("Incorrect!! Value must be between 1 and " & ValidateLate & vbCrLf & "Please enter the number of sessions that " & StudentName & " missed!")
  42.             Loop Until ((LateSessions >= 1) And (LateSessions <= 32) And (LateSessions < ValidateLate))
  43.  
  44.         End If    
  45. End Sub
  46.  
  47. Sub Prepare()
  48. TotalMissed = (MissedSessions / TotalSessions) * 100
  49.         TotalLate = (LateSessions / TotalSessions) * 100    
  50. End Sub
  51.  
  52. Sub Display()
  53. txtDisplay.AppendText(StudentName & " missed " & TotalMissed & "% of possible sessions!" & vbCrLf & StudentName & " attended " & TotalLate & "% of sessions late!" & vbCrLf)    
  54. End Sub
  55.  
  56.     Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
  57.         Call Studentname()
  58.         Call Missedsessions()
  59.         Call Latesessions()
  60.         Call Prepare()
  61.         Call Display()
  62.     End Sub
  63.  
  64. End Class
  65.  
  66.  
May 10 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
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. :)
May 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.