Qbasicnews.com

Full Version: File INPUT/OUTPUT
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Not sure what's wrong with this code. It's supposed to take all the JPGs in a folder and make a hyperlinked list on a webpage, but when I try to run it a get an error in MSVCRT.dll.

Also, this line:

Code:
LINE INPUT #tempfilehandle, filename

Doesn't seem to be doing anything-- as in, the string "filename" is always empty.

Maybe the two problems are linked? Seems like this should have been easy to hunt down, but nothing I do will fix it.

Here's the full code:

Code:
OPTION EXPLICIT

DIM htmlfile AS STRING
DIM title AS STRING
DIM filename AS STRING
DIM htmlfilehandle AS INTEGER, tempfilehandle AS INTEGER

SCREEN 0

INPUT "Output HTML file? ", htmlfile
INPUT "HTML page title? ", title
IF title = "" THEN title = "Photos"
IF htmlfile = "" THEN
    htmlfile = "PHOTOS.HTML"
ELSEIF INSTR(htmlfile, ".") = 0 THEN
    htmlfile = htmlfile + ".HTML"
END IF

PRINT ""
PRINT "Generating file list... ";
SHELL "DIR *.JPG /b > temp.dat"
PRINT "done"
PRINT ""
PRINT "Creating webpage " + UCASE$(htmlfile) + "... ";

htmlfilehandle = FREEFILE
tempfilehandle = FREEFILE

OPEN htmlfile FOR OUTPUT as htmlfilehandle
OPEN "temp.dat" FOR INPUT as tempfilehandle

PRINT #htmlfilehandle, "<html>"
PRINT #htmlfilehandle, "<head><title>" + title + "</title></head>"
PRINT #htmlfilehandle, "</body>"

DO UNTIL EOF(tempfilehandle)
    LINE INPUT #tempfilehandle, filename
    PRINT #htmlfilehandle, "<a href=" + filename + ">" + filename + "</a><br>"
LOOP

CLOSE #tempfilehandle
PRINT #htmlfilehandle, "</body>"
PRINT #htmlfilehandle, "</html>"

CLOSE #htmlfilehandle
KILL "temp.dat"
PRINT "done"

END

--j_k
Well fpor starters:
Code:
htmlfilehandle = FREEFILE
tempfilehandle = FREEFILE

OPEN htmlfile FOR OUTPUT as htmlfilehandle
OPEN "temp.dat" FOR INPUT as tempfilehandle
should be:
Code:
htmlfilehandle = FREEFILE
OPEN htmlfile FOR OUTPUT as htmlfilehandle

tempfilehandle = FREEFILE
OPEN "temp.dat" FOR INPUT as tempfilehandle

Try that, it's a comon mistake, I once did it and was stuck for minutes umtil I posted my code here.
You can only use one freefile per open, right? ^_^;; Is that what it was?
Quote:You can only use one freefile per open, right? ^_^;; Is that what it was?

FREEFILE would point to the same place both times since he never changed any IO settings.

Say #1 is free the first one will return #1, then FREEFILE is called again. Nothing has changed so once again #1 is returned so you end you OPENing #1 twice.
Exactly. Freefile returns the lowest free file descriptor ID. If you don't open a file after an a% = Freefile, that file descriptor returned by the function will be the same one.
That's why FREEFILE whores should be rounded up and shot.
Hey, what prompted that? Freefile is a must if you want to write reusable code. There's absolutely nothing wrong with using it.
Wow, I'm an idiot. Thanks for that.

(hides from Zack's firing squad)

--j_k
Quote:That's why FREEFILE whores should be rounded up and shot.
No, that's why people who misuse FREEFILE should be rounded up and stabbed with pencils before being locked in a room where they have Suzanne Vega records played at them 24/7 until they get a clue.

:rotfl: :rotfl: :rotfl: :rotfl: :rotfl: :rotfl:
I said FREEFILE whores, not FREEFILE users.

Quote:Poster #1: Hello, what's wrong with this code it crashes on line 15 [posts nice, neat code with comments and a small problem].
Poster #2: first of all USE FREEFILE JERK WHAT IF SOMEONE WANTED PORTABILITY IN YOUR CODE ANUSHEAD THEY'D HAVE TO EDIT THREE LINES #$@# YOU AND OPEN #1 USE FREEFILE!!!!!11
Pages: 1 2 3