PDA

View Full Version : VB Code


douglasw32
03-20-2011, 11:25 AM
I uploaded all the VB6 files of the code, HANDI if your out there will you send me the basic starting point code again for liberty basic so I can put that up also.

If someone wants to just follow the logic, this is what it does... not commented great, and learned most of what it does right here on this board, and some google searches.

It is actually very simple to write a basic program to do handicapping.

Remember I am a rookie with no training, never even read a book on the subject.

Some of my code has left over DIM's that are not used, it is a mess, but I just have not had time to clean it up.

The trick with getting the GUI is just knowing how to poke around VB6
and the project has to have the commondialog component as part of the project.

============================

'Released under the GNU General Public License
'``````````````````````````````````````````
'Do whatever you want with it, but give back your results ;)
'The following link define the drf(values)
''http://brisnet.com/cgi-bin/static.cgi?page=drfsff
'
'``````````````````````````````````````````
Option Explicit
Private Declare Function MakeSureDirectoryPathExists _
Lib "imagehlp.dll" (ByVal lpPath As String) As Long
Dim i As Integer
Dim strVarpath As String
Dim strVarpathmove As String
Dim FILE As String 'make FILE a string
Dim path As String
Dim tp As Double
Dim race As Long 'make race a number
Dim horse As String 'make horse a string
Dim countit As Integer 'make count a number
Dim J As Integer
Dim dist As Double
Dim jj As Integer
Dim cnt As Integer
Dim dv As Integer
Dim dd As Double
Dim NN As Integer
Dim par As Integer
Dim filefield As Variant
Dim filefield2(1435) As String
Dim totfig As Double
Dim drf(1435)
Dim cond As String
Dim speed As Double
Dim cond22 As String
Dim surf As String
Dim syn As String
Dim www As Integer
Dim addit As String
Dim prog As String
Dim fig As Double
Dim h As Integer
Dim fpath As String
Dim fpath2 As String
Dim fpath4 As String
Dim fpath5 As String
Dim hold(300, 18) As Double
Dim holdh(300, 2) As String
Dim holdfig(300, 1) As Double
Dim fig1 As Double
Dim cnt1 As Integer
Dim fig2 As Double
Dim fig3 As Double
Dim fig4 As Double
Dim fig5 As Double
Dim fig6 As Double
Dim fig7 As Double
Dim fig8 As Double
Dim fig9 As Double
Dim fig10 As Double
Dim fig11 As Double
Dim fig12 As Double
Dim fig13 As Double
Dim fig14 As Double
Dim fig15 As Double
Dim fig16 As Double
Dim fig17 As Double
Dim fig18 As Double
Dim maxValue As Double
Dim export(3000000, 1) As Double
Dim howmany As Double
Dim howmanynow As Double

'The Button to open the downloaded Bris file
Private Sub Command1_Click()

CommonDialog1.DialogTitle = "Select the BRISNET DRF SINGLE FILE..."

CommonDialog1.Flags = cdlOFNFileMustExist

CommonDialog1.Filter = "BRISNET/TSN DRF (*.drf;*.EG)|*.drf;*.EG"

CommonDialog1.ShowOpen

If Len(CommonDialog1.FileName) <> 0 Then

FILE = CommonDialog1.FileTitle
End If


If FILE = "" Then GoTo start:
Call ReadAFile(FILE) ' calls the subroutine we will use

start:
End Sub


'``````````````````````````````````````````
'Read bris/tsn file (it has to be a bris single file format drf file
'and has to be located in the same folder as the execuatbale file)
'Now we will, store it in a string,then put it into html format
'``````````````````````````````````````````




Private Sub ReadAFile(FILE) 'Name the subroutine

path = App.path

Open path + "\bin\racedata.htm" For Output As #2 'open the Comma File to write to it

Open FILE For Input As #1 'opens the drf file we selected for reading
race = 0 'set race to be the first
horse = "" 'set horse to be blank
cnt1 = 0
countit = 0 'set count to 0
cnt = 0
howmany = 0

Print #2, "<html><body>"


