Announcement

Collapse
No announcement yet.

Parsing...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parsing...

    I have this line of code:

    MSGBOX UCASE$(TRIM$(PARSE$(lRec$,"|",2)))

    and this is part of the file it's reading:

    SANTOPRENCE GRIP|W
    NATURAL CORK|X
    RUBBER CORK COMPOUND|Y
    PINS|Z
    Test|AB

    When I enter AB, only the A is read. How can I get AB to be read?

  • #2
    Is there maybe a NULL Character between the A and the B ? What you have should return the AB as long as there are not any NULLs.

    Try adding lRec$ = Remove$(lRec$, $Nul) before you call your MSGBOX line.
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

    Comment


    • #3
      Scott

      Thank you for your input.

      I looked and retyped and there are no null characters between A and B... it's just AB. I added your line and I still only get A as the return.

      Katherine

      Comment


      • #4
        Code:
        #Compile Exe
        #Dim All
         
        Function PBMain () As Long
         
            Local lRec As String
            
            lRec = "Test|AB"
            
            MsgBox UCase$(Trim$(Parse$(lRec,"|",2)))
         
        End Function
        It works if you do it this way, how are you getting your data into lRec$ ? I would check it beforehand to make sure that it prints out "Test|AB".
        Scott Slater
        Summit Computer Networks, Inc.
        www.summitcn.com

        Comment


        • #5
          Scott,

          Here is the sub that shows how the data is going into lRec$:

          SUB FetchComponentID
          CLOSE #1
          LOCAL lRec$
          OPEN "M:\Scanners\components.ini" FOR INPUT LOCK SHARED AS #1
          IF ERR THEN
          MSGBOX STR$(ERR)+" "+ERROR$+$LF+"Openning M:\Scanners\components.ini"
          EXIT SUB
          END IF
          IF LOF(1)=0 THEN
          gAns&=EZ_MsgBox("SCAN","No Component Items Exist","Shop Floor Bill Of Material","OK")
          SQL_ShutDown
          EZ_UnLoadForm "SCAN"
          END IF
          DO WHILE NOT EOF(1)
          LINE INPUT #1,lRec$
          IF MID$(lRec$,1,3)="REM" THEN ITERATE DO

          lRec$ = REMOVE$(lRec$, $NUL)

          IF UCASE$(TRIM$(PARSE$(lRec$,"|",2)))=MID$(EZ_GetText("SCAN",%SCAN_ORDERNO),14,2) THEN 'was 14,1
          gItemNo$=UCASE$(TRIM$(PARSE$(lRec$,"|",1)))
          gIDError&=0
          CLOSE #1
          EXIT SUB
          END IF
          LOOP

          gIDError&=1
          CLOSE #1
          END SUB

          Comment


          • #6
            I would suggest adding:

            Code:
            MSGBOX lRec$,0,"DEBUG"
            Before the line:

            Code:
            IF UCASE$(TRIM$(PARSE$(lRec$,"|",2)))=MID$(EZ_GetText ("SCAN",%SCAN_ORDERNO),14,2) THEN 'was 14,1
            Run the program and see what the debug message box shows you. See if the AB follows the "|" symbol in your string.
            Scott Slater
            Summit Computer Networks, Inc.
            www.summitcn.com

            Comment


            • #7
              No, it didn't. "PULL PLATE|A" is what was listed instead.

              Comment


              • #8
                The problem is then somewhere else. You will have to check the file itself, and all of the I/O functions related to the file.
                Scott Slater
                Summit Computer Networks, Inc.
                www.summitcn.com

                Comment


                • #9
                  Thank you for your help. I have rewritten the .ini, but no luck so far. I will take your suggestion and look through the code again. I think I have looked at it so much, though, that I'm beginning to skip over lines. However, nothing I have tried has worked yet.

                  Comment


                  • #10
                    BION, this is a good place for the stepping debugger. (Say what? MCM suggesting the stepping debugger?)

                    However, you will only get good value for this if you replace all those multiple function statements, e.g....
                    Code:
                    IF UCASE$(TRIM$(PARSE$(lRec$,"|",2)))=MID$(EZ_GetText ("SCAN",%SCAN_ORDERNO),14,2) THEN 'was 14,1
                    .. with some intermediate variables you can "watch"
                    Code:
                    a$ = PARSE$(lRec$,"|",2)
                    a$ = UCASE$(TRIM$(a$))
                    b$= EZ_GetText ("SCAN",%SCAN_ORDERNO)
                    b$ = MID$(B$, 14,2) 
                    IF B$ = A$ THEN ....
                    ....
                    Step thru the code line by line watching a$ and b$. If something funny is happening it will show up for you.

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Thank you for your advise, Michael, I will try it.

                      I wanted to you let you all know that when I changed AB to 1 or 10 or 34, it came up and I could continue on with the program. I don't understand why the letters aren't working. In the meantime, I'm going to use numbers until I can solve the AB issue.

                      Comment


                      • #12
                        And before anybody whines about it...

                        NO, this will NOT slow down your program. This is what the compiler does with all those multi-function statements anyway. So beat the rush.

                        Not to mention.. over the years I've had some funny things happen when using multi-function statements, which problems magically disappeared when I broke up the code into a series of "simpler" statements. (your compiler and version not shown).
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Just for style points...

                          Code:
                          SUB FetchComponentID
                             CLOSE #1
                          Until today I had never seen a procedure BEGIN with a CLOSE file.

                          "IMO*" files should be OPENed and CLOSEd - in that order - within the using procedure.

                          If the file is opened in a calling procedure, I'd pass the handle as a parameter to the called support procedures.


                          MCM
                          *
                          "IMO" ==> you may argue.
                          "IMNSHO" ===> you may not.
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            That file is used in an above routine. If I don't have that in there, then I get an error stating that the file is open. I have changed it to #2, #3 etc. throughout this sub with the same result.

                            On a earlier topic, when I tried the debugging steps Michael put in, a$ returns B, not AB.

                            Comment


                            • #15
                              Katherine,

                              I tried running your code
                              '
                              Code:
                              'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
                              #Compile Exe                                
                              #Dim All 
                              #Include "WIN32API.INC"
                              #Include "COMDLG32.INC"
                              Function PBMain
                                   Call FetchComponentID
                                  Local x&
                                  x = MsgBox ("Testing Katherine", %MB_YESNO, "Click Yes")
                              End Function
                              Sub FetchComponentID
                              Close #1
                              Local lRec$
                              Open "M:\Scanners\components.ini" For Input Lock Shared As #1
                              If Err Then
                              MsgBox Str$(Err)+" "+Error$+$Lf+"Openning M:\Scanners\components.ini"
                              Exit Sub
                              End If
                              If Lof(1)=0 Then
                              gAns&=EZ_MsgBox("SCAN","No Component Items Exist","Shop Floor Bill Of Material","OK")
                              SQL_ShutDown
                              EZ_UnLoadForm "SCAN"
                              End If
                              Do While Not Eof(1)
                              Line Input #1,lRec$
                              If Mid$(lRec$,1,3)="REM" Then Iterate Do
                              lRec$ = Remove$(lRec$, $Nul)
                              If UCase$(Trim$(Parse$(lRec$,"|",2)))=Mid$(EZ_GetText ("SCAN",%SCAN_ORDERNO),14,2) Then 'was 14,1
                              gItemNo$=UCase$(Trim$(Parse$(lRec$,"|",1)))
                              gIDError&=0
                              Close #1
                              Exit Sub
                              End If
                              Loop
                              gIDError&=1
                              Close #1
                              End Sub
                              '
                              but get an "undefined Equate" error for %SCAN_ORDERNO.

                              As Michael has suggested, the code would be much easier to understand/follow/debug if the multi-nested function lines(s) were broken down into single functions.

                              And when posting code (even snippets), it's much easier to read/follow for the rest of us if the code were enclosed in {code} ... {/code} brackets (using square brackets instead of curlies as shown here).

                              And you are posting EZ_Gui based code which won't run without Ex_Gui (and I tried, ... several times).


                              That file is used in an above routine. If I don't have that in there, then I get an error stating that the file is open. I have changed it to #2, #3 etc. throughout this sub with the same result.
                              To avoid that error use Freefile to get a file number. (Note it indicates an error somewhere else in the code, file getting left open or something)

                              I have this line of code:

                              MSGBOX UCASE$(TRIM$(PARSE$(lRec$,"|",2)))

                              and this is part of the file it's reading:

                              SANTOPRENCE GRIP|W
                              NATURAL CORK|X
                              RUBBER CORK COMPOUND|Y
                              PINS|Z
                              Test|AB

                              When I enter AB, only the A is read. How can I get AB to be read?
                              The first 4 lines only contain 1 character after "|", while "test" has 2. Maybe the string being processed (EZ_Gui Textbox?) is actually returning one character less than you expect. (Can't tell, no operable code shown).

                              ===================================
                              "Being politically correct means
                              always having to say you're sorry."
                              Anonymous
                              ===================================
                              Last edited by Gösta H. Lovgren-2; 8 Oct 2008, 10:13 PM.
                              It's a pretty day. I hope you enjoy it.

                              Gösta

                              JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                              LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                              Comment


                              • #16
                                Check that last line in the file end with CRLF

                                Comment


                                • #17
                                  Code:
                                  #TOOLS ON 
                                  
                                  FUNCTION WinMain 
                                     TRACE NEW   "tracefile.txt" 
                                     CALL main_thing
                                     TRACE CLOSE  
                                  
                                  SUB FetchComponentID
                                      TRACE ON 
                                  
                                  
                                      LINE INPUT #1,lRec$
                                      TRACE PRINT "Raw Lrec$ =" & lrec$
                                       
                                      .....
                                      a$ = PARSE$(lRec$,"|",2)
                                      a$ = UCASE$(TRIM$(a$))
                                      b$= EZ_GetText ("SCAN",%SCAN_ORDERNO)
                                      b$ = MID$(B$, 14,2) 
                                      TRACE PRINT USING$ ("A$ '&'   B$ '&'", A$, B$) 
                                      IF B$ = A$ THEN ....
                                         TRACE PRINT "Equals" 
                                  
                                      ELSE
                                         TRACE PRINT "Not equals" 
                                  
                                  
                                      TRACE OFF 
                                  END SUB
                                  Tune, tweak as required.

                                  Post relevant portions of tracefile.txt if problem does not leap off page at you.





                                  MCM
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    Here's a quick & dirty test of your problem as I understand it. I've tested 2 variations on the PARSE$ function and both of them work as advertised.

                                    Reviewing your code I found this line:

                                    Code:
                                    IF MID$(lRec$,1,3)="REM" THEN ITERATE DO
                                    This implies a more complex structure in your data file than indicated. My best guess is that your field delimiters are not consistent in the data file. As a solution, I suggest programatically checking for and inserting the necessary field delimiters before you do any processing of the individual records, including the exit sequence where I found this line of code.

                                    Or, even better, ensuring that your program accounts for all the necessary variations in the data file as well as the most common errors you are likely to encounter in the data file.

                                    Code:
                                    #COMPILE EXE
                                    #DIM ALL
                                    
                                    FUNCTION PBMAIN () AS LONG
                                        LOCAL tempString AS STRING
                                        LOCAL DataFile AS INTEGER
                                        LOCAL i AS LONG
                                        
                                        LOCAL lRec$     'your variable
                                        
                                        'build array with your data from original post
                                        DIM DataArray(1 TO 10) AS LOCAL STRING
                                        ARRAY ASSIGN DataArray() = "SANTOPRENCE GRIP", "W", "NATURAL CORK", "X", "RUBBER CORK COMPOUND", "Y", _
                                                                   "PINS", "Z", "Test", "AB"
                                        
                                        'make a file like your original post
                                        DataFile = FREEFILE
                                        OPEN "datafile" FOR OUTPUT AS #DataFile
                                        FOR i = 1 TO 10 STEP 2
                                            tempString = DataArray(i) & "|" & DataArray(i + 1)
                                            PRINT #DataFile, tempString
                                        NEXT i
                                        CLOSE #DataFile
                                        
                                        'display as from your original post
                                        DataFile = FREEFILE
                                        OPEN "datafile" FOR INPUT AS #DataFile
                                        FOR i = 1 TO 5
                                            LINE INPUT #DataFile, lRec$
                                            MSGBOX UCASE$(TRIM$(PARSE$(lRec$,"|",2)))   'your code line from original post
                                        NEXT i
                                        CLOSE #DataFile
                                        
                                        'add a delimiter to your input data and display
                                        DataFile = FREEFILE
                                        OPEN "datafile" FOR INPUT AS #DataFile
                                        FOR i = 1 TO 5
                                            LINE INPUT #DataFile, lRec$
                                            lRec$ = lRec$ & "|"         'add a delimiter to the end of your input data
                                            MSGBOX UCASE$(TRIM$(PARSE$(lRec$, "|", 2)))     'your code line from original post
                                        NEXT i
                                        CLOSE #DataFile
                                        
                                        MSGBOX "Basic Test is complete", %MB_TASKMODAL OR %MB_ICONINFORMATION
                                    END FUNCTION
                                    Stan
                                    Do not go quiet into that good night,
                                    ... Rage, rage against the dark.

                                    Comment


                                    • #19
                                      Or if you know it's the last entry:

                                      sTmp = Parse(St,"|",-1) that'll go backwards.

                                      Cheap but it works.
                                      Scott Turchin
                                      MCSE, MCP+I
                                      http://www.tngbbs.com
                                      ----------------------
                                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                                      Comment

                                      Working...
                                      X