Page 1 of 1

Need help with openin a file on the interwebs

Posted: Wed Jul 12, 2006 3:32 pm
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?)

Posted: Wed Jul 12, 2006 5:12 pm
by RayBritton
as far as i know, qb can't use the internet, or networks unless in pure dos

Posted: Wed Jul 12, 2006 6:02 pm
by plad6111
Well, in the help topic, it says you can, just not how to.

Posted: Wed Jul 12, 2006 6:13 pm
by Anima
Isn't there a command like GETURL or somethin like that? :?

Posted: Wed Jul 12, 2006 6:49 pm
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?

Posted: Wed Jul 12, 2006 7:01 pm
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.

Posted: Wed Jul 12, 2006 7:01 pm
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!

Posted: Wed Jul 12, 2006 7:03 pm
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?

Posted: Wed Jul 12, 2006 8:08 pm
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"

Posted: Wed Jul 12, 2006 8:16 pm
by plad6111
but when i try it in qb it doesn't work, I don't know why!

Posted: Wed Jul 12, 2006 9:34 pm
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.

Posted: Thu Jul 13, 2006 9:21 am
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?

Posted: Thu Jul 13, 2006 6:27 pm
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.
*****

Posted: Thu Jul 13, 2006 6:59 pm
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.

Posted: Fri Jul 14, 2006 9:34 am
by plad6111
Hello?

Posted: Fri Jul 14, 2006 4:38 pm
by Z!re
plad6111 wrote:Hello?
This is a forum, not a chat.

Posted: Fri Jul 14, 2006 7:31 pm
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.
*****

Posted: Mon Jul 17, 2006 3:34 pm
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!!

Posted: Mon Jul 17, 2006 11:05 pm
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.

Posted: Tue Jul 18, 2006 7:30 pm
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