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

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

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

Post 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
Last edited by Randy Walker on Mon Sep 16, 2024 9:34 am, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post 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.
Hygge
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

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

Post 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).
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

EnableExplicit not used causes many errors
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

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

Post 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 ;)
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

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

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

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

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

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

Post 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.
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post 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.
Hygge
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

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

Post 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.
Little John
Addict
Addict
Posts: 4803
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

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

Post 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.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

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

Post 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. :(
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

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

Post 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
Post Reply