Value of constants

Everything else that doesn't fall into one of the other PB categories.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Value of constants

Post 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
User avatar
STARGÅTE
Addict
Addict
Posts: 2232
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Value of constants

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Value of constants

Post 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.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: Value of constants

Post 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
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Value of constants

Post by Fred »

BarryG is right, you should never rely on the constant value as it can change anytime between releases.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Value of constants

Post 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
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Value of constants

Post by Fred »

It would be better indeed.
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: Value of constants

Post 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 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Value of constants

Post 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:
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: Value of constants

Post 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?
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Value of constants

Post by Fred »

Yes
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Value of constants

Post by BarryG »

.
Last edited by BarryG on Wed Nov 06, 2024 9:27 am, edited 2 times in total.
Little John
Addict
Addict
Posts: 4789
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Value of constants

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Value of constants

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