Solved

Grabbing stats from a .txt file- Repost!

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

14 Experts available now in Live!

Get 1:1 Help Now