?
Solved

Grabbing stats from a .txt file- Repost!

Posted on 1998-10-17
3
Medium Priority
?
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 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