Results 1 to 6 of 6

Thread: [VB6] Small Job to repair code

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2016
    Posts
    49

    [VB6] Small Job to repair code

    More work to follow once this is fixed. At first I was getting division by zero when calculating F1fps and F2fps. I somehow stopped that error but now the conditions are not being met for the F2fps. When d < 8 is getting the wrong results. The code for F1fps is working with no errors yet

    Code:
    Private Function F1fps_Calc(ByRef r As clsRecord, ByVal detailRecordNum As Integer) As Variant
    
        '// get the paceline distance in furlongs
        Dim dist As String
        dist = gFieldMapping.GetFieldValue(r, "dist " & detailRecordNum)
        Dim dist_val As Double
        If IsNumeric(dist) Then
            dist_val = CDbl(dist) / 220
        End If
        If dist_val < 0 Then
            dist_val = Abs(dist_val)
        End If
        
        Select Case dist_val
      Case Is >= 9
        If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
        F1fps_Calc = ""
        Else
          F1fps_Calc = FormatNumber(((2640 - (gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum) * 9)) / gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
        End If
        
      Case Is < 9
        If gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) = 0 Then
        F1fps_Calc = ""
        Else
          F1fps_Calc = FormatNumber(((2640 - (gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum) * 9)) / gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum)), 2)
        
        End If
     Case Is < 8
        If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
        F1fps_Calc = ""
        Else
          F1fps_Calc = FormatNumber(((1320 - (gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum) * 9)) / gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
        End If
        End Select
                   
    End Function
          
    Private Function F2fps_Calc(ByRef r As clsRecord, ByVal detailRecordNum As Integer) As Variant
        
        '// get the paceline distance in furlongs
        Dim dist As String
        dist = gFieldMapping.GetFieldValue(r, "dist " & detailRecordNum)
        Dim dist_val As Double
        If IsNumeric(dist) Then
            dist_val = CDbl(dist) / 220
        End If
        If dist_val < 0 Then
            dist_val = Abs(dist_val)
        End If
        
        Select Case dist_val
      Case Is >= 9
        If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
        F2fps_Calc = ""
        Else
          F2fps_Calc = FormatNumber((1320 - (gFieldMapping.GetFieldValue(r, "bl2c " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum)) * 9) / (gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
            End If
      Case Is < 9
        If gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) = 0 Then
        F2fps_Calc = ""
        Else
          F2fps_Calc = FormatNumber((1320 - (gFieldMapping.GetFieldValue(r, "bl2c " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum)) * 9) / (gFieldMapping.GetFieldValue(r, "frac #3 " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum)), 2)
       End If
       Case Is < 8
        If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
        F2fps_Calc = ""
        Else
          F2fps_Calc = FormatNumber((1320 - (gFieldMapping.GetFieldValue(r, "bl2c " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum)) * 9) / (gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
       End If
       
       End Select
    End Function

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,987

    Re: [VB6] Small Job to repair code

    Heads up, I modified your title to include the programming language. If you're using an earlier version, just edit your post and update the title.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,494

    Re: [VB6] Small Job to repair code

    The Cases are tested in order from top to bottom, so your Case Is < 8 code will never execute (8 is less than 9, so the Case Is < 9 block will match values < 8 without ever getting to the < 8 test).

    Does this give you the values you expect?

    Code:
    Option Explicit
    
    Private Function F1fps_Calc(ByRef r As clsRecord, ByVal detailRecordNum As Integer) As Variant
    
    '// get the paceline distance in furlongs
       Dim dist As String
       dist = gFieldMapping.GetFieldValue(r, "dist " & detailRecordNum)
       Dim dist_val As Double
       If IsNumeric(dist) Then
          dist_val = CDbl(dist) / 220
       End If
       If dist_val < 0 Then
          dist_val = Abs(dist_val)
       End If
    
       Select Case dist_val
       Case Is < 8
          If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
             F1fps_Calc = ""
          Else
             F1fps_Calc = FormatNumber(((1320 - (gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum) * 9)) / gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
          End If
       Case Is >= 9#
          If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
             F1fps_Calc = ""
          Else
             F1fps_Calc = FormatNumber(((2640 - (gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum) * 9)) / gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
          End If
    
       Case Else
          If gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) = 0 Then
             F1fps_Calc = ""
          Else
             F1fps_Calc = FormatNumber(((2640 - (gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum) * 9)) / gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum)), 2)
    
          End If
       End Select
    
    End Function
    
    Private Function F2fps_Calc(ByRef r As clsRecord, ByVal detailRecordNum As Integer) As Variant
       '// get the paceline distance in furlongs
       Dim dist As String
       dist = gFieldMapping.GetFieldValue(r, "dist " & detailRecordNum)
       Dim dist_val As Double
       If IsNumeric(dist) Then
          dist_val = CDbl(dist) / 220
       End If
       If dist_val < 0 Then
          dist_val = Abs(dist_val)
       End If
    
       Select Case dist_val
       Case Is < 8#
          If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
             F2fps_Calc = ""
          Else
             F2fps_Calc = FormatNumber((1320 - (gFieldMapping.GetFieldValue(r, "bl2c " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum)) * 9) / (gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
          End If
    
       Case Is >= 9#
          If gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum) = 0 Then
             F2fps_Calc = ""
          Else
             F2fps_Calc = FormatNumber((1320 - (gFieldMapping.GetFieldValue(r, "bl2c " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum)) * 9) / (gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "frac #1 " & detailRecordNum)), 2)
          End If
       
       Case Else
          If gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum) = 0 Then
             F2fps_Calc = ""
          Else
             F2fps_Calc = FormatNumber((1320 - (gFieldMapping.GetFieldValue(r, "bl2c " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "bl1c " & detailRecordNum)) * 9) / (gFieldMapping.GetFieldValue(r, "frac #3 " & detailRecordNum) - gFieldMapping.GetFieldValue(r, "frac #2 " & detailRecordNum)), 2)
          End If
       End Select
    End Function

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2016
    Posts
    49

    Re: [VB6] Small Job to repair code

    It appears to be working. I have to check the math for dist =8 or 8.5. It looks like the Case Else is handling that. I was willing to pay for that

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2016
    Posts
    49

    Re: [VB6] Small Job to repair code

    everything is working beautiful. I have had similar errors for months and because I don't really understand the debugging tool. I was not looking for a freebie

  6. #6
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,494

    Re: [VB6] Small Job to repair code

    Quote Originally Posted by jpatierno View Post
    everything is working beautiful. I have had similar errors for months and because I don't really understand the debugging tool. I was not looking for a freebie
    I'm glad I could help. I know you weren't looking for a freebie, it was some "low hanging fruit" which is nice distraction from my day-to-day stuff these days.

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