Page 2 of 2
Posted: Mon Apr 19, 2004 12:45 pm
by MLK
however
maybe, to early in the morning for an unemployed to discuss technical stuff in another language.
Posted: Mon Apr 19, 2004 12:49 pm
by Dare2
hehe.
I have high respect for multi-lingual people. I couldn't disuss anything in German.
Success to you.
Posted: Mon Apr 19, 2004 12:56 pm
by Kris_a
I like this better, personally:
Code: Select all
if (file = fopen("test.txt","rb")) {
// etc
}
I hope PB gets this syntax one day

Posted: Mon Apr 19, 2004 1:00 pm
by Dare2
lol.

Go away.
PureC (or PureJavaScript?)
Posted: Mon Apr 19, 2004 1:06 pm
by GedB
It would be nice if the library functions raised errors as well as returning values. For example, the helpfile states for SetErrorNumber():
You can forcibly fire an error. For example if you did not find a file, fire an error number 53 and let the error handler show the error for you.
Why can't the OpenFile function just raise error number 53 for us, so that we can catch it that way?
Re: using #pb_any
Posted: Mon Apr 19, 2004 5:13 pm
by GPI
MLK wrote:just want to say...
i like this more:
Code: Select all
If CreateFile(#file=#PB_Any,file$)
DeleteFile(file$)
EndIf
then:
Code: Select all
If #file=CreateFile(#PB_Any,file$)
DeleteFile(file$)
EndIf
What you want is impossible, because in PB (and all Basics) compare (is eqal) and "set" is the same char (=).
And so you can't set a variable in a If-Statement.
btw: you can't delete a open file...
Code: Select all
Procedure CreateFileX(*Handle.LONG,File$)
*Handle\l=CreateFile(#PB_Any,File$)
ProcedureReturn *Handle\l
EndProcedure
If CreateFileX(@GetNb,"C:\Test.txt")
CloseFile(GetNb)
EndIf
What is the purpose of #PB_Any?
Posted: Wed Apr 21, 2004 9:48 pm
by oldefoxx
Yeah, the topic suddenly got very obscure, what with the introduction of #PB_Any and mention of an "old" and "New"" way of assigning handles.
So where does #PB_Any come into play? I can't find any reference to it.
One of the problems here is the way in which "=" is being used. The purpose of "=" is to either assign a new value to the left hand variable, or to determine whether two items are equal in value without changing either.
The syntax gets ugly when it is not clear which use the programmer intended, or what action the compiler will actually take. In this case, the "ugly" means ambigious or uncertain.
Some languages require you to use "==" in place of "=" when you mean to compare two quantities or items, but this can be a problem when the programmer forgets this and only uses "=", which then produces the wrong outcome.
So, with regards to the previous discussion, the preferred method would be to assign the handle to a variable, then determine if the variable held a non-zero value, meaning that the act of creating or opening the file had been successful. That is straightforward and simple, and non-ambigious.