Poll: How do you plan on getting to heaven?
You do not have permission to vote in this poll.
Via good works.
100.00%
8 100.00%
I don\'t plan on it at all (going to heaven).
0%
0 0%
Accepting Jesus as personal savior.
0%
0 0%
If your answer is not here email me at terrythebest2001@yahoo.com
0%
0 0%
Total 8 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving some data.
#1
I was working through my program involving a survey, and I was wondering if there was a way to save the data via a seperate file, so that I could chain the program to another program, and have variables still represent the same values.
For example;
If answer$ = "a" then
a=a+1
goto 1 'or wherever you wanna go
end if
if answer$ = "b" then
b=b+1
goto 2 'or wherever again
end if

And what I want to do is take these two variables, a and b, and keep there values so that I can look at them later without manually having to write them down or anything like that. Could someone please give me the formula to use the variables from this program and save them via a document file or something, but also so that I can reach the values of the variables from other files. :o
S VERDAD?!
Reply
#2
Code:
INPUT "What's your answer? "; answer$
IF answer$ <> "" THEN
  OPEN "answers.txt" FOR OUTPUT AS #1
  PRINT #1, answer$
  CLOSE #1
END IF

To get the answer back in QB:

Code:
OPEN "answers.txt" FOR INPUT AS #1
INPUT #1, answer$
PRINT "Your answer was "; answer$; "."

That's pretty general stuff. You can add more "PRINT #1, variable" statements to the first block of code to store more variables, and for the second part you just add more "INPUT #1, variable" statements to get the data back. Even better, if you have lots of data, is to use an array and a FOR/NEXT loop to store/retrieve the data.
Reply
#3
You can pass variables from one program to another though a COMMON statement, and calling the second program with CHAIN.
If you plan an compliing the programs, they both need to be compiled to use the same run time module.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#4
Uhhh...
* Asks the obvious question *
Reply
#5
Quote:Uhhh...
* Asks the obvious question *

wtf is CHAIN? :lol:

I think that saving in an external file is better, so that any program can access the data at any time later, and you can open the file and read the data yourself. Is CHAIN faster though?
Reply
#6
Am I using 7.1 commands again? If so I'm sorry. I only have 7.1, and don't know which commands are specific to it. This is what the help file says:
Code:
CHAIN transfers control from the current program to another program.

CHAIN filespec$
    Ã¾ The argument filespec$ is a string expression; can include a path
      specification. (With DOS 2.1 or earlier versions, you cannot use
      CHAIN unless filespec$ provides a complete path, including drive.)
    Ã¾ Programs running within the QBX environment assume a .BAS extension
      (if no extension is given) and cannot chain to executable files
      (files with a .COM or .EXE extension).
    Ã¾ Programs running outside the QBX environment assume an .EXE
      extension and cannot chain to BASIC source files (files with a .BAS
      extension).
I don't know if it is faster or not. You don't have to write an output file or read an input file, so I think it should be (though probably not enough to be able to tell the difference). As you mentioned, Oracle, you won't have the file around to read later. If you need to save the data a file would be better.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#7
Quote:I was working through my program involving a survey, and I was wondering if there was a way to save the data via a seperate file, so that I could chain the program to another program, and have variables still represent the same values.
For example;
If answer$ = "a" then
a=a+1
goto 1 'or wherever you wanna go
end if
if answer$ = "b" then
b=b+1
goto 2 'or wherever again
end if

And what I want to do is take these two variables, a and b, and keep there values so that I can look at them later without manually having to write them down or anything like that. Could someone please give me the formula to use the variables from this program and save them via a document file or something, but also so that I can reach the values of the variables from other files. :o

COMMON statement in conjunction with the CHAIN statement... However, I've learned from experience, and extensively studying the Help files, that this won't work for Stand-alone EXEs... Ever. Sorry. Use modules. Seems to work fine for me.
earn.
Reply
#8
So wait a minute, wait... are you saying if I use QB 7.1 instead of 4.5 then I could just CHAIN together several programs to make them all work? Or am I just a newbie with grand thoughts?

(my project is too long and wont compile)
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#9
Program too long -> modulise it for the last time already! Wink
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)