Help with CASE Statement

 BBS: Inland Empire Archive
Date: 05-13-92 (14:47)             Number: 134
From: TOM HAMMOND                  Refer#: NONE
  To: ZACK JONES                    Recvd: NO  
Subj: Help with CASE Statement       Conf: (2) Quik_Bas
ZJ>What I need to know is how to change the second Select Case so that it
ZJ>works like the first one.  All help is greatly appreciated.

Zack:

From my (limited) knowledge of the CASE statement (I use it all the
time, I just don't know all the INs and OUTs of it!), It would appear
that CASE permits you to ONLY make comparisons where the operator is an
OR (rather than an AND as you are trying to do is your second example).

The CASE statement in your second example:

  CASE IS <> "Telix Usag", "++ Setting", "Exiting Te", "++ Chars p"

_really_ wants to ask:

  CASE IS <> "Telix Usag", AND <> "++ Setting", AND <> "Exiting Te",_
    AND <> "++ Chars p"

Unfortunately, CASE cannot handle such a construct (however, there may
be another way that I'm not aware of).

I'm not quite sure exactly what the CASE statement in your 2nd example
actually translates to (in QB), but I'm pretty sure it's not what you
want.

My simplistic solution is to your problem is the following:

DEFINT A-Z
  OPEN "telix.use" FOR INPUT AS #1
  OPEN "out1.put" FOR OUTPUT AS #2
  DO UNTIL EOF(1)
  LINE INPUT #1, rec$
  SELECT CASE MID$(rec$, 21, 10)
    CASE "Telix Usag", "++ Setting", "Exiting Te", "++ Chars p"
      'DO Nothing further with this record, we don't want it!
      'Fall thru to next LOOP
    CASE "Elapsed ti"
      IF RIGHT$(rec$, 8) <> "00:00:00" THEN
        PRINT #2, rec$ + CHR$(13)
        LinesWritten% = LinesWritten% + 1
      ENDIF
    CASE ELSE
      PRINT #2, rec$
      LinesWritten% = LinesWritten% + 1
  END SELECT
  LOOP
  CLOSE

1)  Unless you are planning to do something further with test$, you
    don't really need to assign it.  SELECT CASE MID$(rec$, 21, 10)
    works just as well.

2)  Use CASE to test for the presence of the records you don't want
    to keep and then just do NOTHING with them.  This will allow your
    execution to fall thru to the following LOOP.  If a record turns
    out to be one which you DO wish to retain, it will fall thru to the
    next CASE statement(s).

3)  In both of your examples (#1 and #2):

      CASE "Elapsed ti"
        IF RIGHT$(rec$, 8) <> "00:00:00" THEN PRINT #2, rec$ + CHR$(13)
        LinesWritten% = LinesWritten% + 1

    will increment LinesWritten% REGARDLESS of whether rec$ is written
    to disk!  I don't think this is actually what you intended to occur.
    I 'think' you intended that LinesWritten% be incremented ONLY when a
    line was actually written out, therefore, you'll need to include the

        LinesWritten% = LinesWritten% + 1

    line INSIDE your IF THEN clause, so it executes ONLY when the result
    is TRUE:

        CASE "Elapsed ti"
          IF RIGHT$(rec$, 8) <> "00:00:00" THEN
            PRINT #2, rec$ + CHR$(13)
            LinesWritten% = LinesWritten% + 1
          ENDIF

I can't see much benefit of example #2 over example #1, unless you have
FEWER lines you wish to OMIT than those you wish to KEEP.  The logic is
a bit more obscure in example #2.

I suspect you'll get a bunch of other suggestions, and that many will
be more elegant than this one.  Pick one you like!!!

Finally, the out.put file appears to contain one record which you did
not mark with an asterisk, however it appears that the record SHOULD
have been marked and was just inadvertently missed.  This was the
"Upload using Zmodem protocol" line.  It is specifically spoken to in
your example #1 as being one to retain, but it was not marked in the
file.

Good Luck

Tom Hammond        N0SS
 þ SLMR 2.1 þ If this were an actual tagline, it would be funny.


--- WM v2.00/91-0231
 * Origin: The Modem Zone BBS (314) 893-5106 (1:289/2)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET