Need help with openin a file on the interwebs
Need help with openin a file on the interwebs
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?)
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?)
-
- Veteran
- Posts: 109
- Joined: Thu Feb 10, 2005 12:38 pm
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.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?
My site = animaproductions.us.tf
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! Please help!
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! Please help!
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?
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"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?
My site = animaproductions.us.tf
An OPEN FOR APPEND is very similar to an OPEN FOR OUTPUT.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 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.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
Kindly expain yourself more clearly and precisely.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.
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
You might already know all this, but perhaps an example might help you.
*****
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!!
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.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!!
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.
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