Author Topic: Kill & Name command  (Read 3292 times)

0 Members and 1 Guest are viewing this topic.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Kill & Name command
« on: April 02, 2021, 12:43:30 pm »
Hi
stuck home with a positive test arg! so tinkering with some old app I have laying around.

while I don't mind using the shell command, I try to avoid it when I can.
I noticed that there is not a copy command.

so trying the kill/name commands

Problem: KILL produces a file not closed error - when it clearly is and NAME produces an error, most likely because the KILL command error has not been fixed. So before I tackle the NAME error, can someone check out what is wrong with the KILL command?

Code: [Select]
        FF = FreeFile
        If _FileExists("temp.tmp") Then Kill "temp.tmp"

        Open DB_FILE For Input As #FF:
        HH = FreeFile
        Open "temp.tmp" For Append As #HH

        While Not EOF(FF)
                Line Input #FF, aline
                If RECNUM = cnt Then
                        Print #HH, INFO
                Else
                        Print #HH, aline
                End If
               cnt = cnt + 1
        Wend

        Close #HH
        Close #FF

        Kill DB_FILE '<-- program fails here with file not closed
        Name "temp.tmp" As DB_FILE

« Last Edit: April 02, 2021, 12:46:02 pm by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Kill & Name command
« Reply #1 on: April 02, 2021, 12:49:39 pm »
SUB Copy (file1$, file2$)
    OPEN file1$ FOR BINARY AS #1
    l = LOF(1)
    s$ = SPACE$(l)
    GET #1, 1, s$
    CLOSE #1
    OPEN file2$ FOR OUTPUT AS #1: CLOSE #1
    OPEN file2$ FOR BINARY AS #1
    PUT #1, 1, s$
    CLOSE #1
END SUB
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Kill & Name command
« Reply #2 on: April 02, 2021, 12:52:34 pm »
aw man too fast for me. LOL

I actually found the issue as I was re-reading my post... as an experiment I put a

Code: [Select]
CLOSE #1, CLOSE #2 at the top of this sub

and it worked. Which leads to my next question. When I do a
OPEN  command, I immediately follow up with a close command. Is there a way to check my work to find out where (if any) my straggler close commands are?


EDIT:
THANK you for the copy sub!! That should be added to a next revision.. :-)
« Last Edit: April 02, 2021, 12:53:49 pm by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline paranoia1001001

  • Newbie
  • Posts: 13
    • View Profile
Re: Kill & Name command
« Reply #3 on: April 02, 2021, 01:06:59 pm »
Glad you got this fixed. Hope you feel better soon!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Kill & Name command
« Reply #4 on: April 02, 2021, 01:42:16 pm »
Glad you got this fixed. Hope you feel better soon!


thanks!!

Im used to working all day so feels weird just sittin' around LOL

However, only got it partially fixed.
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Kill & Name command
« Reply #5 on: April 02, 2021, 08:56:11 pm »
CLOSE without any argument will close all open files.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Kill & Name command
« Reply #6 on: April 03, 2021, 12:44:00 am »
CLOSE without any argument will close all open files.

thanks! that is very helpful

So with my current conundrum, how would I seek out and destroy any stragglers :-)
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Kill & Name command
« Reply #7 on: April 03, 2021, 11:02:28 am »
thanks! that is very helpful

So with my current conundrum, how would I seek out and destroy any stragglers :-)

What is straggling? certainly not open files not closed yet because you just learned, I think lol, that CLOSE without argument closes them all.

Sometimes when I do file work I have to ChDir and change back to get the system to update it's file listing for the folder that I am working in like renaming files, moving, removing... specially working from QB64.
« Last Edit: April 03, 2021, 11:08:16 am by bplus »

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Kill & Name command
« Reply #8 on: April 03, 2021, 09:53:58 pm »
What is straggling? certainly not open files not closed yet because you just learned, I think lol, that CLOSE without argument closes them all.

Sometimes when I do file work I have to ChDir and change back to get the system to update it's file listing for the folder that I am working in like renaming files, moving, removing... specially working from QB64.

yes the magic CLOSE works, but for me that is a little sloppy if i have an if/then/else floating that left one of them OPEN. Trying to keep it clean. You can check the source - I put it in programs - its a password manager - I am betting there is a case/select or if/then/else messing up the flow of closes :-)

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