QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Dimster on July 08, 2021, 12:12:54 pm

Title: Use of the word "FILE"
Post by: Dimster on July 08, 2021, 12:12:54 pm
Often using key words as variables don't work well. I've been using FILE as in "For File = 1 to 50:Do Something:Next " and so far everything has been fine. Is FILE a key word?
Title: Re: Use of the word "FILE"
Post by: Cobalt on July 08, 2021, 12:34:13 pm
as long as you do not add a 's' to it your fine, as FILES is a keyword but not FILE.
Title: Re: Use of the word "FILE"
Post by: FellippeHeitor on July 08, 2021, 12:53:39 pm
And if it ever becomes a filet, then make sure to invite me. I'll bring a bottle of wine.
Title: Re: Use of the word "FILE"
Post by: Petr on July 08, 2021, 01:31:04 pm
Quote
And if it ever becomes a filet, then make sure to invite me. I'll bring a bottle of wine

:-)
Title: Re: Use of the word "FILE"
Post by: Dimster on July 08, 2021, 05:09:24 pm
You would all be invited. Thanks, I'll keep an eye on my S.
Title: Re: Use of the word "FILE"
Post by: Pete on July 08, 2021, 06:59:58 pm
Filet? I usually put a lot of stock in what Fell has to say, but this time he may be mis-steak-en.

Pete
Title: Re: Use of the word "FILE"
Post by: johnno56 on July 08, 2021, 08:56:14 pm
Dimster was trying to find out if a potential keyword could be used as a variable... and now you have all made me hungry! Well... there goes my schoolboy figure! I hope that you are all happy!

Dimster. Cobalt is correct. Ignore all the other guys... unless they are willing to share recipes.... lol
Title: Re: Use of the word "FILE"
Post by: Pete on July 09, 2021, 02:44:22 am
I don't want to tenderize it to death, but the meat-too movement will not be ignored!

Pete
Title: Re: Use of the word "FILE"
Post by: euklides on July 09, 2021, 03:57:58 am
use Y

for FILY=1 to ...
...
if ... then goto NEXTY
...
NEXTY: next FILY


Z is also usefull...



Title: Re: Use of the word "FILE"
Post by: xra7en on July 09, 2021, 08:22:20 am
Often using key words as variables don't work well. I've been using FILE as in "For File = 1 to 50:Do Something:Next " and so far everything has been fine. Is FILE a key word?

why not use "F" or name of file (or genre)
for f_database = bla bla

for db_file (reversing might be safer if you have to use "file")
for game_score_file =bla bla

Sometimes when using a var close to a keyword - on rare occasions it actually works but produces problems that are difficult to find because there is no error in the IDE.  This situation is not common, but why risk it - especially when your one character away FILE(S)

Code: QB64: [Select]
  1. For i = 1 To 10
  2.     files$ = "hello" <-- no error here but not what it is for LOL
  3.  


Title: Re: Use of the word "FILE"
Post by: Dimster on July 09, 2021, 08:28:54 am
I haven't tried this but I guess this holds true for all the Key words ..Printt, Forr, Nextt,  or Prints, Fors, Nexts even Too as a variable ...I like Loopy .. but as xra7en has just pointed out, the variable maybe too close to the key word.
Title: Re: Use of the word "FILE"
Post by: johnno56 on July 09, 2021, 07:00:07 pm
"Is 'file' a key word?"

No. If you want to use it as a variable, go for it...

The closest commands would be "FILES" (report a list of files in a directory) or _FILEEXISTS(filename$) (check if a file filename$ exists)

J
Title: Re: Use of the word "FILE"
Post by: Pete on July 09, 2021, 09:25:44 pm
I haven't tried this but I guess this holds true for all the Key words ..Printt, Forr, Nextt,  or Prints, Fors, Nexts even Too as a variable ...I like Loopy .. but as xra7en has just pointed out, the variable maybe too close to the key word.

One thing to consider in variable names in a large program is search-ability. opens is okay to use as a variable name, but when you search for OPEN to find file operation statements, you need to match case or search for the exact word, otherwise you end up finding all the opens variables, too.

For files, I use f1$, f2$, etc. or myfile$

Also, I think ending a string variable with an "s" looks a bit weird when followed by the dollar sign... opens$. Others may feel differently, but as we all know, my opinion is the only one that counts... in my opinion.

Pete