Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the file exists, but it doesn't exist ?? 2

Status
Not open for further replies.

JoeyDC

Programmer
Mar 24, 2013
18
US
I found a demo online that I wanted to try. When I run the program, VFP throws up a dialog saying "The file does not exist." The offending line is the second line of this code:
If File("Customer.dbf")
Drop Table Customer
Endif

The file does exist. And if it didn't, why would the second line of code even be executed? What am I missing? I'm not sure you want details about what all I tried in order to get it to run like adding quotes, adding the extension, etc. No change I tried let it run.
 
There is no VFP error message that is worded "The file does not exist." Have you paraphrased?

Now, having said that, File() means a physical file exists. DROP TABLE erases a DBF that is contained in a DBC. The file can exist but not be contained in a DBC. The first test should be:

Code:
If File("customer.dbf") And Indbc("customer",'TABLE')

UNLESS....

If there's no DBC involved at all, then you shouldn't be using DROP TABLE. See ERASE or DELETE FILE in the help file.
 
Dan,

Thanks for responding. Yes, I paraphrased. The word The indeed does not appear at the beginning of the sentence, but unless you are looking the phrase up in some kind of table, which you obviously did, it shouldn't matter. The meaning is exactly the same.

However, I did find the problem. The composer of the demo program did not open the database. He just used the file which is in the database. When I opened the database and ran the program, it worked.

Thanks, again.
 
Hi Joey,

See, funny thing about VFP error messages is there are several that seem exactly the same but mean wildly different things. It kinda does matter. And no, I didn't have to look it up. I know that message well! [shadeshappy]

Glad you got it sorted!
 
>The composer of the demo program did not open the database. He just used the file which is in the database.
If you open (use) a DBF, which is part of a DBC, the database is opened automatically, too. It may just not get selected as in SET DATABASE TO...

Try it yourself:
Code:
Use (_samples+"Tastrade\data\customer.dbf")
? DBused("tastrade")
? indbc("customer","TABLE") && errors
set database to tastrade
? indbc("customer","TABLE") && .T.
Bye, Olaf.
 
Olaf,
I guess I don't understand the point you are trying to make. The code you presented works exactly as you state.
Code:
Use (_samples+"Tastrade\data\customer.dbf")
? DBused("tastrade")
? indbc("customer","TABLE") && errors
set database to tastrade
? indbc("customer","TABLE") && .T.

However, it doesn't help me understand. The programmer, in no place in his his code, ever wrote OPEN DATABASE data.dbc
. Therefore the DROP TABLE (in the snippet I presented) failed. When I inserted the OPEN DATABASE data.dbc prior to where the snippet appeared, all was well. As you pointed out, I replaced the OPEN DATABASE data.dbc with SET DATABASE TO data.dbc. That worked as well. So I suppose in this case, using SET DATABASE TO may be more proper than OPEN DATABASE?
 
So I suppose in this case, using SET DATABASE TO may be more proper than OPEN DATABASE?

No. It's not a question of SET DATABASE or OPEN DATABASE. You use OPEN DATABASE to open the database. If you have more than one database open, you can then use SET DATABASE to make one of them the current database. (Just as you USE a table, and then issue SELECT to make it current.)

Anyhow, I think the code Olaf showed you was just to illustrate how these commands work. The underlying point is this: your DROP command failed either because the database containing the table wasn't open, or the table wasn't part of the currently selected database.

I hope this makes sense.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Both DROP and INDBC work on the current database, and so it doesn't help to OPEN DATABASE alone. It's not the missing command. The developer of the demo may have written the code with the database being opened and current.

So what I wanted to illustrate is, that it does not only matter, if a database is open, but also, if it is the current database. Only then INDBC and DROP will work.

If you're neither in the directory of the DBF file nor the database is selected, the DROP TABLE fails.

The reason why OPEN DATABASE helped was, that if no database is open and you OPEN DATABASE some.dbc, this DBC is opened and selected as current database, both at the same timne. That's also the reason some people might not know the slight difference for years.

Bye, Olaf.
 
I'm about to decide that keeping this thread alive is a waste of your time and bandwidth.

Mike -- I now understand, after reading what Olaf said, the reason either command works in the demo and I mow fully understand your main point about which command is correct.

Olaf -- Your statement -- "The developer of the demo may have written the code with the database being opened and current." makes sense if by that you mean that on his development machine when he tested his code, that the database was previously opened via command window or other means before he ran the code, because it sure as heck wasn't opened in his code.

So, thanks for the lesson.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top