Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to create a file whose name is determined by operator
#1


I am trying to modify an existing application.
Currently, the application prompts the user to open a file (Open "c:\CMM\Compaction\Data\Compaction.txt" For Append As #1) and append it with the latest data from a measurement. I want to prompt the user to enter a device ID and then use that ID as the name for a new file, in which to store the data for that device) Can anyone help?
Reply
#2
Perhaps use INPUT?

Code:
INPUT "Enter a filename:"; filename$
OPEN filename$ FOR APPEND AS #1
...
Reply
#3
Quote:

I am trying to modify an existing application.
Currently, the application prompts the user to open a file (Open "c:\CMM\Compaction\Data\Compaction.txt" For Append As #1) and append it with the latest data from a measurement. I want to prompt the user to enter a device ID and then use that ID as the name for a new file, in which to store the data for that device) Can anyone help?

If you want to create a new file each time you could do DrV's method but with "Output" rather than "Append"

Something like this:

[syntax="qbasic"]
INPUT "Enter the Device ID"; devid$
OPEN devid$ FOR OUTPUT AS #1
'add your junk to the file here
CLOSE #1
[/syntax]
url=http://fileanchor.com]FileAnchor[/url] - ImageAnchor - FBTK - QbasicNews - VPlanet - Various
Reply
#4
When your program inputs the "device ID", as you call it, you are going to have to validate it as follows:

- The drive, like C:, must be a valid drive for the machine that the program is running on.

- Assuming your program is going to run under MSDOS, each pathname and the filename must conform to the 8.3 standard, that is, the name cannot exceed 8 characters and the file extension cannot exceed 3 characters.

- The syntax of the entire drive:\path\filename must be validated.

- The characters in the pathnames and filename must be validated.

Why do all this validatation?
If the drive:\path\filename input by the user is invalid,
then the OPEN will issue an error and crash the program.

In order to avoid the tedious validation, you could:
1) Use ON ERROR, which creates other problems.
2) Do a few SHELL commands to do a test of the drive:\path\filename.

Let me know what you decide to do, and I'll help you.
*****
Reply
#5
The best way to check if file exists and avaluable is:
Code:
function isExist(Filename$)
     onlocal error goto isExistErr
          open  filename$ for input as #1
          close 1
          isExist=not(0)
          exit function
     isExistErr:
          isExist=0
          resume next
end function
Works in PDS and VBD
url=http://zerodivide.h15.ru/cyclone.html]Cyclone v2.5.2 GUI For QBasic 4.5/7.1[/url]
Explorer For DOS
Reply
#6
Quote:The best way to check if file exists and avaluable is:
Code:
function isExist(Filename$)
     onlocal error goto isExistErr
          open  filename$ for input as #1
          close 1
          isExist=not(0)
          exit function
     isExistErr:
          isExist=0
          resume next
end function
Works in PDS and VBD
Yes, that's fine if the Filename$ is a valid Windows or DOS filename. Remember that the original post said that the filename, or device ID as he called it, is to be entered by an operator.

If the operator enters an invalid filename, your function will consider it as "does not exist", which is not the same as invalid.
Get what I mean?
*****
Reply
#7
how about this then ;P
Code:
function isExist(Filename$)
     onlocal error goto isExistErr
          open  filename$ for output as #1
          close 1
          isExist=not(0)
          exit function
     isExistErr:
          isExist=0
          resume next
end function
Big Grin
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#8
Quote:how about this then ;P
Code:
function isExist(Filename$)
     onlocal error goto isExistErr
          open  filename$ for output as #1
          close 1
          isExist=not(0)
          exit function
     isExistErr:
          isExist=0
          resume next
end function
Big Grin
If the filename$ is invalid, you're gonna get a corresponding error code whether you open for input or output.

The function is set up to find out if it exists or not, not if it is invalid. Perhaps you could add some code to look at the error code and return an addition valid/invalid parameter for the function.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)