Qbasicnews.com
April 12, 2021, 06:25:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: File INPUT/OUTPUT  (Read 8036 times)
pr0gger
I hold this place together
*****
Posts: 775


« on: April 01, 2006, 11:38:12 PM »

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
Logged

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]
axipher
Ancient Guru
****
Posts: 544



« Reply #1 on: April 02, 2006, 01:06:13 AM »

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.
Logged
Pritchard
Wandering Guru
***
Posts: 328


« Reply #2 on: April 02, 2006, 01:37:08 AM »

You can only use one freefile per open, right? ^_^;; Is that what it was?
Logged

 will Live Forever, or Die Trying >_<;;
wallace
Wandering Guru
***
Posts: 368



WWW
« Reply #3 on: April 02, 2006, 01:51:29 PM »

Quote from: "Pritchard"
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.
Logged

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.
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #4 on: April 02, 2006, 02:36:43 PM »

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.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #5 on: April 02, 2006, 03:04:28 PM »

That's why FREEFILE whores should be rounded up and shot.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #6 on: April 02, 2006, 03:37:27 PM »

Hey, what prompted that? Freefile is a must if you want to write reusable code.  There's absolutely nothing wrong with using it.
Logged
pr0gger
I hold this place together
*****
Posts: 775


« Reply #7 on: April 03, 2006, 04:11:37 PM »

Wow, I'm an idiot.  Thanks for that.

(hides from Zack's firing squad)

--j_k
Logged

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]
NecrosIhsan
Been there, done that
*****
Posts: 1191



« Reply #8 on: April 03, 2006, 06:41:01 PM »

Quote from: "Zack"
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:
Logged

\__/)
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #9 on: April 03, 2006, 09:24:17 PM »

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
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Anonymous
Guest
« Reply #10 on: April 03, 2006, 11:07:18 PM »

Use FREEFILE. Always.
Logged
Pritchard
Wandering Guru
***
Posts: 328


« Reply #11 on: April 04, 2006, 05:22:14 AM »

Quote from: "cha0s"
Use FREEFILE. Always.
Uh oh! *runs* Should I start using it too?

I mean I know how hard it is to edit a line of code for opening the .bmp (Why they would want to change anything I do not know)
Logged

 will Live Forever, or Die Trying >_<;;
Anonymous
Guest
« Reply #12 on: April 04, 2006, 01:38:19 PM »

what if you distribute a binary? gonna just "edit that out" :|
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #13 on: April 04, 2006, 01:53:59 PM »

Then file numbers shouldn't be a problem. FREEFILE is a tool of portability, for open-source.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
axipher
Ancient Guru
****
Posts: 544



« Reply #14 on: April 04, 2006, 03:03:07 PM »

If you don't want freefile then number each file from #1 and up for your program, then but another number in front of that one so you would end up with 11,12,13 or 421,422,423 etc.
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!