Posted: Tue Dec 17, 2002 10:48 am
Restored from previous forum. Originally posted by Xuul.
The following is a percentage calculator I coded (my first ever app!).
You will notice that the #Gadget number for all of the frame and text gadgets is zero. ie. they are all sharing the same number. I did this because they are static elements which never change and are not referenced in any other parts of the code.
The app works fine, but my question is, is it really OK to use the same #Gadget number for more than one "decorative" gadget, or is this going to cause unforseen problems?
Thanks.
If OpenWindow(0,0,0,450,255,#PB_Window_ScreenCentered | #PB_Window_MinimizeGadget,"Percentage Calculator")
If CreateGadgetList(WindowID())
Frame3DGadget(0,10,10,WindowWidth()-20,70,"Find the value of the % of any given number",0)
Frame3DGadget(0,10,90,WindowWidth()-20,70,"Find the % of one number against another",0)
Frame3DGadget(0,10,170,WindowWidth()-20,70,"Find the % increase or decrease between 2 numbers",0)
TextGadget(0,20,44,60,12,"What is:")
TextGadget(0,123,44,30,12,"% of:")
TextGadget(0,261,44,60,12,"Answer:")
TextGadget(0,85,124,90,12,"Is what percent of:")
TextGadget(0,261,124,60,12,"Answer:")
TextGadget(0,85,204,20,12,"To:")
TextGadget(0,261,204,60,12,"Answer:")
StringGadget(1,60,40,60,20,"")
StringGadget(2,150,40,60,20,"")
StringGadget(3,302,40,60,20,"")
ButtonGadget(4,368,38,60,24,"Calculate")
StringGadget(5,20,120,60,20,"")
StringGadget(6,177,120,60,20,"")
StringGadget(7,302,120,60,20,"")
ButtonGadget(8,368,118,60,24,"Calculate")
StringGadget(9,20,200,60,20,"")
StringGadget(10,106,200,60,20,"")
StringGadget(11,302,200,60,20,"")
ButtonGadget(12,368,198,60,24,"Calculate")
EndIf
Repeat
action = WaitWindowEvent()
If action = #PB_EventGadget
Select EventGadgetID()
Case 4
SetGadgetText(3,StrF(ValF(GetGadgetText(1))/100*ValF(GetGadgetText(2))))
Case 8
SetGadgetText(7,StrF((ValF(GetGadgetText(5))/ValF(GetGadgetText(6)))*100))
Case 12
SetGadgetText(11,StrF(((ValF(GetGadgetText(10))-ValF(GetGadgetText(9)))/ValF(GetGadgetText(9)))*100)+"%")
EndSelect
EndIf
Until action = #PB_EventCloseWindow
EndIf
End
The following is a percentage calculator I coded (my first ever app!).
You will notice that the #Gadget number for all of the frame and text gadgets is zero. ie. they are all sharing the same number. I did this because they are static elements which never change and are not referenced in any other parts of the code.
The app works fine, but my question is, is it really OK to use the same #Gadget number for more than one "decorative" gadget, or is this going to cause unforseen problems?
Thanks.
If OpenWindow(0,0,0,450,255,#PB_Window_ScreenCentered | #PB_Window_MinimizeGadget,"Percentage Calculator")
If CreateGadgetList(WindowID())
Frame3DGadget(0,10,10,WindowWidth()-20,70,"Find the value of the % of any given number",0)
Frame3DGadget(0,10,90,WindowWidth()-20,70,"Find the % of one number against another",0)
Frame3DGadget(0,10,170,WindowWidth()-20,70,"Find the % increase or decrease between 2 numbers",0)
TextGadget(0,20,44,60,12,"What is:")
TextGadget(0,123,44,30,12,"% of:")
TextGadget(0,261,44,60,12,"Answer:")
TextGadget(0,85,124,90,12,"Is what percent of:")
TextGadget(0,261,124,60,12,"Answer:")
TextGadget(0,85,204,20,12,"To:")
TextGadget(0,261,204,60,12,"Answer:")
StringGadget(1,60,40,60,20,"")
StringGadget(2,150,40,60,20,"")
StringGadget(3,302,40,60,20,"")
ButtonGadget(4,368,38,60,24,"Calculate")
StringGadget(5,20,120,60,20,"")
StringGadget(6,177,120,60,20,"")
StringGadget(7,302,120,60,20,"")
ButtonGadget(8,368,118,60,24,"Calculate")
StringGadget(9,20,200,60,20,"")
StringGadget(10,106,200,60,20,"")
StringGadget(11,302,200,60,20,"")
ButtonGadget(12,368,198,60,24,"Calculate")
EndIf
Repeat
action = WaitWindowEvent()
If action = #PB_EventGadget
Select EventGadgetID()
Case 4
SetGadgetText(3,StrF(ValF(GetGadgetText(1))/100*ValF(GetGadgetText(2))))
Case 8
SetGadgetText(7,StrF((ValF(GetGadgetText(5))/ValF(GetGadgetText(6)))*100))
Case 12
SetGadgetText(11,StrF(((ValF(GetGadgetText(10))-ValF(GetGadgetText(9)))/ValF(GetGadgetText(9)))*100)+"%")
EndSelect
EndIf
Until action = #PB_EventCloseWindow
EndIf
End