Parse Pickle

Started by Petrus Vorster, July 17, 2014, 02:23:31 AM

Previous topic - Next topic

Petrus Vorster

I got myself in a brain twist again....  :o

I made an entire module to automate the way i used random files. Works like a charm, except one issue....
I had to go back to using delimited formats and use PARSE and PARSECOUNT as i want the module to be able to accommodate any program i make without having to go and do UDT pointers etc in the module.
On the fly in other words.

The one function must evaluate multiple words e.g. "JOHN, SMITH, 1969/12/30, Kansas" in that order against the file entries in that same order. JOhn = column 1, SMITH = column 2 and so on.
Only if all 4 are true then it places the info in a listview.

Easy if you know how many elements will be passed, but this function must accommodate it regardless of the count. It must use the parsecount to see there is perhaps 6 elements to be checked and then check the 6 elements in every line in the file.

Its just that little bit i cant get right yet. Perhaps someone have a pointer for me?

-Regards
Peter

David Kenny

It's not immediately obvious to me what you are asking.  There doesn't seem to be enough info to go on.  I'm guessing parsecount doesn't give you the right answer every time?  Otherwise, as you said, it should be easy.

Jim Dunn

But, if you show your source for this awesome module, we'd be glad to try to help update it!  : )
3.14159265358979323846264338327950
"Ok, yes... I like pie... um, I meant, pi."

Petrus Vorster

hahahha, i kind of DONT want to show you my module, since i feel sometimes a bit "behind" you guys!!! ;D

Ok, i send a string to a module.
This string was made by adding selections in for example a form with multipe dropdowns.
The parsecount gives the right info yes, but i just seem not to be able to wrap my head around it on how to confirm say six things in one string with six strings in another and only confirm it when all six matches.
(especially since the quantities send by one user will be different for another function. I think its just something small i am again missing.
Here are some of the stuff.

Function Find_all(Filename As String,maxlen As Long, mylistview As Dword, searchstring As String, searchField As Long ) As String
If Trim$(searchstring$) = "" Then Exit Function
'finds all entries that CONTAINS a string in only one specific field and places in listview
FF_ListView_DeleteAllItems(mylistview)
Dim NEWLEN As Long
NEWLEN = FreeFile
Dim newstring As String
Try   
Open filename For Random As #NEWLEN Len = maxlen
   Get #NEWLEN,1,filecounter$
    mycount& = Val(Trim$(filecounter$))
     For runner& = 2 To mycount&
        Get #newlen,runner&, mydata$
          GoSub entrypoint
   
     Next runner&
    Close #NEWLEN
Catch

End Try
Exit Function
Entrypoint:
mydata$ = mydata$ + Trim$(Str$(runner&)) 'adds a index in the listview
Dim xstring$(1 To ParseCount(mydata$))
xrunner& = ParseCount(mydata$)
Parse mydata$,xstring$()
  If Instr(xstring$(searchfield),searchstring) > 0 Then
  place& = FF_ListView_GetItemCount(mylistview)
  For newrunner& = 1 To xrunner&
  FF_ListView_InsertItem (mylistview,place&,newrunner&-1,xstring$(newrunner&)) 
  Next xrunner&
  End If
 
Return



End Function
'-----------------------------------------------------------------------------------------------
Function Dump_all(Filename As String,maxlen As Long, mylistview As Dword) As String  'Dump entire file contents in a listview
'open file and dump entire content into a listview.
FF_ListView_DeleteAllItems(mylistview)
Dim NEWLEN As Long
NEWLEN = FreeFile
Dim newstring As String
Try   
Open filename For Random As #NEWLEN Len = maxlen
   Get #NEWLEN,1,filecounter$
    mycount& = Val(Trim$(filecounter$))
     For runner& = 2 To mycount&
        Get #newlen,runner&, mydata$
          GoSub entrypoint
   
     Next runner&
    Close #NEWLEN
Catch

End Try
Exit Function
Entrypoint:
mydata$ = mydata$ + Trim$(Str$(runner&))
Dim xstring$(1 To ParseCount(mydata$))
xrunner& = ParseCount(mydata$)
Parse mydata$,xstring$()
  place& = FF_ListView_GetItemCount(mylistview)
  For newrunner& = 1 To xrunner&
  If Trim$(xstring$(1)) <> "**********" Then
  FF_ListView_InsertItem (mylistview,place&,newrunner&-1,xstring$(newrunner&)) 
  End If
  Next xrunner&

Return

End Function

This example returns basically all matches from the given file in a certain field, the other dumps the entire file in a listview.
But i will need to make some report manager where one can select for instance:
All equipment, on which network, in which region and so forth and change it later to more or less entires.

I wanted to upload the screenprint but somehow i cant get this image insert right.
-Regards
Peter

David Kenny

Quotei just seem not to be able to wrap my head around it on how to confirm say six things in one string with six strings in another and only confirm it when all six matches
You have not shown any code or module for this.  What form is the data in when it gets to the compare?

Am I right to assume the two modules you did show work as you want them to?

Without the answers to the questions above, here is my current idea of what you are looking for:'Not sure how you are getting your data to this routine but I am using delimited strings
'as your example code shows you are familiar with that.
Function MatchAll(String1 As String, String2 As String) As Long   'Return True or False
   
   StrCount& =  ParseCount(String1)
   Dim S1$(StrCount&)
   Dim S2$(StrCount&)
   Parse String1, S1$()
   Parse String2, S2$()
   
   For i& = 1 To StrCount&
      If S1$(i&) <> S2$(i&) Then
         Function = %False                         'Set the return code to False
         Exit Function                                'Get out
      End If
   Next i
   Function = %TRUE                               'If we made it through all checks, set the return code to True
Exit Function


Petrus Vorster

Beautiful! Thanks a million.

Yes, my other functions works great.
I didnt know one can compare a string with elements like that. Now it is logical!.
I was about to start playing in that direction. (Finding the time to sit in front of the pc though.....)

Your example is perfect, now one last question.
If one would like to use INSTR in this and not a direct match could you use IF instr(string1$(stringcount&)) <> instr(stringb$(stringcount&)) ???
It is sometimes necessary to use INSTR to find a close-enough match or something containing that word.

Thanks for the patience and help!
-Regards
Peter

David Kenny

If one would like to use INSTR in this and not a direct match could you use IF instr(string1$(stringcount&)) <> instr(stringb$(stringcount&))Well, I'm not sure what you are asking again. In your example, both calls to Instr are incomplete and Instr returns a position.

You should always explain your data first, then what you expect for a result.  For instance, you say "I need to be able to tell if string A is in string B. An here is some sample data:"
A = "router", B = "Cisco Router"

If that is what you are asking then here would be my answer:If Instr(LCase$(B), LCase$(A)) = 0 then  'No match (greater that zero indicates the position the match was found)



Petrus Vorster

Hi, sorry its unclear.

I will tinker with it a bit more and see what i come up with.

thanks for the help.
-Regards
Peter