Solved

Grabbing stats from a .txt file- Repost!

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 41
How to measure sizes and angles in scanned images ? 3 89
Added a column screws up code 5 69
Formula problem with Excel attachment 6 43
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

697 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