Results 1 to 8 of 8

Thread: [RESOLVED] Detect a string formatting

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    Resolved [RESOLVED] Detect a string formatting

    Hi, i have been using the InStr function to detect strings within strings...

    if instr(1, "Call", Line) then...

    but i have a string it needs to detect, but i need to detect it by the formatting of it, as every letter in the string will be different meaning i cannot use the InStr function.

    the text will appear like this:
    7h 9d Kh (Flop)
    OR
    2c 4d Qh Qs (Turn)
    OR
    Th 3d 4h 9s Jc (River)

    the first letter will always be a number or: J,Q,K,A
    and the second letter will always be lowercase: c,h,d,s
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  2. #2
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Detect a string formatting

    Because each 'word' you use, have a space between them, you can simply Split() up the content, that you can analyse element by element.

    Code:
    Dim aLine() As String, i as Long
    aLine = Split(Line," ")
    For i = 0 to Ubound(aLine)
      Select Case uCase(Left$(aLine(i),1))
       Case Is = "J"
         'J...
        Debug.Print Right$(aLine(i),1) 'secondary letter.
       Case Is = "Q"
         'Q...
       '...... more cases come here
       Case Is = "1"
         '1...
       Case Is = "2"
         '2...
       '...... even more cases come here
       Case Else
         'Nothing the above, it could be an illegal message.
      End Select
    Next i

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    Re: Detect a string formatting

    Here is an example of the text it will come across:

    Dealer: ronnieone calls 10
    Dealer: willeone5 calls 5
    Dealer: jfranck checks
    Dealer:
    Dealing Flop
    5s 9d 7h
    Dealer: willeone5 checks
    Dealer: jfranck checks
    Dealer: Lolitorico27 bets 10
    Dealer: pomca folds
    Dealer: setport77 calls 10
    Dealer: retxinesss calls 10
    Dealer: yoris14 folds
    Dealer: jovenard folds
    Dealer: ronnieone folds
    Dealer: willeone5 calls 10
    Dealer: jfranck folds
    Dealer:
    Dealing Turn
    5s 9d 7h Ad
    Dealer: willeone5 checks
    Dealer: Lolitorico27 bets 20
    I can detect the "Dealing Flop", and "Dealing Turn". but it needs to be able to get the cards also, as they will be split up, and then put into seperate text boxes.. and then images

    i was expecting somthing like: if Format(line, "## ## ##") then flop
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  4. #4
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Detect a string formatting

    Before each 'data words', there is a Command, that you have to interpret, that the next line will be a Turn, a Flop or whatever it is. Store the result in a value (lNextData) that you can recall next time.

    Code:
    Private lNextData As Long
    
    '....
    
    lNextData = 0 'Clear the value
    If Instr(Line,"Dealing Flop") > 0 Then lNextData = 1
    If Instr(Line,"Dealing Turn") > 0 Then lNextData = 2
    If Instr(Line,"Dealing River") > 0 Then lNextData = 3
    Now, where you process the lines, you can simply check the lNextData, if its greater than zero, it should be interpreted, otherwise your code have to skip the extra process.

    Code:
    Dim aLine() As String, i as Long
    
    If lNextData = 1 Then
      'Process the Flop event
      aLine = Split(Line," ")
      For i = 0 to Ubound(aLine)
      '...
    ElseIf lNextData = 2 Then
      'Process the Turn event
      aLine = Split(Line," ")
      For i = 0 to Ubound(aLine)
      '...
    ElseIf lNextData = 3 Then
      'Process the River event
    Else
      'It is not a data word, you can process those lines here...
      lNextData = 0 'Clear the value
      If Instr(Line,"Dealing Flop") > 0 Then lNextData = 1
      If Instr(Line,"Dealing Turn") > 0 Then lNextData = 2
      If Instr(Line,"Dealing River") > 0 Then lNextData = 3
    
    End If

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Detect a string formatting

    Try this one

    vb Code:
    1. Private Sub Command1_Click()
    2. MsgBox (TestRegExp(Text1.Text))
    3. End Sub
    4. Function TestRegExp(myString As String)
    5.    'Create objects.
    6.    'the first letter will always be a number or: J,Q,K,A
    7. 'and the second letter will always be lowercase: c,h,d,s
    8.    Dim objRegExp As RegExp
    9.    Dim objMatch As Match
    10.    Dim colMatches   As MatchCollection
    11.    Dim RetStr As String
    12.    
    13.    ' Create a regular expression object.
    14.    Set objRegExp = New RegExp
    15.  
    16.    'Set the pattern by using the Pattern property.
    17.    objRegExp.Pattern = "([0-9]|[JQKA])[chds]+"
    18.  
    19.    ' Set Case Insensitivity.
    20.    objRegExp.IgnoreCase = True
    21.  
    22.    'Set global applicability.
    23.    objRegExp.Global = True
    24.  
    25.    'Test whether the String can be compared.
    26.    If (objRegExp.Test(myString) = True) Then
    27.  
    28.    'Get the matches.
    29.     Set colMatches = objRegExp.Execute(myString)   ' Execute search.
    30.  
    31.     For Each objMatch In colMatches   ' Iterate Matches collection.
    32.       RetStr = RetStr & "Match found at position "
    33.       RetStr = RetStr & objMatch.FirstIndex & ". Match Value is '"
    34.       RetStr = RetStr & objMatch.Value & "'." & vbCrLf
    35.     Next
    36.    Else
    37.     RetStr = "String Matching Failed"
    38.    End If
    39.    TestRegExp = RetStr
    40. End Function


    Add reference to : Microsoft VBScript Regular Expressions 5.5,
    Please mark you thread resolved using the Thread Tools as shown

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    Re: Detect a string formatting

    this method just came to me, thanks for writing that up once again.
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  7. #7
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: [RESOLVED] Detect a string formatting

    @danasegarane: Nice! RegExp, i just can learn its syntax ^^

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] Detect a string formatting

    Thanks Jim Davis
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width