Issue with Print #, Using when terminating with a semicolon.

New to FreeBASIC? Post your questions here.
tauman
Posts: 2
Joined: May 25, 2006 5:47
Location: San Antonio TX

Issue with Print #, Using when terminating with a semicolon.

Postby tauman » May 25, 2006 23:37

I am a new FB user and I came across an issue when treying to compile a QB program I have been using. The program has several processes involved but the FBC gives an error 34 Expected 'END IF'

My program reads a file and reformats the data.
The reformated data is then processed to build datbase records.
The records are then sorted.
After the sort the records are compiled by a control field and formatted
This is where I run into the problem.

my basic code for the section gererating the error is as follows:

Code: Select all

tYPE MYREC
.
.
.
END TYPE

OPEN INFILE.DAT FOR RANDOM AS #1
OPEN OUTFILE.TXT FOR OUTPUT AS #2
RECNO = 0
DO WHILE NOT EOF(1)
      RECNO = RECNO + 1
      GET #1, RECNO, MYREC
      IF RECNO = 1 THEN
           CONTROL = MYREC.FIELD
           .    PERFORM THIS SERIES OF COMMANDS
           .    TO SETUP FIRST COMPILED RECORD
      ELSEIF CONTROL = MYREC.FIELD
           . PERFORM CALCULATIONS ON RECORD FIELDS
      ELSE
           . PERFORM FINAL CALCULATIONS
           . ON THE DATA AND STORE THE RECORD.
           . THIS IS WHERE THE PROBLEM IS
           .
           PRINT #2, Q$ SORTCH$ C$ CALFIG$ C$;
           .
           . SEVERAL MORE STATEMENTS
           .
      ENDIF
      PRINT "PROCESSING FILE RECORD: "; RECNO
LOOP


While I am not showing all my code the problem occurs when the print #2 is encountered in the ELSE of the IF - ENDIF loop. Is it due to the termination of the Print line with the semicolon? I need to terminate the PRINT # statement with the semicolon so I can add the rest of the formatted output. There are a 14 PRINT # statements to format the output of the record as I need it.

I think I may be able to place the PRINT commands into a GOSUB and get it to work but can not figure out why the PRINT # will not work inside of the IF - END IF statement.
VirusScanner
Posts: 775
Joined: Jul 01, 2005 18:45

Postby VirusScanner » May 26, 2006 0:14

Try
PRINT #2, Q$; SORTCH$; C$; CALFIG$; C$;
You need semicolons after each variable, or if you want spaces in between them (keep in mind it's much more than one), use ',' (comma).
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » May 26, 2006 0:36

QB will allow you to separate the printed items in a print statement with spaces or tabs, but IMO this was just another one of QB’s warts, and a feature that I think few programmers used.
tauman
Posts: 2
Joined: May 25, 2006 5:47
Location: San Antonio TX

Postby tauman » May 26, 2006 1:09

Thanks for the input,

Your right I was not even thinking.... This program was a quick one after about 6 years of not writing any and I just used a sample to check my format instead of really looking at the Command structure.

It was because it worked that I did not even think of the need to include the additional semicolons.

Thanks again and it is nice to be programming again with a language I have been using in various forms for over 20 years.
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » May 26, 2006 3:52

tauman wrote:Thanks again and it is nice to be programming again with a language I have been using in various forms for over 20 years.


yeah, and now its on steroids =)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 5 guests