Page 1 of 1

[SOLVED] Can't get Create file() to work

Posted: Sun Sep 15, 2024 9:46 pm
by Randy Walker
If I cut the if CreateFile() section and paste it to the front of the file then it works, but just cannot get CreateFile() to work inside the procedure. Driving me nuts!!!! :!: :evil:
You might notice I was also having issues with DeleteFile()

Code: Select all

Procedure Ping()
  url$="-n 1 test.rebex.net"
  If InternetGetConnectedState_(0,0)=1 ; Only check further if modem is switched on.
    p=RunProgram("ping.exe",url$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
    If p : While ProgramRunning(p) : o$+ReadProgramString(p) : Wend : CloseProgram(p) : EndIf
    If o$<>"" And FindString(o$,"unreachable",1)=0 And FindString(o$,"could not find host",1)=0 : Status=1 : EndIf
  EndIf
  ProcedureReturn Status
EndProcedure
If Ping()
  Debug "Live URL"
Else
  MessageRequester("Ohh Pooh","             Cannot find internet." +Chr(10)+ "This FTP session will be aborted")
  End
EndIf

#ALL = 3555
Global FTPassword$, Password$, FTPreturn$, HOME$
Global Dim FileList$(50)
Global Dim pick$(50)
HOME$ = "C:\TEMP\"     ; set path to working directory
testfile$ = HOME$ + "test.dat"
FTPassword$ = "password"

Procedure FTPGetArchive()
    If OpenFTP(0, "ftp.free.fr", "anonymous", "")
    ;If OpenFTP(0, "test.rebex.net", "demo", FTPassword$)
      ;SetFTPDirectory(0,"ARCHIVE")
      If ExamineFTPDirectory(0)
        While NextFTPDirectoryEntry(0)
          check$ = FTPDirectoryEntryName(0)
          If 1=1 ;LCase(Right(check$,9)) = "vital.arc"
            s$ + check$ + " " + FTPDirectoryEntryDate(0) + Chr(13)
            Debug check$
          EndIf
        Wend
      EndIf
      FinishFTPDirectory(0)
      CloseFTP(0)
    Else
      Debug "Can't connect to ftp Server"
    EndIf
  FTPreturn$ = s$
EndProcedure
Procedure GetArchList()
  ;DeleteFile(testfile$,#PB_FileSystem_Force)
  While FileSize(testfile$) > -1
    DeleteFile(testfile$,#PB_FileSystem_Force)
  Wend
  FTPGetArchive()
  Debug "Open the Damn file!!!"
  If CreateFile(10,testfile$)
    Debug "says success"
    WriteStringN(10,FTPreturn$,#PB_Ascii)
    CloseFile(10)
  Else
    Debug "FuuuQQ!!! FuuuQQ!!! FuuuQQ!!!"
  EndIf
 ; Debug FTPreturn$
EndProcedure
;Debug testfile$
;Debug testfile$
;Debug testfile$
GetArchList()
If ReadFile(0,testfile$)
  While Eof(0) = 0
    n + 1
    FileList$(n) = ReadString(0,#PB_Ascii)
    If Len(FileList$(n)) > 10
      ;Debug Str(n) + "  " + FileList$(n)
    EndIf
  Wend
  CloseFile(0)
EndIf

Re: CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Sun Sep 15, 2024 9:50 pm
by Kiffi
change

Code: Select all

testfile$ = HOME$ + "test.dat"
to

Code: Select all

Global testfile$ = HOME$ + "test.dat"
P.S.: You would have noticed this more quickly if you had used EnableExplicit.

Re: CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Sun Sep 15, 2024 10:03 pm
by Randy Walker
Kiffi wrote: Sun Sep 15, 2024 9:50 pm change

Code: Select all

testfile$ = HOME$ + "test.dat"
to

Code: Select all

Global testfile$ = HOME$ + "test.dat"
P.S.: You would have noticed this more quickly if you had used EnableExplicit.
WOW!! Kiffi -- You really nailed it, Really fast too. Thank you VERY Much!!!
I never use EnableExplicit because it gives me too many errors that don't make sense (to me).

Re: CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Sun Sep 15, 2024 10:44 pm
by mk-soft
EnableExplicit not used causes many errors

Re: CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Sun Sep 15, 2024 11:08 pm
by Quin
Tracking down a typo bug for two and a half hours is what finally sold me on using EnableExplicit. I'd much rather have to put Define I before my for loops than have to ever do that again ;)

Re: CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 7:22 am
by Randy Walker
I guess if I knew exactly what EnableExplicit was supposed to be doing, I might use it. Searched all through help and nothing there that I can find. The few times I tried using it, it only caused more grief than it appeared to be worth.

Re: CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 7:52 am
by mk-soft
PB-Help: https://www.purebasic.com/documentation ... tives.html

With EnableExplicit, you must always declare all variables. Define, Global, Protected and Share (Procedures). This means that an error is displayed immediately if you make a mistake.

Re: CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 9:33 am
by Randy Walker
mk-soft wrote: Mon Sep 16, 2024 7:52 am PB-Help: https://www.purebasic.com/documentation ... tives.html

With EnableExplicit, you must always declare all variables. Define, Global, Protected and Share (Procedures). This means that an error is displayed immediately if you make a mistake.
Yes I see now. Thanks mk_soft. I didn't search hard enough inside Compiler Directives.

Re: [SOLVED] CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 2:16 pm
by Quin
Another easy way to figure out what a directive does is to type it in the IDE, focus over it with your cursor, and then pres F1.

Re: [SOLVED] CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 3:28 pm
by Kiffi
Quin wrote: Mon Sep 16, 2024 2:16 pm Another easy way to figure out what a directive does is to type it in the IDE, focus over it with your cursor, and then pres F1.
This is true, but in this special case the "Compiler Directives" help opens and EnableExplicit is a little hard to find.

Re: [SOLVED] CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 3:55 pm
by Quin
Kiffi wrote: Mon Sep 16, 2024 3:28 pm
Quin wrote: Mon Sep 16, 2024 2:16 pm Another easy way to figure out what a directive does is to type it in the IDE, focus over it with your cursor, and then pres F1.
This is true, but in this special case the "Compiler Directives" help opens and EnableExplicit is a little hard to find.
You can press control+f to bring up a find dialog, and just type EnableE, it should come up :)
It would be nice if it could automatically focus you on/near it already, though.

Re: [SOLVED] CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 4:56 pm
by Little John
Maybe a moderator can rename this thread?
I think the title doesn't have much got to do with its content, and thus is pretty misleading.

Re: [SOLVED] CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Mon Sep 16, 2024 6:42 pm
by Randy Walker
Quin wrote: Mon Sep 16, 2024 2:16 pm Another easy way to figure out what a directive does is to type it in the IDE, focus over it with your cursor, and then pres F1.
:lol: I can't seem to manage to get through a single line of code without using F1. Often times I remember the keyword but syntax and associated notes escape me so yes, I am highly dependent on F1 topical help. This is maybe the main reason I am stuck on 5.xx and JaPBe, because F1 topical help works on variables and procedures too. Used to work on win APIs but that got broken thanks to MS so called upgrades. I have a lot of API usage so this is very inconvenient to me. :(

Re: [SOLVED] CreateFile() isn't working PB 5.40, 5.62, 6.11

Posted: Tue Sep 17, 2024 2:42 am
by AZJIO
Kiffi wrote: Mon Sep 16, 2024 3:28 pm This is true, but in this special case the "Compiler Directives" help opens and EnableExplicit is a little hard to find.
you need to add an anchor on page sections to go directly to the description

Code: Select all

<td nowrap><a href="#EnableExplicit">EnableExplicit<br>DisableExplicit</a></td>
...
<a name="EnableExplicit"></a>
I was moving a little towards this kind of control. But in the table above I made the wrong case, it works in CHM, but not on the website.
You can also add to the tree: viewtopic.php?p=595101#p595101