Do While Not EOF(1) 'does the folowing until the END OF THE FILE


'Read All fields of a Single Horse each time it loops




For J = 1 To 1435
Input #1, filefield
drf(J) = filefield
Next J


If countit = 0 Then Print #2, "<B><p style='font-size:medium;'>Thoroughbred Report Card V1.0</p></B><br>"


If countit = 0 Then Print #2, drf(1) & " | "
Dim date1 As String
If countit = 0 Then date1 = Str$(drf(2))
If countit = 0 Then Print #2, Left$(date1, 5) & "-"; Mid$(date1, 6, 2) & "-" & Right$(date1, 2)
countit = countit + 1 'count number of loops
cond = Left$(drf(10), 1)
cond22 = Mid$(drf(10), 2, 1)
If cond22 = "U" Then cond22 = "And Up"
If cond22 <> "And Up" Then cond22 = ""
If cond = "A" Then cond = "2 Year Olds"
If cond = "B" Then cond = "3 Year Olds"
If cond = "C" Then cond = "4 Year Olds"
If cond = "D" Then cond = "5 Year Olds"
If cond = "E" Then cond = "3 & 4 Year Olds"
If cond = "F" Then cond = "4 & 5 Year Olds"
If cond = "G" Then cond = "3, 4 & 5 Year Olds"
If cond = "H" Then cond = "ALL AGES"
surf = drf(7)
If Left$(drf(6), 1) = "-" Then surf = "Down Hill Turf"
If Left$(drf(6), 1) = "-" Then drf(6) = Mid$(drf(6), 2, Len(drf(6)) - 1)
If surf = "T" Then surf = "Turf"
If surf = "t" Then surf = "Inner Turf"
If surf = "D" Then surf = "Dirt"
If surf = "d" Then surf = "Inner Dirt"

syn = drf(25)
If syn <> "A" Then syn = ""
If syn = "A" Then syn = "( All Weather )"


If race <> drf(3) Then GoTo nope:
GoTo nope2:
nope:

Print #2, "<br>__________________________________________________ _________________________<br>"
Print #2, "Race #" & Val(race) + 1 & " for " & cond & " " & cond22 & ", " & drf(11) & ", going " & Format((Val(drf(6)) / 220), "#0.0"); "f, " & "on " & surf & " " & syn & " @ " & drf(1374)
Print #2, "<br>================================================== =================<br>"

nope2:

race = Val(drf(3))

path = App.path

Open path + "\bin\todays_scratches.txt" For Input As #3
www = 1
Do Until EOF(3)
Input #3, filefield2(www)

If drf(45) = filefield2(www) Then drf(45) = "scratched"
www = www + 1
Loop
Close #3
'================================================= ==============
'CRUNCH DATA HERE
'================================================= ==============
fig = 0
dv = 0
speed = 0
par = 0
fig1 = 0

If Val(drf(70)) > 0 And Val(drf(71)) Or Val(drf(72)) Or Val(drf(73)) Then fig = fig + 8
If fig = 0 And (Val(drf(1267)) - Val(drf(1264))) > 0 Then fig = fig + 8

If Val(drf(65)) > 0 And Val(drf(66)) Or Val(drf(67)) Or Val(drf(68)) Then fig = fig + 8


If (Abs((Val(drf(138)) / 220))) = 5 Then fig = fig + 8
If Val(drf(186)) > 2 And Val(drf(198)) = 1 Or Val(drf(198)) = 2 Then fig = fig + 8

If (Val(drf(666)) - Val(drf(686)) - Val(drf(726)) - Val(drf(746))) + (Val(drf(576)) - Val(drf(586)) - Val(drf(606)) - Val(drf(616))) > 4.9 Then fig = fig + 8

If drf(210) = "E " Then fig = fig + 8

dv = 0

If Val(drf(214)) <= Val(drf(766)) Then dv = dv + 1
If Val(drf(215)) <= Val(drf(776)) Then dv = dv + 1
If Val(drf(216)) <= Val(drf(786)) Then dv = dv + 1
If Val(drf(218)) <= Val(drf(816)) Then dv = dv + 1
If Val(drf(217)) <= Val(drf(846)) Then dv = dv + 1

