Page 1 of 2

OPEN command help

Posted: Wed Mar 03, 2004 4:57 am
by Guest
Hi. I tried using this code:

Code: Select all

INPUT "What program do you want to run"; dir$
OPEN dir$ FOR OUTPUT AS #1
And nothing opened. I've tried this before, with the same result. I have Windows XP. Is this why it's not working? Please e-mail me the response at bpeters@burntmail.com, because I won't check back here. Thanx.
Image
-----------------
Sometimes I question myself if I am sane.

Re: OPEN command help

Posted: Wed Mar 03, 2004 4:06 pm
by Artie
The simple answer is: you need to open dir$ for INPUT, not "output".
But, your input line implies that you're wanting to run an executable, in which case the line should look more like:

INPUT "What program do you want to run"; dir$
SHELL dir$

. . . or, you might have:

Code: Select all

INPUT "What file would you like to open"; file$
OPEN file$ for INPUT AS #1
  DO WHILE NOT EOF(1)
    INPUT #1, A$
  LOOP
CLOSE #1
. . . or something like that. ;)

Artie

Re: OPEN command help

Posted: Fri Mar 05, 2004 4:17 am
by Guest
One more thing: how do you create directories in Qbasic?

Re: OPEN command help

Posted: Fri Mar 05, 2004 3:26 pm
by Artie
Hi Brentis; if you mean a directory, as in a folder, you can do that a couple different ways also:

Lets say you want to make a folder called "programs" within the "C:\temp" folder.

MKDIR "C:\TEMP\PROGRAMS"

or

CHDIR "C:\TEMP"
MKDIR "PROGRAMS"

or

dir$ = "PROGRAMS"
path$ = "C:\TEMP"
MKDIR path$ + "\" + dir$

or

SHELL "MD C:\TEMP\PROGRAMS"

All those ways do the same thing.  But mainly, the command within QuickBASIC is:

MKDIR

Artie

BTW - Take note that if you "SHELL" out to DOS, you can shorten the command to "MD", but within BASIC, you must use the full command:  MKDIR

Re: OPEN command help

Posted: Sat Mar 06, 2004 7:04 am
by Guest
Thanx for your help.

Re: OPEN command help

Posted: Sat Mar 06, 2004 10:05 pm
by Guest
Just one more thing: I want to copy some files from a CD to the hard drive. Would I do something like this?

MKDIR "C:\QBASIC"
COPY "D:\program1.exe"

I don't even know if the copy command exists. Please reply to bpeters@burntmail.com, I won't check back here. Thanks. I'm really confused. How do you tell Qbasic where to copy it to???
Image

Re: OPEN command help

Posted: Sat Mar 06, 2004 10:52 pm
by Artie
Anytime you want to use simple DOS commands, its easier to just SHELL out to DOS.

MKDIR "C:\QBASIC"
SHELL "COPY D:\Program1.exe c:\Qbasic"

When you use SHELL, you just put between quotes, whatever you'ld type at the DOS command line.

BTW - When you make a post here, just put a check in the box below that says:

"Check this box if you wish to be notified of replies to this topic."  

Its all automatic,  or better yet, bookmark this thread. One click in your browser, and you're back here.  Its easier than opening email.  :)

Re: OPEN command help

Posted: Sun Mar 07, 2004 5:21 am
by Guest
Thanks SO much for the help. Hey, did I ever tell you that I'm just 11? Yup.
Image
bpeters@burntmail.com

Re: OPEN command help

Posted: Sun Mar 07, 2004 5:48 am
by Guest
Ok, i know i have no end to questions, but listen to this. Ok, I have this file C:\tacos.txt . i want to copy it to C:\enchilada , but the directory doesn't exist. so, i'd do this:

MKDIR "C:\enchilada"
SHELL "COPY C:\tacos.txt C:\enchilada"

right? it doesn't work. and then, would this work?

INPUT "What drive do you want to install to"; drive$
SHELL "COPY D:\nahco.exe drive$:\folder"

thanks once more

Re: OPEN command help

Posted: Sun Mar 07, 2004 5:26 pm
by Artie
You're making me hungry Brent.   ;D

Its good to see young folk getting in to programming.  A couple of my grandkids are almost your age.

Your first example should have worked.  Double check your spelling and puntuation, and try it again.  I loaded the code just as you have it and it worked. Make sure the file called "tacos.txt" exists in the "C:\" drive.

On your second example, you must separate literal strings from variables.  Like so:

INPUT "What drive do you want to install to"; drive$
SHELL "COPY D:\nahco.exe " + drive$ + ":\folder"

What I would do, is build the whole string first, then use it. Also, you may want to create a "default" value, in case the person enters nothing.

INPUT "What drive do you want to install to ";drive$
IF drive$ = "" THEN drive$ = "C"
mypath$ = "COPY D:\nacho.exe " + drive$ + ":\folder"
SHELL mypath$

(I assume you meant "nacho".)    ;)

Try that.  And keep checking back.  I'll be glad to help you as much as I can.

Artie

Re: OPEN command help

Posted: Thu Mar 11, 2004 4:00 am
by Guest
hi. ok i used this:

INPUT "What file do you want to copy"; filepath$
dir$ = filepath$ + " C:\DOS"
SHELL dir$

I DID NOT have a folder at C:\DOS. Should I have used MKDIR before? Ok, well, now to the facts. I copied the files ok, but when I looked at the folder, it was not a folder. it said it was a file. no extension. not .exe, .lnk, nothing. really weird.

Re: OPEN command help

Posted: Fri Mar 12, 2004 1:11 am
by frankiebaby
It is possible to have a file without an extension. If the file u specify does not exist, DOS will create it, so u told it to copy to that file. This also allows copy and rename in one.

By adding a '\' you will fix your problem. This is how u might try it:

INPUT "What file do you want to copy"; filepath$
dir$ = filepath$ + " C:\DOS\"
SHELL "copy" dir$

you can also copy and rename:
copy c:\one.txt  c:\one\two.txt

Re: OPEN command help

Posted: Sat Mar 13, 2004 8:30 pm
by Guest
ok, i've run into a problem. in my extraction program, it asks what drive they want to install to. then in one of the extracted files, it refers to another one of the extracted files. so, the point is: can you store information in a textfile (without opening it) and more importantly, 'import' the text into qbasic?
thanks.
------------------------------
Image

Re: OPEN command help

Posted: Sun Mar 14, 2004 1:03 pm
by yacinator
if u mean can u store information in a txt file (either making a new one or adding to and already existing 1 then u can. u do something like this :

open filespec.txt for append as 1
let a$="yacinator"
write# 1, a$
close# 1

now to import text u go like this :

open filespec.txt for input as 1
input# 1, var$
close#1
print var$

sometimes when the file is really long u might need to use more than 1 variable.

And brent i'm 13.

when u're finished with your program email it to me!

Re: OPEN command help

Posted: Mon Mar 15, 2004 1:25 am
by Guest
thanks for the help, but why should I e-mail it to you?
Image