Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File INPUT/OUTPUT
#1
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
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#2
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.
Reply
#3
You can only use one freefile per open, right? ^_^;; Is that what it was?
will Live Forever, or Die Trying >_<;;
Reply
#4
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.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#5
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.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#6
That's why FREEFILE whores should be rounded up and shot.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#7
Hey, what prompted that? Freefile is a must if you want to write reusable code. There's absolutely nothing wrong with using it.
Reply
#8
Wow, I'm an idiot. Thanks for that.

(hides from Zack's firing squad)

--j_k
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#9
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:
\__/)
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.
Reply
#10
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
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)