PDA

View Full Version : vb code for looping


exactajack
04-17-2005, 08:53 AM
can any programmers out the share some code for how you loop thru the data files to get each horse name to display with it's race dates underneath it and then the next horse and so on

syyamo
04-17-2005, 10:00 AM
The following is from another post on this topic somewhere on this board:

------------------------------------------------------------------------
Using VB to read a past performance file is not all that hard to do. Here's a code snippet that I've used with VB6 with great success for years.
Something very similar should work as VBA code inside of Access 97 or Access 2000.

Create a standard EXE VB project and add a command button to your form.

In the declarations portion of your VB Project, paste in the following code:

Dim FieldVal (1435)
Public FILE as String

And then place this bit of code in the click event procedure behind the command button:

FILE = InputBox("Enter File Name:")
If Not FILE = "" Then
call ReadAFile(FILE)
end if


And then create a subroutine named ReadAFile. Here's the code for that; you can just copy and paste it in:

Private Sub ReadAFile(FILE)

Err.Clear
On Error Goto handler:

Open FILE for input as #1

Do While Not EOF(1)

'Read A Single Horse:

For j = 1 To 1435
Input #1, fileField
FieldVal(j) = fileField
Next j


'Done With Single Horse, now do something interesting.




Loop


handler:
If Not Err.Number = 0 then

MsgBox Err.Number & " " & Err.Description, vbCritical, "Error"
Err.Clear
-------------------------------------------------------

Just pull out the horse name and date from the array and your done.