Solved

Grabbing stats from a .txt file- Repost!

Posted on 1998-10-17
3
145 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now