Replace fractional Odds with Decimal

jdncoke99

Registered User.
Local time
Today, 08:56
Joined
Nov 1, 2007
Messages
40
Hi
I want to be able to type a set of fractional odds into a textbox "txtodds" on my form and for it to be changed to decimal odds on the Lost_Focus Event.
E.g. If I enter 1/2, I want 1.5 to be displayed.
Thanks in anticipation.
Kev
 
Hi
I want to be able to type a set of fractional odds into a textbox "txtodds" on my form and for it to be changed to decimal odds on the Lost_Focus Event.
E.g. If I enter 1/2, I want 1.5 to be displayed.
Thanks in anticipation.
Kev

wrong ..1/2 = 0.5 if you want 1.5 then you need 3/2
and why if you want decimals then enter decimals
 
i don't know how to do this in one field but could do it as the result of 2 sepearate field which would be
x divided by y = (z *100)
 
Thanks Gary
I am using betting odds, therefore 2/1 fractional becomes 3.00 decimal,, as the initial stake is factored in. If I can't do it in the text box itself, I shall have to build a table with the conversions.
 
You can use this function to "Evaluate" the initial division problem of 2 divided by 1 = 2. Because I don't gamble, except to drive the freeways of California, I don't know if after doing this division, you just simply add 1 to the answer, as would be the case in 2/1. Could you give a good explaination of the process of calculating the betting odds from fractional to decimal if the adding of 1 is not enough, and I'll see what can be done to fix the formula.
Code:
Function EvalField()
Dim x As Integer, ctl As Control
  Set ctl = Screen.ActiveControl
  x = Val(Mid(ctl.Name, 5))
  Screen.ActiveForm.Controls("Formula" & x) = ctl
  ctl = Eval(ctl)
End Function
Then in the AfterUpdate event of the field to be changed to decimal odds, put this: =EvalField()
 
ok- kinda understand - but would not my formula still work but add on +1
this would give 2/1 2 divied by = 0.5 + 1 = 1.5

3/1 = 1.33333

-- bettings not my thing - IO always end up picking a donkey at the races -lottery about as adventureous as I get..

divid x by y and adding 1 on should solve this

do you get top heavy fractions
5/4

5 divided by 4 =1.25 + 1 = 2.25

does this work ???
10/2 odds on etc = 6.00 (10 divided by 2 = 5 + 1 = 6)

regards
 
Thanks Guys
Had trouble getting onto the site for a couple of hours there. I have already built the table, as I thought it sounded like an unusual question myself. Having done that though, I now, still have no clue as to the coding, or where to put it, ha ha.
tblOdds
FieldName: Fractional (PK); Decimal
As I said, I would like txtOdds to look up the corresponding decimal odds after I have entered the fractional odds. I do not want to store the fractional odds.
Re. adding on the 1.
In't olden days, folk would say "that's 6/4 wi ya stake back" now they just say "that's 2.5". Best way of putting it lol.
 
Code:
Function EvalField()
Dim x As Integer, ctl As Control
  Set ctl = Screen.ActiveControl
  x = Val(Mid(ctl.Name, 5))
  Screen.ActiveForm.Controls("Formula" & x) = ctl
  ctl = Eval(ctl)
End Function
On that last line.
ctl = Eval(ctl) + 1
 
"Runtime error '438' Object doesn't support this property or method" is the popup, after I have entered "5/4" and pressed the tab key. Have I screwed the code up?
Function EvalField()
Dim x As Integer, ctl As Control
Set ctl = Screen.ActiveControl
x = Val(Mid(ctl.txtCoralHome, 5))
x = Val(Mid(ctl.txtCoralDraw, 5))
x = Val(Mid(ctl.txtCoralAway, 5))
Screen.ActiveForm.Controls("Formula" & x) = ctl
ctl = Eval(ctl) + 1
End Function

Then

