Newbie stumper

Everything else that doesn't fall into one of the other PB categories.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Newbie stumper

Post by kpeters58 »

Hi all,

this one stumps me (my second day with PB):

When I have the window below open and open another window from the same application, the container gadget with id #20 disappears into nirwana, even if the two windows do not overlap (Windows 7, if that's of any interest)

As always,
thanks for any pointers
Kai

Code: Select all

Procedure OpenWindow_Window_1()
  If OpenWindow(#Form_About, 488, 274, 450, 300, "About", #PB_Window_ScreenCentered|#PB_Window_TitleBar, WindowID(#Form_Main))
    
    Frame3DGadget(#PB_Any, 10, 10, 430, 250, " Version Information ")
    
    SetGadgetFont(TextGadget(#PB_Any, 60, 50, 200, 24, VersionInfo\ProductName), LoadFont(1, "Arial", 14, #PB_Font_Bold)) 
    TextGadget  (#PB_Any, 60, 80, 200, 24, VersionInfo\ProductInfo)

    ; >>> shadow first 
    ContainerGadget(10, 50, 120, 370, 120)
    CloseGadgetList()
    SetGadgetColor(10, #PB_Gadget_BackColor, RGB(60, 60, 60))
    
    ; >>> white rect next overlapping the shadow rectangle
    ContainerGadget(20, 45, 115, 370, 120, #PB_Container_Flat)
      TextGadget  (22,  45,  20, 200,  24, VersionInfo\CompanyName)
      TextGadget  (24,  45,  50, 200,  24, VersionInfo\CopyRight)
      TextGadget  (26,  45,  80, 200,  24, VersionInfo\CompanyURL)
    CloseGadgetList()
    For i = 20 To 26 Step 2 
      SetGadgetColor(i, #PB_Gadget_BackColor,  RGB(255, 255, 255))
    Next  
    ButtonGadget(#Form_About_Button, 390, 270, 50, 25, "Close")
  EndIf
EndProcedure
PB 5.73 on Windows 10 & OS X High Sierra
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Newbie stumper

Post by citystate »

at a guess, #Form_About_Button is equal to 20

it's good practice to either use all hard coded values, or all global constants when coding gadgets
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Newbie stumper

Post by kpeters58 »

Hmm, looks like I have to keep my IDs unique - both windows had a container gadget with the same ID....

Kai
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Newbie stumper

Post by em_uk »

I would like to see a little more code, or a working example with the problem.

I did a little bit of code changing and easily got 3 windows to open, but without seeing the other parts of the code I'm not sure what will be going on.
----

R Tape loading error, 0:1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Newbie stumper

Post by netmaestro »

It's best to pick one approach to numbering your gadgets and stick to it. Here you're using constants for some gadgets and hardcoded numbers for others, setting yourself up for a conflict. For projects that aren't just hacking around, ones that will need maintained in future, I like to make a gadget enumeration block and put a constant for every gadget in the project in the block. With this approach there is no possibility of a conflict. Other approaches are fine too, such as #PB_Any or hardcoded numbers, but it's important not to mix them if you want a smooth, trouble-free development process without unnecessary headaches.
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Newbie stumper

Post by IdeasVacuum »

I like to make a gadget enumeration block and put a constant for every gadget in the project in the block. With this approach there is no possibility of a conflict.
This is always the safest way to do it, for everything except an app with a huge amount of gadgets (in which case it is a matter of hard coding them/testing them via loops).
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Newbie stumper

Post by netmaestro »

Yes, and I also said #PB_Any is fine too. The point is just pick one approach and stick to it.
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Newbie stumper

Post by IdeasVacuum »

...I know #PB_Any is very convenient and works well, but in anything other than simple source, it's easy to get confused about what happens where and to what.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Newbie stumper

Post by MachineCode »

IdeasVacuum wrote:...I know #PB_Any is very convenient and works well, but in anything other than simple source, it's easy to get confused about what happens where and to what.
Say what? I disagree. #PB_Any makes large sources easier to follow. It depends on how you code, I guess.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Newbie stumper

Post by IdeasVacuum »

...well, if you have 25 "#PB_Any String Gadgets" I don't see how that is easy to understand in your code in terms of each gadgets purpose? If you use enumerations on the other hand, you will have a much better idea of purpose with labels like #GivenName #FamilyName #DateOfBirth etc. I try to get the best of both worlds by having more than one enumeration block and defining the start number and step. That way, the code is easy to read overall, but I can still process gadgets sequentially in a loop - for example, grabbing the text from those String Gadgets and saving to file, where the loop simply increments the gadget id number.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Newbie stumper

Post by MachineCode »

IdeasVacuum wrote:if you have 25 "#PB_Any String Gadgets" I don't see how that is easy to understand in your code in terms of each gadgets purpose?
It's easy! Do what I do. No enumerations required! :)

Code: Select all

OpenWindow(0,100,100,640,480,"test")

Global username=ButtonGadget(#PB_Any,10,10,200,25,"Username")
Global password=ButtonGadget(#PB_Any,10,40,200,25,"Password")
Global website=ButtonGadget(#PB_Any,10,70,200,25,"Website")

Repeat

  event=WaitWindowEvent()

  If event=#PB_Event_Gadget
    Select EventGadget()
      Case username : Debug "username"
      Case password : Debug "password"
      Case website  : Debug "website"
    EndSelect
  EndIf

Until event=#PB_Event_CloseWindow
IdeasVacuum wrote:I can still process gadgets sequentially in a loop - for example, grabbing the text from those String Gadgets and saving to file, where the loop simply increments the gadget id number.
You can do this with my example like so:

Code: Select all

For g=username To website
  text$=GetGadgetText(g)
Next
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Newbie stumper

Post by citystate »

kpeters58 wrote:Hmm, looks like I have to keep my IDs unique - both windows had a container gadget with the same ID....

Kai
yup, that would do it...

for methods on how to minimise this happening again, I'd suggest one of them posted above - but as netmaestro says, be consistent - it makes your job much easier in the long run
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Newbie stumper

Post by Trond »

MachineCode wrote: You can do this with my example like so:

Code: Select all

For g=username To website
  text$=GetGadgetText(g)
Next
No, that's wrong. It works by chance only. The gadget numbers allocated by #PB_Any are never one number apart and not guaranteed to be sequential. You have to put the numbers in an array and loop over it.

When running your example:
username = 31905408
password = 31905504
website = 31905600
Last edited by Trond on Tue Nov 29, 2011 12:34 pm, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Newbie stumper

Post by Trond »

Hmm, looks like I have to keep my IDs unique
ID's must definetely be unique, that's the purpose of ID's: To identify an object uniquely.

Edit: We are actually talking about gadget numbers here (sometimes referred to as #Gadget), not ID's. An ID is what you get when passing a gadget number to the function GadgetID(). The ID is the number used by the operating system to identify the gadget.
Last edited by Trond on Tue Nov 29, 2011 12:35 pm, edited 1 time in total.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Newbie stumper

Post by MachineCode »

Trond wrote:It works by chance only
You're right. I only tested the output of the first gadget, saw that it worked for that single test, so I posted a For/Next loop that I assumed would work for all. Sorry peeps!
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Post Reply