Page 1 of 1

Value of constants

Posted: Mon Nov 04, 2024 9:20 pm
by mestnyi
Aren't these bit constants?

Code: Select all

Debug #PB_Button_Toggle ; return 4099 not 4096
Debug #PB_ComboBox_Editable ; return 66 not 64

Re: Value of constants

Posted: Mon Nov 04, 2024 9:47 pm
by STARGĂ…TE
mestnyi wrote: Mon Nov 04, 2024 9:20 pm Aren't these bit constants?

Code: Select all

Debug #PB_Button_Toggle ; return 4099 not 4096
Debug #PB_ComboBox_Editable ; return 66 not 64
Why should they have only one set bit? Probably these constants are itself combinations of multiple OS specific constants.

Re: Value of constants

Posted: Mon Nov 04, 2024 10:34 pm
by BarryG
Constants starting with "#PB_" are custom-made for PureBasic and can be any value decided by Fred. They don't always correspond to an existing API constant, and nor should they.

Re: Value of constants

Posted: Mon Nov 04, 2024 10:51 pm
by mestnyi
that's right, but I remember that there were problems with the combobox.
maybe it was because of him that there were problems, maybe there was a typo :D

Re: Value of constants

Posted: Tue Nov 05, 2024 10:41 am
by Fred
BarryG is right, you should never rely on the constant value as it can change anytime between releases.

Re: Value of constants

Posted: Tue Nov 05, 2024 11:29 am
by BarryG
Fred, on this subject... I've always meant to report that there are no constants for the return value of FileSize()... should there be? :) Can you add some? Thanks.

Image

Re: Value of constants

Posted: Tue Nov 05, 2024 11:35 am
by Fred
It would be better indeed.

Re: Value of constants

Posted: Tue Nov 05, 2024 3:32 pm
by Axolotl
Yes, I would support that.
BTW: I use this for a (very) long time now!? Just a cautious suggestion.

Code: Select all

;/
;| FileSize() results as constants 
;\
#PB_FileSize_Empty     =  0    
#PB_FileSize_Missing   = -1   
#PB_FileSize_Directory = -2 

Re: Value of constants

Posted: Tue Nov 05, 2024 4:52 pm
by Quin
Axolotl wrote: Tue Nov 05, 2024 3:32 pm Yes, I would support that.
BTW: I use this for a (very) long time now!? Just a cautious suggestion.

Code: Select all

;/
;| FileSize() results as constants 
;\
#PB_FileSize_Empty     =  0    
#PB_FileSize_Missing   = -1   
#PB_FileSize_Directory = -2 
Something like this would be absolutely amazing, for the first three years of me using PB I had to go check what the return value was for missing file vs directory every time I wanted to use this function :mrgreen:

Re: Value of constants

Posted: Tue Nov 05, 2024 6:45 pm
by mestnyi
Fred wrote: Tue Nov 05, 2024 10:41 am BarryG is right, you should never rely on the constant value as it can change anytime between releases.
I agree with you, but I'm working on a GUI to replace the standard one for all three axes, and it was almost ready until my hard drive burned down, I had to rewrite it again, so I'm directly connected with both hands. :cry:
I just saw a lot of potential in purebasic, its syntax has sunk :) into my soul, but the graphical interface kills with its limitations.

So it's not a typo, is that what Fred intended?

Re: Value of constants

Posted: Tue Nov 05, 2024 7:46 pm
by Fred
Yes

Re: Value of constants

Posted: Wed Nov 06, 2024 12:33 am
by BarryG
.

Re: Value of constants

Posted: Wed Nov 06, 2024 6:53 am
by Little John
Quin wrote: Tue Nov 05, 2024 4:52 pm Something like this would be absolutely amazing, for the first three years of me using PB I had to go check what the return value was for missing file vs directory every time I wanted to use this function :mrgreen:
You can use Macros:

Code: Select all

Macro ExistFile (_entry_)
   Bool(FileSize(_entry_) > -1)
EndMacro

Macro ExistDirectory (_entry_)
   Bool(FileSize(_entry_) = -2)
EndMacro

Re: Value of constants

Posted: Wed Nov 06, 2024 7:59 am
by Demivec
Little John wrote: Wed Nov 06, 2024 6:53 am
Quin wrote: Tue Nov 05, 2024 4:52 pm Something like this would be absolutely amazing, for the first three years of me using PB I had to go check what the return value was for missing file vs directory every time I wanted to use this function :mrgreen:
You can use Macros:

Code: Select all

Macro ExistFile (_entry_)
   Bool(FileSize(_entry_) > -1)
EndMacro

Macro ExistDirectory (_entry_)
   Bool(FileSize(_entry_) = -2)
EndMacro
Or using the proposed constants:

Code: Select all

Macro ExistFile (_entry_)
   Bool(FileSize(_entry_) >= #PB_FileSize_Empty)
EndMacro

Macro ExistDirectory (_entry_)
   Bool(FileSize(_entry_) = #PB_FileSize_Directory)
EndMacro