-
Nov 13th, 2023, 03:44 PM
#1
Thread Starter
Member
[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
-
Nov 13th, 2023, 03:47 PM
#2
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.
-
Nov 13th, 2023, 07:56 PM
#3
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
-
Nov 14th, 2023, 12:49 PM
#4
Thread Starter
Member
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
-
Nov 14th, 2023, 04:20 PM
#5
Thread Starter
Member
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
-
Nov 14th, 2023, 11:34 PM
#6
Re: [VB6] Small Job to repair code
Originally Posted by jpatierno
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|