Code for calculating golf scores

ChadW

Registered User.
Local time
Today, 01:53
Joined
Jun 26, 2008
Messages
13
I am trying to write a function which calculates the stableford score for a golfers round. Unfortunately, I am quite new to access and my coding experience is with Progress Open Edge.

I have attached the code I have attempted to write below, any help would be greatly appreciated.

Code:
Private Function calcStblFrd()
Dim iScore As Integer
Dim iPoints As Integer
Dim iPar As Integer
Dim iStrokes As Integer
Dim iAllow As Integer
Dim iHcap As Integer
Dim iStrInd As Integer
Dim iHcapDif As Integer

iHcap = 28
iStrInd = 7
iPar = 5
iStrokes = 5


If iHcap <= 18 Then
  If iStrInd <= iHcap Then
    iAllow = 1
  Else
    iAllow = 0
  End If
ElseIf iHcap > 18 Then
  iHcapDif = iHcap - 18
  If iHcapDif <= 10 Then
    If iStrInd <= iHcapDif Then
      iAllow = 2
    Else
      iAllow = 1
    End If
  End If
End If

iScore = (iStrokes - iAllow) - iPar

Select Case iScore
Case -5
  iScore = 7
Case -4
  iScore = 6
Case -3
  iScore = 5
Case -2
  iScore = 4
Case -1
  iScore = 3
Case 0
  iScore = 2
Case 1
  iScore = 1
Case Else
  iScore = 0
End Select

End Function
 
I happen to be a golfer, so I know generally how stableford scoring works, but it would be helpful to anyone to have you write out in words the parameters of what you're trying to achieve. It would also help to tell us what the problem is with your code. Does it error, and if so where? Does it not return the expected result? Offhand I would say it doesn't do anything with the result, but how to fix that depends on how you intend to use it.
 
Hi thanks for your reply.

I plan to call this function for each score(on-leave) entered in the GUI scorecard for each player.

I need to pass four parameters into the function Handicap(iHcap), Par(iPar), Stroke index(iStrInd) and the gross score(iScore).

My trouble is that I'm a bit unsure of how to do this. in Progress i would just call the function in the calling procedure(the GUI Scorecard) eg.

calcStblFrd(iHcap,iPar,iStrInd,iScore)

and then define the variables in the same order in the function.
 
Sorry.... and the use for the function is to return the stableford score for each hole.
 
you pass parameters the same in vba, but you need to declare the types in the function, and type the function

and if the function is in a module, it needs to be public, not private

so

Public Function calcStblFrd(handicap as long, par as long, strokeindex as long, actualscore as long) as long
etc
end function

so the function returns a long value

change the parameters to suit - not looked at your code, but you obviously know what you are doing
if any are real numbers, make them double instead of long
note vba will fall over if you pass a null (blank parameter)

------
one other thing - not sure about progress, but vba passes parameters as default byref (ie the address is passed, not a local copy), so if you change them in the proc, they will be changed

you can pass them as byval, but you have to explicitily request that in the code
 
Last edited:
If you're still stuck on this, I was more after the logic of what you want the function to do. IOW, basic stableford scoring (over here at least) is so many points for par, so many for birdie, minus so many for bogey, etc. You appear to be adjusting for handicap, so it was the basic parameters of all that I was looking for. If you feel it already does that calculation properly, then perhaps the only missing piece is that you need to set the value of the function at the end so it can be returned:

calcStblFrd = iScore
 
Not sure if you are still looking at this or not, but I think you are looking at something like this:-

Private Sub Gross_AfterUpdate()
If Handicap <= (18) Then
If (Handicap - [Stroke Index]) >= 0 Then
Net = (Gross - 1)
Else
Net = Gross
End If
End If

If Handicap > (18) Then
If ((Handicap - 18) - [Stroke Index]) >= 0 Then
Net = (Gross - 2)
Else
Net = (Gross - 1)
End If
End If

If Net >= (Par + 2) Then
Points = 0
End If
If Net = (Par + 1) Then
Points = 1
End If
If Net = (Par) Then
Points = 2
End If
If Net = (Par - 1) Then
Points = 3
End If
If Net = (Par - 2) Then
Points = 4
End If
If Net = (Par - 3) Then
Points = 5
End If
If Net = (Par - 4) Then
Points = 6
End If


End Sub


Would be interested to see the databse, am also looking into creating a golf database for 12 of us that play 3 rounds a year together - a way of getting away and keeping in touch.
 

Users who are viewing this thread

Back
Top Bottom