Private Sub txtCoralHome_AfterUpdate()
Me.txtCoralHome = EvalField()
End Sub
etc. x3
 
I've been working on a hack for this and I think I see the light at the end of the tunnel (of course, that could be an oncoming train! :D), but I don't want to add to the mismash here, which is very easy to do with only two examples, until I'm certain of the results you want. Could you post 3 or 4 more odds and their decimal equivelents? It would be good to have a couple of one type (i.e. 1/2) and a couple of the other (i.e. 2/1)
 
In the code above you are overwriting the first 2 instances of the value of x
 
My bad, sorry about that. Change it to this:
Code:
Function EvalField()
Dim ctl As Control
  Set ctl = Screen.ActiveControl
  ctl = Eval(ctl) + 1
End Function
I took out all the code that was using x. That code was so I could copy the formula that had been typed into the field into another text box so the formula could be preserved. You should not need any other code in here other than what I have shown.
 
Last edited:
Sorry Golfer, this just leaves the text box blank after the tab button.

Function EvalField()
Dim ctl As Control
Set ctl = Screen.ActiveControl
ctl = Eval(ctl) + 1
End Function

Then

Private Sub txtCoralHome_AfterUpdate()
Me.txtCoralHome = EvalField()
End Sub
etc. x3

missingling; a few more odds for you ;)

2/9 1.22 11/8 2.38 11/2 6.50
1/4 1.25 7/5 2.40 6/1 7.00
2/7 1.29 6/4 2.50 13/2 7.50
3/10 1.30 8/5 2.60 7/1 8.00
1/3 1.33 13/8 2.63 15/2 8.50
4/11 1.36 7/4 2.75 8/1 9.00
2/5 1.40 9/5 2.80 17/2 9.50
4/9 1.45 15/8 2.86 9/1 10.00
 
Then in the AfterUpdate property not event of the field to be changed to decimal odds, put this: =EvalField()
Did you put the =EvalField() into the AfterUpdate property of the field(s) you are dealing with?

I'm sorry, I said the afterupdate event, when I meant (in original post) to say property.
 
This is an interesting thread.

Coke, have you seen this website?
I want to be able to type a set of fractional odds into a textbox "txtodds" on my form and for it to be changed to decimal odds on the Lost_Focus Event.
E.g. If I enter 1/2, I want 1.5 to be displayed.
Code:
Control_LostFocus

Dim x As Single

x = Me.TextBoxControl

  Me.TextBoxControl = 1 + Me.TextBoxControl
 
Works like a dream Golfer! Thank you all very much.
Kev
 
I even have one of those lists stuck to my study wall Ajet, know most of them by heart in fact but i'd much rather read once and enter once, hence the code.
Thanks for your version though.
Kev
 
This code does what you want for the 24 examples you gave, so I assume it'll hold up to further testing!

Code:
Private Sub txtOdds_LostFocus()

Bet = Val(Right(Me.txtOdds, Len(Me.txtOdds) - InStr(Me.txtOdds, "/")))
PayOff = Val(Left(Me.txtOdds, Len(Me.txtOdds) - InStr(Me.txtOdds, "/") + 1))
Ratio = PayOff / Bet

  If Ratio < 1 Then
   
    If PayOff = 1 Then
     Me.txtOdds = Format((PayOff + Ratio), "0.00")
    Else
    OffSet = PayOff - 1
     Me.txtOdds = Format((PayOff + Ratio) - OffSet, "0.00")
    End If
  Else
   
   Me.txtOdds = Format(Ratio + 1, "0.00")
  End If
End Sub

Good Luck!:cool:

Linq
 
Thanks again guys. I've got Golfer's code up and running. Unfortunately, because its in Ater Update I cannot use the Decimal Places Format for the text box. Any chance of a bit of you know what to slip in somewhere, only want two DecimalPlace pleeease. If it,s easier to do at table level, then that works for me guys.
Cheers - Kev
 

Users who are viewing this thread

Back
Top Bottom