Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting data and populating tables from a single textfield

Status
Not open for further replies.

Cali92

Programmer
Oct 4, 2003
1
IT
Hi everyone.
I have a problem with a scouting-like software.
I have a table, with names and numbers of players
(ie 1->12)
Then I have codes meaning actions and values.

I need that in a textfield I will insert a complex code like

4b+16 3d+5 2p-3 1a=d4

where it means : 4 = n°of the player
b = serve
+ = not too good, not too bad
1 = from our court zone 1
6 = to other team court zone 6

So, how can I parse or split the code as it will fill the table ACTION which fields are :

n° | Action | Value | From | To |

-------------------------------------
In this way I will have a table to extract all datas to have charts or what I need to analyze the match ...


Thanks in advance !!!
 
Your example, 4b+16 3d+5 2p-3 1a=d4 does not seem to be consistent. In the second sequence, is the 5 From or To (or both?). In the fourth sequence, what is the "d"?

Here is a function that comes close to what I think you want, but probably needs some refinement once all of the coding rules become known:
[blue]
Code:
Option Explicit

Sub test()
Dim sText As String
Dim nPlayer As Integer
Dim sAction As String
Dim sValue As String
Dim nFrom As Integer
Dim nTo As Integer

  sText = "4b+16 3d+5 2p-3 1a=d4"
  While ComplexParse(sText, nPlayer, sAction, sValue, nFrom, nTo)
    MsgBox "Player = " & nPlayer & vbNewLine & _
           "Action = " & sAction & vbNewLine & _
           "Value = " & sValue & vbNewLine & _
           "From = " & nFrom & vbNewLine & _
           "To = " & nTo & vbNewLine
  Wend
End Sub

Function ComplexParse(AText As String, APlayer As Integer, _
             AAction As String, AValue As String, _
             AFrom As Integer, ATo As Integer) As Boolean
[green]
Code:
' AText contains 5 or 6 character strings separated by spaces
' Format: nnAVxy  or nAVxy
[/color]
Code:
Dim nOffset As Integer
[green]
Code:
  ' First, allow for possible extra spaces
[/color]
Code:
  AText = Trim(AText)
  If Len(AText) < 5 Then
    ComplexParse = False
  Else
    On Error Resume Next
[green]
Code:
    ' Player is one or two numbers
[/color]
Code:
    APlayer = 0
    If Mid(AText, 2, 1) < &quot;0&quot; Or Mid(AText, 2, 1) > &quot;9&quot; Then
      APlayer = Left(AText, 1)
      nOffset = 0
    Else
      APlayer = Left(AText, 2)
      nOffset = 1
    End If
    AFrom = 0
    ATo = 0
    AAction = Mid(AText, 2 + nOffset, 1)
    AValue = Mid(AText, 3 + nOffset, 1)
    AFrom = Mid(AText, 4 + nOffset, 1)
    ATo = Mid(AText, 5 + nOffset, 1)
    AText = Mid(AText, 6 + nOffset, 999)
    ComplexParse = True
  End If
End Function
[/color]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top