Replace fractional Odds with Decimal

This is the last piece of my jigsaw and I couldn't have done it without you guys. I've got 5 years of data to enter, when I'm done, so I should be outa your hair for a while. One last piece friends, please.
kev
 
Is there an order to the events? (apart from the obvious). I mean does Lost Focus happen before After Update etc. I tried =Round([txtOdds],2) in the Lost Focus property but it doesn't work!
 
I now know the order of events, so I know that Lost Focus occurs AFTER After Update, which doesn't answer too many other questions.
P.S. I still have the table that does the job, if it would be easier to explain that method.
 
This site is going bonkers again! I posted this answer last night, and after getting errors for half an hour this morning, trying to log on to the site, I find my last post is gone!

Anyway, the following code does the conversion correctly on all 24 examples you posted yesterday, 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
 
Hi again missinglinq
I notice in your code you have "0.00" (2 decimal places). Will this restrict the entry to 2 decimal places, which is what I am now looking for, having already taken golfers generous advice, which works fine apart from the above-mentioned.
Regards
Kev
 
Yes, I figured from you examples, that you wanted to limit it to 2 decimals places, and hence the formatting to "0.00" !

I see my previous post is now showing! This site is behaving most strange this morning!
 
I'm totally awestruck man.
Thank you
Thank you all.
Kev
 
I'm assuming this is how you are now formatting this:
Code:
  ctl = Format(Eval(ctl) + 1, "0.00")
 
Afraid not golfer, as much as I've learned from you guys over the last couple of weeks, the last couple of days have been frustrating with the end in sight. I should have thought of that one but my head is now mashed and desperation for an easy solution has set in, I deleted your hard work friend and replaced it with missinglinqs. Everyone in here has inspired me and anyone who visits should think themselves lucky. Didn't know the first thing about access two weeks ago and I am very proud of what I have learned and what I have achieved, so thank you all again for your kindness.
 
Actually I just noticed that if I scroll through my records, which already include the decimal odds, they all change to "2.00".
 
Personally, I would be tempted to have two numerical fields and on the Form separate these fields with a "/". You are always in the realm of numerical calculations. I say this from my experience trying convert to centimetres to inches of the other way 'round. I have to interpret the quarter / half and three quarter symbols - dealing with the numerical fields in easy by comparison.

Simon
 
Actually I just noticed that if I scroll through my records, which already include the decimal odds, they all change to "2.00".

That's sounds like the the behavior of an unbound control! Is txtOdds bound to a field in the underlying table?
 
If you mean, 'is the control source of the txtOdds box, the Odds field on my table', then yes. Just to throw a spanner in the works though missinglinq. Whilst searching for historical odds data, I came across this site http://www.football-data.co.uk/mmz4281/0708/E0.csv, which actually lists the odds in csv format for most of the leagues I am dealing with. Now the dreaded question; Is ther a way of extracting the odds data direct from the website, by matching up the Date, Home Team and Away Team (unique) to the record containing the odds I need?
 
I would settle for being able to enter the decimal odds into the txtodds box but I can't do that, as it returns the value to 2.00 on lost focus. I now have to convert decimal odds to fractional to put in the box to have them converted back lol.
 
May I suggest you run the function from the AfterUpdate property rather than the lost focus property. I would think you do not want any calculations done to the existing field unless you have entered some data.
 
Have you looked at the table itself to see what is out there? I'm assuming that the old way has actually changed all your data to 2.00. If so, you will have to rekey it unless you have a backup somewhere.
 

Users who are viewing this thread

Back
Top Bottom