OPEN command help

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Guest
OPEN command help

Post by Guest » Wed Mar 03, 2004 4:57 am

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.

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: OPEN command help

Post by Artie » Wed Mar 03, 2004 4:06 pm

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

Guest

Re: OPEN command help

Post by Guest » Fri Mar 05, 2004 4:17 am

One more thing: how do you create directories in Qbasic?

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: OPEN command help

Post by Artie » Fri Mar 05, 2004 3:26 pm

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

Guest

Re: OPEN command help

Post by Guest » Sat Mar 06, 2004 7:04 am

Thanx for your help.

Guest

Re: OPEN command help

Post by Guest » Sat Mar 06, 2004 10:05 pm

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

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: OPEN command help

Post by Artie » Sat Mar 06, 2004 10:52 pm

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.  :)

Guest

Re: OPEN command help

Post by Guest » Sun Mar 07, 2004 5:21 am

Thanks SO much for the help. Hey, did I ever tell you that I'm just 11? Yup.
Image
bpeters@burntmail.com

Guest

Re: OPEN command help

Post by Guest » Sun Mar 07, 2004 5:48 am

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

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: OPEN command help

Post by Artie » Sun Mar 07, 2004 5:26 pm

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

Guest

Re: OPEN command help

Post by Guest » Thu Mar 11, 2004 4:00 am

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.

User avatar
frankiebaby
Global Moderator
Posts:95
Joined:Tue Apr 30, 2002 1:38 am
Location:Pennsylvania
Contact:

Re: OPEN command help

Post by frankiebaby » Fri Mar 12, 2004 1:11 am

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

Guest

Re: OPEN command help

Post by Guest » Sat Mar 13, 2004 8:30 pm

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

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: OPEN command help

Post by yacinator » Sun Mar 14, 2004 1:03 pm

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!

Guest

Re: OPEN command help

Post by Guest » Mon Mar 15, 2004 1:25 am

thanks for the help, but why should I e-mail it to you?
Image

Post Reply