Need help with openin a file on the interwebs

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Need help with openin a file on the interwebs

Post by plad6111 »

I realy need help! How do you change the path on a file open? I am writing a very basic IM program, but I need the program to look in a folder on a website, but I can't change the path. This is what I tried, but it didn't work:

open "C:\docume~!\bob\desktop\file\bla.txt" for append as #1
write #1, text$
close #1

please help me! (and how do I make the path look at a web address?)
RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton »

as far as i know, qb can't use the internet, or networks unless in pure dos
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

Well, in the help topic, it says you can, just not how to.
User avatar
Anima
Coder
Posts: 31
Joined: Tue Aug 23, 2005 7:25 pm
Location: Fort Wayne, IN
Contact:

Post by Anima »

Isn't there a command like GETURL or somethin like that? :?
My site = animaproductions.us.tf
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

there isn't on my version of qb, but I have a very old version, so they may have updated it. What I was wondering is how do you change the file path on an open statment?
User avatar
Anima
Coder
Posts: 31
Joined: Tue Aug 23, 2005 7:25 pm
Location: Fort Wayne, IN
Contact:

Post by Anima »

plad6111 wrote:there isn't on my version of qb, but I have a very old version, so they may have updated it. What I was wondering is how do you change the file path on an open statment?
Um... if you mean changing the path while it's running, you CAN set a string variable for the path and have an input command in so that you can change it. If that's what you mean.
My site = animaproductions.us.tf
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

Oh yeah, and how do you make it so that if I have a file that sais:

do:
open "bla.txt" for append as #1
write #1, text$
close #1

open "bla.txt" for input as #1
input $1, text2$
close #1
print text2$
loop

The only thing that appears on the screen is the first entry in the bla.txt, but since I said to append every input to the file, I wan't to get the second, third, fourth and so on entry in the file. How do I do that?
I have been trying to figure it out, but I can't! :x Please help!
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

No, I mean, if I have a file that I wan't to open, and it is in a place where the program isn't, how do I make the program look in the file that the .txt document is in.

For example: if the program is sitting on my desktop, and the .txt file that I wan't to open is in a file in my documents. How do I make it look in there for the first file, and on the desktop for the second file?
User avatar
Anima
Coder
Posts: 31
Joined: Tue Aug 23, 2005 7:25 pm
Location: Fort Wayne, IN
Contact:

Post by Anima »

plad6111 wrote:No, I mean, if I have a file that I wan't to open, and it is in a place where the program isn't, how do I make the program look in the file that the .txt document is in.

For example: if the program is sitting on my desktop, and the .txt file that I wan't to open is in a file in my documents. How do I make it look in there for the first file, and on the desktop for the second file?
Well it should work when your typing in the path. But the example program you put up there, all you have to do is type the full path of the file AND the file at the end, like, if I had something call file.txt in C:\txt, I would say "C:\txt\file.txt"
My site = animaproductions.us.tf
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

but when i try it in qb it doesn't work, I don't know why!
User avatar
Anima
Coder
Posts: 31
Joined: Tue Aug 23, 2005 7:25 pm
Location: Fort Wayne, IN
Contact:

Post by Anima »

plad6111 wrote:but when i try it in qb it doesn't work, I don't know why!
Maybe the path is wrong, maybe you should try going to my computer and check the path

other than that, I dunno what's wrong.
My site = animaproductions.us.tf
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

thanks, I figured it out. Another thing I was wondering was how do I make an open for append statment and then make an input statment that will take everything from the file that I said to append?
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

plad6111 wrote:......how do I make an open for append statment and then make an input statment that will take everything from the file that I said to append?
An OPEN FOR APPEND is very similar to an OPEN FOR OUTPUT.
An OPEN FOR OUTPUT creates a new file. If you write 10 records to it, you will have 10 records on the file.

An OPEN FOR APPEND works as follows:
If the file does not already exist, then it works exactly the same as the OPEN FOR OUTPUT. However, if the file does exist, and let's say it already has 6 records on it, then it positions AFTER the 6th record so that the next write or print to the file will become the 7th record, and subsequent writes or prints to the file will become the 8th record and so on.

In order to read everything, or "take everything" as you say, from the previously appended file, you have to CLOSE it first. Then, if you're still in the same program, you can open that file FOR INPUT, and read from it from the beginning of the file.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

