Author Topic: Use of the word "FILE"  (Read 4063 times)

0 Members and 1 Guest are viewing this topic.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Use of the word "FILE"
« 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?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Use of the word "FILE"
« Reply #1 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.
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Use of the word "FILE"
« Reply #2 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.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Use of the word "FILE"
« Reply #3 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

:-)

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Use of the word "FILE"
« Reply #4 on: July 08, 2021, 05:09:24 pm »
You would all be invited. Thanks, I'll keep an eye on my S.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Use of the word "FILE"
« Reply #5 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Use of the word "FILE"
« Reply #6 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
Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Use of the word "FILE"
« Reply #7 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Use of the word "FILE"
« Reply #8 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...



Why not yes ?

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Use of the word "FILE"
« Reply #9 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.  


I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Use of the word "FILE"
« Reply #10 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.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Use of the word "FILE"
« Reply #11 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
Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Use of the word "FILE"
« Reply #12 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/