using #pb_any

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
MLK
User
User
Posts: 57
Joined: Sat Jan 24, 2004 8:46 pm
Location: Germany

Post by MLK »

however :-)

maybe, to early in the morning for an unemployed to discuss technical stuff in another language.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

hehe. :)

I have high respect for multi-lingual people. I couldn't disuss anything in German.

Success to you.
Kris_a
User
User
Posts: 92
Joined: Sun Feb 15, 2004 8:04 pm
Location: Manchester, UK

Post 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 :D
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

lol. :D Go away.

PureC (or PureJavaScript?)
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post 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?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: using #pb_any

Post 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
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

What is the purpose of #PB_Any?

Post 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.
has-been wanna-be (You may not agree with what I say, but it will make you think).
Post Reply