Solved

Grabbing stats from a .txt file- Repost!

Posted on 1998-10-17
3
148 Views
Last Modified: 2010-04-30
This is probably a pretty stupid question, but I need to extract specific data from a text file, assign each piece of data a variable, and manipulate the variables.  Here's the situation; Making a baseball stat page that withdraws from a text file in this format:

Abreu, Bobby        PHI OF   .312 151 139 497  68 155  29  
Agbayani, Benny     NYM OF   .133  11   3  15   1   2   0  
Alexander, Manny    CHN SS   .227 108  57 264  34  60  10  

What I want to do is assign the players' name and stats to seperate variables and then list the data.  Also interested in removing the data from the file after it's been extracted.  Any idea?

Thanks!
0
Comment
Question by:tomservo071698
3 Comments
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1440375
Yes, it is fairly easy to do.  The question is if the file is fixed-width or delimited file?  You could declare an ODBC datasource using the text driver, and manipulate the file like a database, or you could import the data yourself.

Let Me Know,
Martin
0
 
LVL 9

Expert Comment

by:david_levine
ID: 1440376
In addition to mkmccreary's recommendations:

For storing the results, what you want to do is use an array. First create your own datatype called Player with variables called Name, Team, Position, BattingAverage, etc.

Then create an Array, we'll call it Stats, of type Player.

For each record you read in from your file, you'll parse the line and load a new record into the array setting all the variables.
0
 
LVL 3

Accepted Solution

by:
kfrick earned 100 total points
ID: 1440377
Here ya go.....
Make a form with a command button on it, then paste in this code.
You can customize the resulds by adding or deleting values to "szValid" in the FindField$ Function.

Good Luck!

-kf


Private Sub Command1_Click()
Dim sz1 As String, sz2 As String, sz3 As String
Dim x As Integer

sz1 = "Abreu, Bobby        PHI OF   .312 151 139 497  68 155  29"
sz2 = "Agbayani, Benny     NYM OF   .133  11   3  15   1   2   0"
sz3 = "Alexander, Manny    CHN SS   .227 108  57 264  34  60  10"

    For x = 1 To 11
        Debug.Print FindField$(sz1, x)
    Next
    For x = 1 To 11
        Debug.Print FindField$(sz2, x)
    Next
    For x = 1 To 11
        Debug.Print FindField$(sz3, x)
    Next
   
End Sub

Function FindField$(szData As String, intFieldNum As Integer)
Dim szField  As String, szChar As String
Dim intPosition As Integer, intCount As Integer
Dim szValid As String

    szValid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789."
    FindField = ""
   
    szField = ""
    intCount = 0
    For intPosition = 1 To Len(szData)
        szChar = Mid$(szData, intPosition, 1)
        If InStr(szValid, szChar) > 0 Then
            If szField = "" Then intCount = intCount + 1
            szField = szField + szChar
        Else
            If intCount = intFieldNum Then
                FindField = szField
                Exit Function
            End If
            szField = ""
        End If
    Next
           
End Function

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 57
Visual Basic Excel Formatting error 4 102
MS Date Picker 64 bit 32 bit issue 12 53
vbModal 12 51
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question