If Val(drf(214)) <= Val(drf(766)) Then fig1 = fig1 + 8
If Val(drf(215)) <= Val(drf(776)) Then fig1 = fig1 + 8
If Val(drf(216)) <= Val(drf(786)) Then fig1 = fig1 + 8
If Val(drf(218)) <= Val(drf(816)) Then fig1 = fig1 + 8
If Val(drf(217)) <= Val(drf(846)) Then fig1 = fig1 + 8

If dv <> 0 Then fig = fig1 / dv




fig = fig + ((Val(drf(251))) - 112) ' divide by 10 for jcap, -100 for bris.
If fig < 0 Then fig = 0

fig1 = fig * 10


cnt = cnt + 1

If drf(45) = "scratched" Then GoTo skipthis:

'=====store
prog = drf(43)
horse = drf(45)


holdh(cnt, 1) = horse
holdh(cnt, 2) = prog

hold(cnt, 1) = fig1


If Len(drf(43)) < 2 Then drf(43) = "0" + drf(43)
For NN = 1 To cnt
If Val(drf(97)) = 0 Then Print #2, "FTS"
If hold(NN, 1) = 0 And Val(drf(97)) <> 0 Then Print #2, "<B>" & "......"
If Val(drf(97)) <> 0 And hold(NN, 1) <> 0 Then Print #2, "<B>" & Format$(Int(hold(NN, 1)), "000")
Print #2, "</B> (" & drf(43) & ") " & holdh(NN, 1) & "<br>"

howmany = howmany + 1
export(howmany, 1) = Int(hold(NN, 1))

Next NN



skipthis:



cnt = 0

Loop 'Do it all again until no more horses
'Last Race Done Now Continue to do things with the data in vbasic or just use the CSV generated for Excell or Access etc.

'SORT and COUNT !
'======================================

Print #2, "<br> 2008 Equibase Company LLC. All Rights Reserved. Software 2008 Douglas Wood<br>"
Print #2, "<br>"


Print #2, "</body></html>"


Close #2 'close the CSV file

Close #3

Close #1 'close the read file

'EXPORT FOR ALLDATA
Open FILE For Input As #1 'opens the drf file we selected for reading
strVarpath = "C:" & "\tsn1\"


strVarpathmove = strVarpath
'NOTE: make sure complete path ends with backslash
MakeSureDirectoryPathExists strVarpathmove
'Check to see if folders exist in said path and if not Create them
Open strVarpathmove + FILE For Output As #2
howmanynow = 0
Do While Not EOF(1)
For J = 1 To 1435
Input #1, filefield
If filefield = "" Then GoTo noq:
dd = 0
If VarType(filefield) <> 8 And VarType(filefield) <> 7 Then dd = 1
filefield = Trim(filefield)
If dd = 1 Then filefield = Val(filefield) 'count space for zero's
'If filefield = 0 Then filefield = "" + Space(Len(filefield))
If VarType(filefield) = 8 Or VarType(filefield) = 7 Or J = 43 Or J = 18 Or J = 19 Or J = 20 Or J = 240 Or J = 241 Or J = 242 Or J = 243 Or J = 244 Or J = 245 Or J = 246 Or J = 247 Or J = 248 Then Print #2, """"; 'may bugout if other field is 8 and number?"
If J = 251 Then howmanynow = howmanynow + 1
If J = 251 Then Print #2, export(howmanynow, 1);
If J <> 251 Then Print #2, filefield;
If VarType(filefield) = 8 Or VarType(filefield) = 7 Or J = 43 Or J = 18 Or J = 19 Or J = 20 Or J = 240 Or J = 241 Or J = 242 Or J = 243 Or J = 244 Or J = 245 Or J = 246 Or J = 247 Or J = 248 Then Print #2, """";
GoTo yep:
noq:
If J = 251 Then howmanynow = howmanynow + 1
If J = 18 Or J = 19 Or J = 20 Or J = 240 Or J = 241 Or J = 242 Or J = 243 Or J = 244 Or J = 245 Or J = 246 Or J = 247 Or J = 248 Then Print #2, """";
If J = 18 Or J = 19 Or J = 20 Or J = 240 Or J = 241 Or J = 242 Or J = 243 Or J = 244 Or J = 245 Or J = 246 Or J = 247 Or J = 248 Then Print #2, """";
yep:
If J < 1434 Then Print #2, ",";
If J = 1434 Then Print #2, ","
Next J
Loop
Close #1
Close #2