Thanks, but I already knew all of that. What I wan't to know is, after you say open for input, I say input as #1, so that only takes the first file, and since it is in a do/loop I can't make it say anything else. Please help.
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

Hello?
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

plad6111 wrote:Hello?
This is a forum, not a chat.
I have left this dump.
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

plad6111 wrote:Thanks, but I already knew all of that. What I wan't to know is, after you say open for input, I say input as #1, so that only takes the first file, and since it is in a do/loop I can't make it say anything else. Please help.
Kindly expain yourself more clearly and precisely.

You said:" after you say open for input, I say input as #1, so that only takes the first file".
What do you mean by "takes the first file"?

The you said: "and since it is in a do/loop I can't make it say anything else."
What do you mean by "say anything rlse"?

Assuming that you wrote records of string data to the file, the normal procedure for reading records from the file is as follows:

Code: Select all

open "thefile" for input as #1
do while not eof(1)
     line input #1, recdata$   'recdata$ will contain the data from each record.
     gosub processdata
loop
system

processdata:
    ' Your logic for processing each and every record on the file.
return
The LINE INPUT # statement above is the recommended method of reading an entire record of string data from a file, because it reads the entire record regardless of blanks, commas or other punctuation, which do affect the INPUT # statement.

You might already know all this, but perhaps an example might help you.
*****
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

Okay, what I wan't to happen is:

1. I wan't to write several lines of text into an input statment

2. I wan't to open those lines of text from the file later in the program.

My problem: when I say open for append, the files get writen at the end of the file, just like i wan't them to, but then, when I try to use the open for input statment later, it doesn't work because it only takes the first line of text from the file.
That is the best I can explain it and I think that is dang clear!!
RyanKelly
Coder
Posts: 48
Joined: Sun Jan 22, 2006 6:40 pm
Contact:

Post by RyanKelly »

plad6111 wrote:Okay, what I wan't to happen is:

1. I wan't to write several lines of text into an input statment

2. I wan't to open those lines of text from the file later in the program.

My problem: when I say open for append, the files get writen at the end of the file, just like i wan't them to, but then, when I try to use the open for input statment later, it doesn't work because it only takes the first line of text from the file.
That is the best I can explain it and I think that is dang clear!!
I'm sorry. It is not clear at all. We could help you out if you would post a short code sample demonstating how you are attempting to output to the file and how you are attempting to input from the file. As it stands, you don't seem to be familiar enough with programming in general to describe your problem.

However, I think I may have an idea about what is confusing you. Whenever you open a file for input, the file position is set to the beginning of the file. When you use the input statement to read from the file, the file position is updated, and the next input statement will read from that position. This will continue until you reach the end of the file, at which point any attempt to input from the file will throw an error. BUT... if you close the file and reopen it, the file position will be set back to the begining of the file, and I suspect this is what you are doing inside your loop, but I can't know for sure unless you post an example of exactly what lines of code you are having trouble with.
plad6111
Coder
Posts: 13
Joined: Wed Jul 12, 2006 3:28 pm

Post by plad6111 »

Thanks, that is my problem. I closed the file because the program says I have to. Here is an example, see what you can do with it:

Code: Select all

'main loop:

IF a = 2 THEN
INPUT "Input your text: ", text$

OPEN "talk.txt" FOR APPEND AS #1
WRITE #1, text$
CLOSE #1
CLS

DO UNTIL text$ = "q":


mcy:
IF v = 1 THEN
OPEN "C:\Docume~1\Matt\zero\mine\talk1.txt" FOR INPUT AS #1
INPUT #1, othertext$
CLOSE #1
IF othertext$ = "" THEN
v = 2
END IF


LOCATE g, 1
PRINT username$; ": "; text$
PLAY m$
g = g + 1

IF v = 1 THEN
LOCATE g, 1
PRINT friend$; ": "; othertext$
PLAY m$
g = g + 1
END IF
END IF

LOCATE 1, 1
INPUT "", text$

OPEN "talk.txt" FOR APPEND AS #1
WRITE #1, text$
CLOSE #1
LOCATE 1, 1
PRINT "                                                                                              "

IF text$ = "king" THEN GOTO king

v = 1
LOOP
END IF
END
Post Reply