Constants Verification

Just starting out? Need help? Post your questions and find answers here.
dfw1417
User
User
Posts: 16
Joined: Tue Mar 01, 2022 1:45 am

Constants Verification

Post by dfw1417 »

I have used the example for the file system and slightly modified it to show the actual values corresponding to the constants. However it appears that some of the documented values for the constants are the same as others. This is shown in the code example provided below. So is this an error or was this really meant to be the same values. I used pb version 6.04 x64 for this code. Thanks in advance.

Code: Select all


;10032024 - File System Example

If OpenWindow(0, 100, 200, 290, 200, "PureBasic - FileSystem Example")
;   StringGadget  (0,  10, 10, 202, 24, GetHomeDirectory())
  StringGadget  (0,  10, 10, 202, 24, "E:\TEST")
  ButtonGadget  (1, 220, 10, 60 , 24, "List")
  ListViewGadget(2,  10, 40, 270, 150); Directory Listings
  ListViewGadget(3,  10, 40, 270, 150); File System Attribute Listings
  ;----- FS Attrib List
  ClearGadgetItems(3)
  AddGadgetItem(3, -1, "PB Hide Constant Value is: " + Str(#PB_FileSystem_Hidden))
  AddGadgetItem(3, -1, "PB Archive Constant Value is: " + Str(#PB_FileSystem_Archive))
  AddGadgetItem(3, -1, "PB Compressed Constant Value is: " + Str(#PB_FileSystem_Compressed))
  AddGadgetItem(3, -1, "PB Forced Constant Value is: " + Str(#PB_FileSystem_Force))
  AddGadgetItem(3, -1, "PB NoExtension Constant Value is: " + Str(#PB_FileSystem_NoExtension))
  AddGadgetItem(3, -1, "PB Normal Constant Value is: " + Str(#PB_FileSystem_Normal))
  AddGadgetItem(3, -1, "PB ReadOnly Constant Value is: " + Str(#PB_FileSystem_ReadOnly))
  AddGadgetItem(3, -1, "PB ReCursive Constant Value is: " + Str(#PB_FileSystem_Recursive))
  AddGadgetItem(3, -1, "PB System Constant Value is: " + Str(#PB_FileSystem_System))
  ;----- Event Loop
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget
      If EventGadget() = 1 ; Read
        ClearGadgetItems(2)  ; Clear all the items found in the ListView
        If ExamineDirectory(0, GetGadgetText(0), "*.*")
          While NextDirectoryEntry(0)
            FileName$ = DirectoryEntryName(0)
            If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory
              FileName$ = "[DIR] "+FileName$
            EndIf
            AddGadgetItem(2, -1, FileName$)
          Wend
        Else
          MessageRequester("Error","Can't examine this directory: "+GetGadgetText(0),0)
        EndIf
      EndIf
    EndIf
  Until Event = #PB_Event_CloseWindow
  
EndIf

Experience is what you get when you didn't get what you thought you wanted!
Acer TC895 32gb i5-2.9ghz Win10 1.5tb ssd Asus Gsyn 4k and Vizio 1080 hd monitors.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Constants Verification

Post by spikey »

The constants aren't a single related enumeration. They are used by different commands in different ways. So this exercise isn't entirely meaningful as a whole. It either goes too far, or not far enough. (They're named alike as a convenience when using autocomplete and so you know which library they belong to).

As a example #PB_FileSystem_ReadOnly is returned by DirectoryEntryAttributes(), #PB_FileSystem_NoExtension is an argument to GetFilePath() and #PB_FileSystemRecursive is an argument to CopyDirectory/DeleteDirectory. The same sort of thing will apply to the other 'duplicated' values if you actually follow through.

Where constants are used together there won't be an overlap by value, for example #PB_FileSystem_Hidden and #PB_FileSystem_ReadOnly don't overlap.

This isn't a fault and won't cause a problem unless you're trying to create some sort of code analysis tool, in which case you will need to take context into account as well.

If you are trying to decode file attribute values, see the example at https://www.purebasic.com/documentation ... tives.html
Last edited by spikey on Fri Oct 04, 2024 11:18 pm, edited 1 time in total.
dfw1417
User
User
Posts: 16
Joined: Tue Mar 01, 2022 1:45 am

Re: Constants Verification

Post by dfw1417 »

Thanks! I was thinking more along the lines of the Windows API attribute values and they are not directly used the same way and not the same values. :D
Experience is what you get when you didn't get what you thought you wanted!
Acer TC895 32gb i5-2.9ghz Win10 1.5tb ssd Asus Gsyn 4k and Vizio 1080 hd monitors.
Post Reply