MsgBox "Go Baby Go ! You can open the report."


End Sub




'The Button to open the Report
Private Sub Command2_Click()
fpath2 = "http://www.brisnet.com/cgi-bin/trk_report.cgi?drs"
Shell "explorer.exe """ & fpath2 & """"

End Sub



Private Sub Command3_Click()
path = App.path

Shell "explorer.exe " & "file://" + path + "\bin\racedata.htm"

End Sub

Private Sub Command4_Click()
Dim linne As String
path = App.path

linne = "notepad " + path + "\bin\todays_scratches.txt"
Shell linne, vbNormalFocus
End Sub

Private Sub Command5_Click()
fpath = "http://www.brisnet.com/cgi-bin/trk_report.cgi?scr"
Shell "explorer.exe """ & fpath & """"
End Sub



Private Sub Command8_Click()
fpath4 = "http://www.equibase.com/static/chart/pdf/index.html"
Shell "explorer.exe """ & fpath4 & """"
End Sub
==========================

This may help someone with the same aspirations I had get started =)
with there own home grown program.

http://www.brisnet.com/cgi-bin/static.cgi?page=drfsff

douglasw32
03-20-2011, 11:33 AM
The way this works is very simplistic, using sub routines and calls to them, and multiple forms for displaying the data on the screen instead of what I am doing (Writing the data a line at a time to an HTML file) allows for storing more of the data first, then pulling it out, sorting it, scratching horses etc later in another part. That is how handifast works. I started down that path with this code but I have not gone that far yet other than to declare it.

Also http://en.kioskea.net/download/download-104-visual-basic-express-edition

This looks perfect for someone who want sto get started without the $700.00 investment for visual studio.

Of course what handifast is coded in is free, and the logic is still the same.

Locate the file, read it, store every comma value as a variable, refer to the data layout from bris, and find what you need, do something with it, display it.

Any language can do that, then the sky is the limit, IMHO

headhawg
04-02-2011, 01:20 PM
Doug,

Have you changed this code at all? I am trying to incorporate the number into Handifast HHX so I wanted it to be the latest and greatest version.

HH

douglasw32
04-02-2011, 05:54 PM
THAT WOULD BE SO AWESOME !!!!

Yes it is modified based on what I learned using the exports from my TRC Program in All Data.

It should replace the FAST figure. (I never liked that fig as a stand alone)

This one I do, alot !

If you took the outdated FAST figure and replaced it with the one in the current code file at http:/localpcpros.com/handifast (http:/localpcpros.com/handifast)

I think you would find it improves things. I would love a copy.

Just uploaded the FINAL version, I am done "Touching It"

douglasw32
04-02-2011, 05:57 PM
This is the chunk that takes care of the Math part.
(Final Version)
====================================
'================================================= ==============
'CRUNCH DATA HERE
'================================================= ==============
fig = 0
dv = 0
speed = 0
par = 0
fig1 = 0

If Val(drf(70)) > 0 And Val(drf(71)) > 0 Or Val(drf(72)) > 0 Or Val(drf(73)) > 0 Then fig = fig + 8
If fig = 0 And (Val(drf(1267)) - Val(drf(1264))) > 0 Then fig = fig + 8

If Val(drf(65)) > 0 And Val(drf(66)) > 0 Or Val(drf(67)) > 0 Or Val(drf(68)) > 0 Then fig = fig + 8


If (Abs((Val(drf(138)) / 220))) = 5 Then fig = fig + 8

If Val(drf(186)) > 2 And Val(drf(198)) = 1 Or Val(drf(198)) = 2 Then fig = fig + 8

If (Val(drf(666)) - Val(drf(686)) - Val(drf(726)) - Val(drf(746))) + (Val(drf(576)) - Val(drf(586)) - Val(drf(606)) - Val(drf(616))) > 4.9 Then fig = fig + 8

If drf(210) = "E " Then fig = fig + 8

dv = 0

If Val(drf(214)) <= Val(drf(766)) Then dv = dv + 1
If Val(drf(215)) <= Val(drf(776)) Then dv = dv + 1
If Val(drf(216)) <= Val(drf(786)) Then dv = dv + 1
If Val(drf(218)) <= Val(drf(816)) Then dv = dv + 1
If Val(drf(217)) <= Val(drf(846)) Then dv = dv + 1

If Val(drf(214)) <= Val(drf(766)) Then fig1 = fig1 + 8
If Val(drf(215)) <= Val(drf(776)) Then fig1 = fig1 + 8
If Val(drf(216)) <= Val(drf(786)) Then fig1 = fig1 + 8
If Val(drf(218)) <= Val(drf(816)) Then fig1 = fig1 + 8
If Val(drf(217)) <= Val(drf(846)) Then fig1 = fig1 + 8

If dv <> 0 Then fig = fig1 / dv

tr = 0
tr1 = 0
tr2 = 0
dv = 0
cl = 0


If Val(drf(217)) > Val(drf(846)) + 3 And Val(drf(846)) > 0 And Val(drf(616)) > 1 Then dv = dv + 1
If Val(drf(217)) > Val(drf(847)) + 3 And Val(drf(847)) > 0 And Val(drf(617)) > 1 Then dv = dv + 1
If Val(drf(217)) > Val(drf(848)) + 3 And Val(drf(848)) > 0 And Val(drf(618)) > 1 Then dv = dv + 1
If Val(drf(217)) > Val(drf(849)) + 3 And Val(drf(849)) > 0 And Val(drf(619)) > 1 Then dv = dv + 1
If Val(drf(217)) > Val(drf(850)) + 3 And Val(drf(850)) > 0 And Val(drf(620)) > 1 Then dv = dv + 1
If Val(drf(217)) > Val(drf(851)) + 3 And Val(drf(851)) > 0 And Val(drf(621)) > 1 Then dv = dv + 1

If dv > 1.5 Then cl = 1



If Val(drf(29)) > 0 Then tr1 = (Val(drf(30)) / Val(drf(29))) * 100
tr = tr1
If Val(drf(1147)) > 0 Then tr2 = (Val(drf(1148)) / Val(drf(1147))) * 100
If tr2 > tr Then tr = tr2

If tr < 12 And cl = 1 Then fig = fig - 8
pace2 = 0

For ctt = 0 To 9
dist = Abs(Val(drf(316 + ctt)) / 220)
If dist < 8 Then pace = Val(drf(766 + ctt)) + Val(drf(776 + ctt)) + Val(drf(846 + ctt))
If dist > 7.5 Then pace = Val(drf(776 + ctt)) + Val(drf(816 + ctt)) + Val(drf(846 + ctt))
If dist < 8 And Val(drf(766 + ctt)) + Val(drf(776 + ctt)) + Val(drf(846 + ctt)) < Val(drf(776 + ctt)) + Val(drf(816 + ctt)) + Val(drf(846 + ctt)) Then pace = Val(drf(776 + ctt)) + Val(drf(816 + ctt)) + Val(drf(846 + ctt))
If dist > 7.5 And Val(drf(776 + ctt)) + Val(drf(816 + ctt)) + Val(drf(846 + ctt)) < Val(drf(776 + ctt)) + Val(drf(816 + ctt)) + Val(drf(846 + ctt)) Then pace = Val(drf(776 + ctt)) + Val(drf(816 + ctt)) + Val(drf(846 + ctt))
If pace > pace2 Then pace2 = pace
Next ctt
fig = fig + (pace2 / 3)

fig = fig + Val(drf(251))
fig1 = fig / 2
==========================================
http://brisnet.com/cgi-bin/static.cgi?page=drfsff