i find this Code to be convenient for handling a lot of various Program Inputs (50+)
Level 1 :
; 0 - 999 = Total of StringGadget and ComboBoxGadget ( 1000 Total possible values for Inputs )
Basically for example ,
my 1st Input or Choice is a ComboBoxGadget which i number as number 1
; 1000 - 1999 = TextGadgets only to use for 0-999 Gadgets ( 999 Total possible values )
but before it, i have a TextGadget , which i number 1001
then my 2nd Input is a StringGadget , which i number as number 2
Level 2 :
; 1000 - 1999 = TextGadgets only to use for 0-999 Gadgets ( 999 Total possible values )
but before it, i have a TextGadget , which i number 1002
and so on .........
__________________________________________________________________________
then maybe sometimes i might have a :
TextGadget + ComboBoxGadget + TextGadget + StringGadget ( all on same Line in Program )
this is where the 3rd Level comes in :
; 2000 - 2999 = extra TextGadget, StringGadget, ComboBoxGadget ( 999 Total possible values )
i would then Number the Gadgets like this
TextGadget(1003) + ComboBoxGadget(3) + TextGadget(2003) + + StringGadget(3)
and so on ........
All the primary Inputs or Choices use progressively increasing Gadget Numbers
like 1,2,3,4.... so on
all the TextGadgets use progressively increasing Gadget Numbers
like 1001, 1002, 1003, 1004, to correspond to the Primary Inputs
and the 3rd Level is used for multiple Gadgets on 1 Program Line
Level 3 :
or can use one of the --> 3000 - 3199 = Miscellaneous Gadgets ( 199 possible values )
__________________________________________________________________________
the ComboBoxGadget "Flag" ... is used to make an Editable ComboBoxGadget
"not" editable ... and to retain the original choice
if the User enters incorrect Keys or values
the reason i use an editable ComboBoxGadget ( that's made non-editable )
is to maintain same "look" as a StringGadget and TextGadget
in a large Program with 50+ Inputs
an editable ComboBoxGadget can have same height as a StringGadget and TextGadget
which allows a better looking text Font to fit inside the height of an
editable ComboBoxGadget -VS- normal graphic looking ComboBoxGadget ,
and at same time , increases Screen real-estate when having to fit a bunch of Gadgets
Code: Select all
;-----< Top >-----
; Calculate_Cubic_Inches_with_ComboBox_FLAG_v1.pb
;-............... PureBasic Gadget Numbering System ......................................................
;
; 5000 - 9999 = CatchImage ( 4999 possible values ) ( .PNG , .JPG , .BMP , etc. )
;
; 4800 - 4999 = Windows ( 199 possible values )
; 4600 - 4799 = Menu ( 199 possible values )
; -----------------------------------------------------------------------------------------------------------
; 4300 - 4599 = ContainerGadget ( 299 possible values )
; 4000 - 4299 = ButtonGadget ( 299 possible values )
; 3700 - 3999 = ButtonImageGadget ( 299 possible values )
; 3400 - 3699 = ImageGadget ( 299 possible values )
; 3300 - 3399 = CanvasGadget ( 99 possible values )
; 3200 - 3299 = EditorGadget ( 99 possible values )
; 3000 - 3199 = Miscellaneous ( 199 possible values ) #Dummy_Focus = 3199
; -----------------------------------------------------------------------------------------------------------
; 2000 - 2999 = TextGadget, StringGadget, ComboBoxGadget ( 999 Total possible values )
; 1000 - 1999 = TextGadgets only to use for 0-999 Gadgets ( 999 Total possible values )
; 0 - 999 = Total of StringGadget and ComboBoxGadget ( 1000 Total possible values for Inputs )
;____________________________________________________________________________________________________________
EnableExplicit
;~~~~~ Constants List
#Window_0 = 0
#Menu_0 = 1
#CalcTextBox = 2000
#HelpTextBox = 3000
#CalculateButton = 4000
#Tahoma10 = 4
#Verdana9 = 5
LoadFont(#Tahoma10,"Tahoma", 10)
LoadFont(#Verdana9,"Verdana", 9)
Global.i WW, EW, EG, EM
; WW = WaitWindowEvent() ; EventID = WaitWindowEvent()
; EW = EventWindow() ; WindowID = EventWindow()
; EG = EventGadget() ; GadgetID = EventGadget()
; EM = EventMenu() ; MenuID = EventMenu()
Global Cylinders.i , Bore.d , Stroke.d , CID.d , wFlags.i, Flag
Declare Help(Index.i)
Procedure Help(Index.i)
Protected Help_Txt.s
Select Index
Case 1 : Help_Txt = " Choose : Number of Cylinders ( 1 to 16 Default = 8 Cylinders )"
Case 2 : Help_Txt = " Cylinder Bore in inches ( Valid Range= 1.000 to 7.000 inches )"
Case 3 : Help_Txt = " Crankshaft Stroke in inches ( Valid Range= 1.000 to 7.000 inches )"
EndSelect
SetGadgetText(#HelpTextBox,Help_Txt)
EndProcedure
Declare InputMAX()
Procedure InputMAX()
;Beep_(2500,200)
;~~~~~~~~~~ Result = MessageRequester(Title$, Text$ [, Flags]) ;~~~~~~~~~~ 2= CANCEL 6= YES 7= NO
;~~~~~~~~~~ #PB_MessageRequester_Ok ;~~~~~~~~~~ 'OK' only one button (Standard)
;~~~~~~~~~~ #PB_MessageRequester_YesNo ;~~~~~~~~~~ 'YES' or 'NO' buttons
;~~~~~~~~~~ #PB_MessageRequester_YesNoCancel ;~~~~~~~~~~ 'YES', 'NO' and 'CANCEL' buttons
Protected Title$ = "ERROR : Input exceeded the Valid Range"
Protected Text$ = "Input exceeded the maximum allowed value ...." + #CRLF$ + #CRLF$ + "Please enter a Value within the Valid Range"
MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)
EndProcedure
Declare ComboMAX()
Procedure ComboMAX()
;Beep_(2500,200)
;~~~~~~~~~~ Result = MessageRequester(Title$, Text$ [, Flags]) ;~~~~~~~~~~ 2= CANCEL 6= YES 7= NO
;~~~~~~~~~~ #PB_MessageRequester_Ok ;~~~~~~~~~~ 'OK' only one button (Standard)
;~~~~~~~~~~ #PB_MessageRequester_YesNo ;~~~~~~~~~~ 'YES' or 'NO' buttons
;~~~~~~~~~~ #PB_MessageRequester_YesNoCancel ;~~~~~~~~~~ 'YES', 'NO' and 'CANCEL' buttons
Protected Title$ = "ERROR : Invalid Keyboard Key Pressed"; + Space(5)
Protected Text$ = "Valid Keyboard Keys are :" + #CRLF$ + #CRLF$
Text$ + "F4 = ( Dropdown or Close ComboBox )" + #CRLF$+ #CRLF$
Text$ + "Arrow Up" + #CRLF$
Text$ + "Arrow Down" + #CRLF$
Text$ + "Arrow Left" + #CRLF$
Text$ + "Arrow Right" + #CRLF$
Text$ + "Page Up" + #CRLF$
Text$ + "Page Down" + #CRLF$
Text$ + "Home" + #CRLF$
Text$ + "End" + #CRLF$ + #CRLF$
Text$ + "Enter or Return" + #CRLF$
Text$ + "Escape ( Esc )" + #CRLF$
Text$ + "Tab" + #CRLF$ + #CRLF$ + #CRLF$
Text$ + "Note : Default Choice will now be used !" + #CRLF$ + #CRLF$
Text$ + Space(2) + "... make sure this new Choice is correct ?" + #CRLF$ + #CRLF$
MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)
EndProcedure
Declare Calc_CID()
Procedure Calc_CID()
Protected Title$ = " ERROR : Input Value is less than Valid Range "
Protected Text$ = " Input is less than the minimum allowed value " + #CRLF$ + #CRLF$ + " Please enter a Value within the Valid Range " + #CRLF$
Protected Cnt.i
For Cnt = 1 To 3
If ValD(GetGadgetText(Cnt)) < 1
SetGadgetText(Cnt,"")
MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)
SetActiveGadget(Cnt)
ProcedureReturn
EndIf
Next Cnt
Select GetGadgetState(1)
Case 0 : Cylinders = 1
Case 1 : Cylinders = 2
Case 2 : Cylinders = 3
Case 3 : Cylinders = 4
Case 4 : Cylinders = 5
Case 5 : Cylinders = 6
Case 6 : Cylinders = 8
Case 7 : Cylinders = 10
Case 8 : Cylinders = 12
Case 9 : Cylinders = 16
EndSelect
CID = Bore * Bore * Stroke * Cylinders * #PI/4 ;<--- 0.78539816339744828
SetGadgetText(#CalcTextBox,"CID = " + StrD(CID,5))
SetActiveGadget(1)
EndProcedure
OpenWindow(#Window_0, 0, 0, 440, 300, "Calculate Cubic Inch Displacement", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
CreateMenu(#Menu_0, WindowID(#Window_0))
MenuTitle("Exit")
MenuItem(0,"Quit Program")
TextGadget(1001,3,61,58,18," Cylinders") : SetGadgetFont(1001,FontID(#Tahoma10)) : SetGadgetColor(1001,#PB_Gadget_BackColor,RGB(250,250,250))
ComboBoxGadget(1,63,60,39,20,#PB_ComboBox_Editable) : SetGadgetFont(1,FontID(#Verdana9))
AddGadgetItem(1, -1, " 1") ; 0
AddGadgetItem(1, -1, " 2") ; 1
AddGadgetItem(1, -1, " 3") ; 2
AddGadgetItem(1, -1, " 4") ; 3
AddGadgetItem(1, -1, " 5") ; 4
AddGadgetItem(1, -1, " 6") ; 5
AddGadgetItem(1, -1, " 8") ; 6 = 8 Cylinders = Default choice
AddGadgetItem(1, -1, "10") ; 7
AddGadgetItem(1, -1, "12") ; 8
AddGadgetItem(1, -1, "16") ; 9
SetGadgetState(1,6) ;6 = 8 Cylinders = Default choice
TextGadget(1002,3,81,58,18," Bore") : SetGadgetFont(1002,FontID(#Tahoma10)) : SetGadgetColor(1002,#PB_Gadget_BackColor,RGB(250,250,250))
StringGadget(2,63,80,84,20,"",#PB_Text_Center) : SetGadgetFont(2,FontID(#Verdana9)) : SetGadgetAttribute(2,#PB_String_MaximumLength,10)
TextGadget(1003,3,101,58,18," Stroke") : SetGadgetFont(1003,FontID(#Tahoma10)) : SetGadgetColor(1003,#PB_Gadget_BackColor,RGB(250,250,250))
StringGadget(3,63,100,84,20,"",#PB_Text_Center) : SetGadgetFont(3,FontID(#Verdana9)) : SetGadgetAttribute(3,#PB_String_MaximumLength,10)
ButtonGadget(#CalculateButton,26,124,70,20,"Calculate") : SetGadgetFont(#CalculateButton,FontID(#Verdana9))
GadgetToolTip(#CalculateButton, "Calculate Cubic Inches")
TextGadget(#CalcTextBox,3,150,142,18,"",#PB_Text_Center) : SetGadgetFont(#CalcTextBox,FontID(#Verdana9)) : SetGadgetColor(#CalcTextBox,#PB_Gadget_BackColor,RGB(255,255,255))
TextGadget(#HelpTextBox,5,200,400,18,"") : SetGadgetFont(#HelpTextBox,FontID(#Tahoma10)) : SetGadgetColor(#HelpTextBox,#PB_Gadget_BackColor,RGB(255,255,220))
AddKeyboardShortcut(#Window_0,#PB_Shortcut_Return,10013)
AddKeyboardShortcut(#Window_0,#PB_Shortcut_Escape,10027)
SetActiveGadget(1) : SendMessage_(GadgetID(GetActiveGadget()), #EM_SETSEL, 0, -1)
Repeat
WW = WaitWindowEvent() ;<--- WW = WaitWindowEvent()
Select EventWindow()
Case #Window_0 ;~~~~~ BlackBox
Select WW
Case #PB_Event_CloseWindow : End
Case #PB_Event_Gadget
EG = EventGadget() ;<--- EG = EventGadget()
Select EventGadget()
Case 1 ; Number of Cylinders
Select EventType()
Case #PB_EventType_Focus : Flag = GetGadgetState(GetActiveGadget()) : Help(EG)
Case #PB_EventType_Change : SetGadgetText(#CalcTextBox,"")
If GetGadgetState(GetActiveGadget()) <> -1 : Flag = GetGadgetState(GetActiveGadget()) : SetGadgetState(EventGadget(),Flag) : EndIf
If GetGadgetState(GetActiveGadget()) = -1 : SetGadgetState(EventGadget(),Flag) : ComboMAX() : EndIf
EndSelect
Case 2 ; Bore
Select EventType()
Case #PB_EventType_Focus : Help(EG) : Bore = ValD(GetGadgetText(EG)) : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
Case #PB_EventType_Change : SetGadgetText(#CalcTextBox,"")
If ValD(GetGadgetText(EG)) > 7 : InputMAX() : SetGadgetText(EG,"") : SetActiveGadget(EG) : EndIf
Case #PB_EventType_LostFocus : Bore = ValD(GetGadgetText(EG))
If Bore >= 1 And Bore <= 7 : SetGadgetText(EG,StrD(Bore,5)) : Else : SetGadgetText(EG,"") : EndIf
EndSelect
Case 3 ; Stroke
Select EventType()
Case #PB_EventType_Focus : Help(EG) : Stroke = ValD(GetGadgetText(EG)) : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
Case #PB_EventType_Change : SetGadgetText(#CalcTextBox,"")
If ValD(GetGadgetText(EG)) > 7 : InputMAX() : SetGadgetText(EG,"") : SetActiveGadget(EG) : EndIf
Case #PB_EventType_LostFocus : Stroke = ValD(GetGadgetText(EG))
If Stroke >= 1 And Stroke <= 7 : SetGadgetText(EG,StrD(Stroke,5)) : Else : SetGadgetText(EG,""): EndIf
EndSelect
Case #CalculateButton ; Calculate Button
Calc_CID()
Select EventType()
EndSelect
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 0 ; Exit and Quit Program
End ; End Program
;=====< Enter/Return and Escape Keys to move thru Input routines >=====
Case 10013 ;~~~~~ #PB_Shortcut_Return ( 13 is now 10013 )
Select GetActiveGadget()
Case #CalculateButton : RemoveKeyboardShortcut(#Window_0,#PB_Shortcut_Return)
Calc_CID()
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, 10013)
Case 1 To 2 : SetActiveGadget(GetActiveGadget() + 1)
Case 3 : SetActiveGadget(#CalculateButton)
EndSelect
Case 10027 ;~~~~~ #PB_Shortcut_Escape ( 27 is now 10027 )
Select GetActiveGadget()
Case 1 : SetActiveGadget(3)
Case 2 To 3 : SetActiveGadget(GetActiveGadget() - 1)
EndSelect
EndSelect
EndSelect
EndSelect
Until WW = #PB_Event_CloseWindow
;----------< Bottom >--------------------------