Simple Program with additional Form Designer Code

Share your advanced PureBasic knowledge/code with the community.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Simple Program with additional Form Designer Code

Post by VB6_to_PBx »

Simple Program with additional Form Designer Code
Image

Form Designer Code :

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global W1

Global CT1, TX1, T1, G1, T2, G2, T3, G3, T4, G4, T5, G5, TX2, G6

Enumeration FormMenu
  #MenuItem_0
EndEnumeration

Enumeration FormFont
  #Font_W1_0
  #Font_W1_1
  #Font_W1_2
  #Font_W1_3
EndEnumeration

LoadFont(#Font_W1_0,"Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)
LoadFont(#Font_W1_1,"Tahoma", 10)
LoadFont(#Font_W1_2,"Verdana", 9)
LoadFont(#Font_W1_3,"Verdana", 10, #PB_Font_Bold)


Procedure OpenW1(x = 0, y = 0, width = 625, height = 115)
  W1 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  SetWindowColor(W1, RGB(150,150,150))
  CreateMenu(0, WindowID(W1))
  MenuTitle("Quit")
  MenuItem(#MenuItem_0, "Quit Program")
  MenuTitle("Calculate")
  MenuTitle("Clear")
  CT1 = ContainerGadget(#PB_Any, 4, 4, 618, 87, #PB_Container_Raised)
  SetGadgetColor(CT1, #PB_Gadget_BackColor,RGB(192,192,192))
  TX1 = TextGadget(#PB_Any, 2, 1, 200, 22, " ET Factor Calculator")
  SetGadgetColor(TX1, #PB_Gadget_FrontColor,RGB(0,0,128))
  SetGadgetColor(TX1, #PB_Gadget_BackColor,RGB(192,192,192))
  SetGadgetFont(TX1, FontID(#Font_W1_0))
  T1 = TextGadget(#PB_Any, 2, 25, 90, 18, " Initial Distance")
  SetGadgetColor(T1, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(T1, #PB_Gadget_BackColor,RGB(240,240,240))
  SetGadgetFont(T1, FontID(#Font_W1_1))
  G1 = StringGadget(#PB_Any, 92, 24, 110, 20, "")
  SetGadgetColor(G1, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(G1, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(G1, FontID(#Font_W1_2))
  T2 = TextGadget(#PB_Any, 206, 25, 90, 18, " Initial ET")
  SetGadgetColor(T2, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(T2, #PB_Gadget_BackColor,RGB(240,240,240))
  SetGadgetFont(T2, FontID(#Font_W1_1))
  G2 = StringGadget(#PB_Any, 296, 24, 110, 20, "")
  SetGadgetColor(G2, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(G2, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(G2, FontID(#Font_W1_2))
  T3 = TextGadget(#PB_Any, 410, 25, 90, 18, " Initial MPH")
  SetGadgetColor(T3, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(T3, #PB_Gadget_BackColor,RGB(240,240,240))
  SetGadgetFont(T3, FontID(#Font_W1_1))
  G3 = StringGadget(#PB_Any, 500, 24, 110, 20, "")
  SetGadgetColor(G3, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(G3, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(G3, FontID(#Font_W1_2))
  T4 = TextGadget(#PB_Any, 2, 45, 90, 18, " Final Distance")
  SetGadgetColor(T4, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(T4, #PB_Gadget_BackColor,RGB(240,240,240))
  SetGadgetFont(T4, FontID(#Font_W1_1))
  G4 = StringGadget(#PB_Any, 92, 44, 110, 20, "")
  SetGadgetColor(G4, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(G4, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(G4, FontID(#Font_W1_2))
  T5 = TextGadget(#PB_Any, 206, 45, 90, 18, " Final ET")
  SetGadgetColor(T5, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(T5, #PB_Gadget_BackColor,RGB(240,240,240))
  SetGadgetFont(T5, FontID(#Font_W1_1))
  G5 = StringGadget(#PB_Any, 296, 44, 110, 20, "")
  SetGadgetColor(G5, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(G5, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(G5, FontID(#Font_W1_2))
  TX2 = TextGadget(#PB_Any, 410, 45, 90, 18, " ET Factor")
  SetGadgetColor(TX2, #PB_Gadget_FrontColor,RGB(0,0,128))
  SetGadgetColor(TX2, #PB_Gadget_BackColor,RGB(240,240,240))
  SetGadgetFont(TX2, FontID(#Font_W1_3))
  G6 = StringGadget(#PB_Any, 500, 44, 110, 20, "")
  SetGadgetColor(G6, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(G6, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(G6, FontID(#Font_W1_2))
  CloseGadgetList()
EndProcedure

Procedure W1_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
        Case #MenuItem_0
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenW1()

Repeat
  event = WaitWindowEvent()
Until W1_Events(event) = #False

End
Last edited by VB6_to_PBx on Mon Jul 27, 2020 12:11 am, edited 1 time in total.
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: Simple Program with additional Form Designer Code

Post by VB6_to_PBx »

i then modify the Form Designer code to this :

Code: Select all

EnableExplicit
;~~~~~ DisableExplicit

Global.i WW , EW , EG , ET , EM , AG    ;<<--- WW= WaitWindowEvent()  EW= EventWindow()  EG= EventGadget()  ET= EventType()  EM= EventMenu()  AG= GetActiveGadget()
;        EW = EventWindow()             ;<<--- In Programs with more than one Form or Window, which Window did the Event occur on.
;        WW = WaitWindowEvent()         ;<<--- Wait until a new Window or Gadget Event occurs.
;        EG = EventGadget()             ;<<--- Which Gadget did the Event occur on. ( Numerical Number or Constant #Name of the Gadget )
;        ET = EventType()               ;<<--- What sort of Event Type occurred.
;        EM = EventMenu()               ;<<--- Which Menu did the Event occur on.
;        AG = GetActiveGadget()         ;<<--- Get the Active Gadget's Numerical Number or Constant #Name that has the current Focus
Global.i wFlags , cFlag                 ;<<--- wFlags= Window Flags   cFlag= stores the initial State of the ComboBoxGadget  ComboMAX()= ERROR caused by wrong Key by User
Global.i GX                             ;<<--- GX = use for indentifying Gadgets in various Callback() Procedures
Global.i Gad = 10                       ;<<--- Gad = Array total number of User input Gadgets such as StringGadgets and ComboBoxGadgets in GUI
Global.d Dim Var(Gad) , Dim VarM(Gad)   ;<<--- Var()= Input StringGadget English Variables   VarM()= Input StringGadget Metric Variables
Global.d Dim Min(Gad) , Dim Max(Gad)    ;<<--- English Units   Min()= minimum value    Max()= maximum value
Global.d Dim MinM(Gad) , Dim MaxM(Gad)  ;<<--- Metric Units   MinM()= minimum value   MaxM()= maximum value
Global.i Dim MaxLen(Gad) , Dim Dec(Gad) ;<<--- MaxLen()= max character input length    Dec()= number of Decimal Places
Global.i DirtyS , DirtyC                ;<<--- DirtyS= StringGadget value was changed     DirtyC= ComboBoxGadget choice was changed
Global.i Inc , Cnt , Units              ;<<--- Inc or Cnt= For : Next Loops -or- for Integer Loops     Units= 0 for English   Units= 1 for Metric
Global.d IncD , CntD                    ;<<--- IncD and CntD = Double Precision for Repeat : Until Loops
Global.s Title , Text                   ;<<--- use for all MessageRequester or InputRequester

#Dummy_Focus = 0 ;<<--- an invisible location off Window Screen that can receive Caret Focus---> example : StringGadget(#Dummy_Focus,-10,-10,5,5,"",#PB_Text_Center)

;====== Keyboard Shortcut Constants
#KeyReturn= 10013 : #KeyEscape= 10027 : #KeyPageUp= 10033 : #KeyPageDown= 10034 : #KeyEnd= 10035 : #KeyHome= 10036 : #KeyUp= 10038 : #KeyDown= 10040
#F1= 10112 : #F2= 10113 : #F3= 10114 : #F4= 10115 : #F5= 10116 : #F6= 10117 : #F7= 10118 : #F8= 10119 : #F9= 10120 : #F10= 10121 : #F11= 10122 : #F12= 10123

;====== Font Constants
#Consolas11  = 1 : LoadFont(#Consolas11,"Consolas", 11)
#Tahoma10    = 2 : LoadFont(#Tahoma10,"Tahoma", 10)
#Verdana8b   = 3 : LoadFont(#Verdana8b,"Verdana", 8, #PB_Font_Bold)
#Verdana9    = 4 : LoadFont(#Verdana9,"Verdana", 9)
#Verdana10b  = 5 : LoadFont(#Verdana10b,"Verdana", 10, #PB_Font_Bold)
#Verdana11bi = 6 : LoadFont(#Verdana11bi,"Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)


Declare ComboERROR()
Declare ComboInput()
Declare StringERROR()
Declare StringInput()
Declare Clear()
Declare ETFactor()


Procedure OpenW1(x = 0, y = 0, width = 625, height = 115)
    OpenWindow(1, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
    SetWindowColor(1, RGB(128,128,128))

    CreateMenu(1, WindowID(1))
    MenuTitle("Quit")
        MenuItem(0," Quit  Program ")
    CloseSubMenu()
        MenuItem(1,"Calculate")
        MenuItem(2,"Clear")

    ;------ Add Keyboard Shortcuts to travel thru Inputs
    AddKeyboardShortcut(1,#PB_Shortcut_Return,#KeyReturn)
    AddKeyboardShortcut(1,#PB_Shortcut_Escape,#KeyEscape)
    AddKeyboardShortcut(1,#PB_Shortcut_PageDown,#KeyPageDown)
    AddKeyboardShortcut(1,#PB_Shortcut_PageUp,#KeyPageUp)
    AddKeyboardShortcut(1,#PB_Shortcut_Tab,#TAB) ;<<--- prevent User from using the TAB Key
    AddKeyboardShortcut(1,#PB_Shortcut_F1,#F1)   ;<<--- F1 = Help Key for Gadgets in Window 1

    StringGadget(#Dummy_Focus,-10,-10,5,5,"",#PB_Text_Center)

    Protected.i CT1 = ContainerGadget(#PB_Any, 4, 4, 618, 87, #PB_Container_Raised)
                      SetGadgetColor(CT1, #PB_Gadget_BackColor,RGB(210,210,210))

      Protected.i TX1 = TextGadget(#PB_Any, 2, 1, 200, 22, " ET Factor Calculator")
      SetGadgetColor(TX1, #PB_Gadget_FrontColor,RGB(0,0,150))
      SetGadgetColor(TX1, #PB_Gadget_BackColor,RGB(210,210,210))
      SetGadgetFont(TX1, FontID(#Verdana11bi))
                     
      Protected.i T1 = TextGadget(#PB_Any, 2, 25, 90, 18, " Initial Distance")
      SetGadgetColor(T1, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(T1, #PB_Gadget_BackColor,RGB(245,245,245))
      SetGadgetFont(T1, FontID(#Tahoma10))
      Global.i G1 = 1 : StringGadget(G1, 92, 24, 110, 20, "",#PB_Text_Center)
      SetGadgetColor(G1, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(G1, #PB_Gadget_BackColor,RGB(255,255,255))
      SetGadgetFont(G1, FontID(#Verdana9))
      Min(G1)= 60 : Max(G1)= 1320 : MinM(G1)= Min(G1) : MaxM(G1)= Max(G1) : MaxLen(G1)= Len("1320.0") : Dec(G1)= 1
                     
      Protected.i T2 = TextGadget(#PB_Any, 206, 25, 90, 18, " Initial ET")
      SetGadgetColor(T2, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(T2, #PB_Gadget_BackColor,RGB(245,245,245))
      SetGadgetFont(T2, FontID(#Tahoma10))
      Global.i G2 = 2 : StringGadget(G2, 296, 24, 110, 20, "",#PB_Text_Center)
      SetGadgetColor(G2, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(G2, #PB_Gadget_BackColor,RGB(255,255,255))
      SetGadgetFont(G2, FontID(#Verdana9))
      Min(G2)= 0.75 : Max(G2)= 40 : MinM(G2)= Min(G2) : MaxM(G2)= Max(G2) : MaxLen(G2)= Len("40.00000000") : Dec(G2)= 8
                     
      Protected.i T3 = TextGadget(#PB_Any, 410, 25, 90, 18, " Initial MPH")
      SetGadgetColor(T3, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(T3, #PB_Gadget_BackColor,RGB(245,245,245))
      SetGadgetFont(T3, FontID(#Tahoma10))
      Global.i G3 = 3 : StringGadget(G3, 500, 24, 110, 20, "",#PB_Text_Center)
      SetGadgetColor(G3, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(G3, #PB_Gadget_BackColor,RGB(255,255,255))
      SetGadgetFont(G3, FontID(#Verdana9))
      Min(G3)= 30 : Max(G3)= 400 : MinM(G3)= Min(G3) : MaxM(G3)= Max(G3) : MaxLen(G3)= Len("400.00000000") : Dec(G3)= 8
                     
      Protected.i T4 = TextGadget(#PB_Any, 2, 45, 90, 18, " Final Distance")
      SetGadgetColor(T4, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(T4, #PB_Gadget_BackColor,RGB(245,245,245))
      SetGadgetFont(T4, FontID(#Tahoma10))
      Global.i G4 = 4 : StringGadget(G4, 92, 44, 110, 20, "",#PB_Text_Center)
      SetGadgetColor(G4, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(G4, #PB_Gadget_BackColor,RGB(255,255,255))
      SetGadgetFont(G4, FontID(#Verdana9))
      Min(G4)= 330 : Max(G4)= 1320 : MinM(G4)= Min(G4) : MaxM(G4)= Max(G4) : MaxLen(G4)= Len("1320.0") : Dec(G4)= 1
                     
      Protected.i T5 = TextGadget(#PB_Any, 206, 45, 90, 18, " Final ET")
      SetGadgetColor(T5, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(T5, #PB_Gadget_BackColor,RGB(245,245,245))
      SetGadgetFont(T5, FontID(#Tahoma10))
      Global.i G5 = 5 : StringGadget(G5, 296, 44, 110, 20, "",#PB_Text_Center)
      SetGadgetColor(G5, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(G5, #PB_Gadget_BackColor,RGB(255,255,255))
      SetGadgetFont(G5, FontID(#Verdana9))
      Min(G5)= 3.85 : Max(G5)= 40 : MinM(G5)= Min(G5) : MaxM(G5)= Max(G5) : MaxLen(G5)= Len("40.00000000") : Dec(G5)= 8
                     
      Protected.i TX2 = TextGadget(#PB_Any, 410, 45, 90, 18, " ET Factor")
      SetGadgetColor(TX2, #PB_Gadget_FrontColor,RGB(0,0,150))
      SetGadgetColor(TX2, #PB_Gadget_BackColor,RGB(245,245,245))
      SetGadgetFont(TX2, FontID(#Verdana10b))
      Global.i G6 = 6 : StringGadget(G6, 500, 44, 110, 20, "",#PB_Text_Center | #PB_String_ReadOnly)
      SetGadgetColor(G6, #PB_Gadget_FrontColor,RGB(0,0,0))
      SetGadgetColor(G6, #PB_Gadget_BackColor,RGB(255,255,255))
      SetGadgetFont(G6, FontID(#Verdana9))
      MaxLen(G6)= Len("0.0000000000") : Dec(G6)= 10

      For Cnt = G1 To G6 ;<<--- at start of program , populate all the StringGadgets with blank data
          SetGadgetAttribute(Cnt,#PB_String_MaximumLength,MaxLen(Cnt))
          SetGadgetText(Cnt,"")
      Next
      SetActiveGadget(1)
    CloseGadgetList() ;<<--- close CT1
EndProcedure


OpenW1() ;<<--- start program


Repeat
  EW = EventWindow()     ;<<--- In Programs with more than one Form or Window, which Window did the Event occur on.
  WW = WaitWindowEvent() ;<<--- Wait until a new Window or Gadget Event occurs.
  EG = EventGadget()     ;<<--- Which Gadget did the Event occur on. ( Numerical Number or Constant #Name of the Gadget )
  ET = EventType()       ;<<--- What sort of Event Type occurred.( #PB_EventType_Focus , #PB_EventType_Change , #PB_EventType_LostFocus )
  EM = EventMenu()       ;<<--- Which Menu did the Event occur on.( #KeyPageDown , #KeyReturn , #KeyPageUp , #KeyEscape , #F1 to #F12 Keys )
  AG = GetActiveGadget() ;<<--- Get the Active Gadget's Numerical Number or Constant #Name that has the current Focus

  Select WW
  Case #PB_Event_CloseWindow : End  ;<<--- Quit or End Program

  Case #PB_Event_Menu
       Select EventMenu()
       Case 0 : End
       Case 1 : ETFactor()
       Case 2 : Clear()

  Case #KeyPageDown , #KeyReturn ;------ move Downward or Forward thru inputs
       Select AG
       Case #Dummy_Focus : SetActiveGadget(G1)
       Case G1 To (G5 - 1) : SetActiveGadget(AG + 1)
       Case G5 : SetActiveGadget(G1)
       EndSelect
  Case #KeyPageUp , #KeyEscape   ;------ move Upward or Backward thru inputs
       Select AG
       Case #Dummy_Focus : SetActiveGadget(G1)
       Case G1 : SetActiveGadget(G5)
       Case (G1 + 1) To G5 : SetActiveGadget(AG - 1)
       EndSelect
  Case #F1 ;-[ #F1 = 10112 call Help ]
       Select AG
       Case G1 To G6: MessageRequester("Program Help","#F1 Key Pressed at [ Gadget # " + AG + " ]")
       EndSelect
  EndSelect

  Case #PB_Event_Gadget
       Select EventGadget()
       Case G1 To G5 : StringInput()
       Case G6 : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
       EndSelect
  EndSelect
Until WW = #PB_Event_CloseWindow : End



; Declare Clear()
Procedure Clear()
    For Cnt = G1 To G6
        SetGadgetText(Cnt,"")
        SetActiveGadget(Cnt)
    Next
    SetActiveGadget(G1)
EndProcedure



; Declare ComboERROR()
Procedure ComboERROR()
    ;~~~~~~~~~~ Result = MessageRequester(Title,Text,[Flags]) ;~~~~~~~~~~ 2= CANCEL  6= YES  7= NO
    ;~~~~~~~~~~ Flag = #PB_MessageRequester_Ok                ;~~~~~~~~~~ 'OK' only one button (Standard)
    ;~~~~~~~~~~ Flag = #PB_MessageRequester_YesNo             ;~~~~~~~~~~ 'YES' or 'NO' buttons
    ;~~~~~~~~~~ Flag = #PB_MessageRequester_YesNoCancel       ;~~~~~~~~~~ 'YES', 'NO' and 'CANCEL' buttons
    Title = "ERROR  :   Invalid  Keyboard  Key  Pressed"; + Space(5)
    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 ComboInput()
Procedure ComboInput()
    Select EventType()
    Case #PB_EventType_Focus
         cFlag = GetGadgetState(EG)
         ;Help(EG)

    Case #PB_EventType_Change
         DirtyC = 1 ;<<--- set only the User's ComboBoxGadgets to Dirty if they change a ComboBoxGadget choice

         If GetGadgetState(EG) <> -1 : cFlag = GetGadgetState(EG) : SetGadgetState(EG,cFlag) : EndIf
         If GetGadgetState(EG) = -1 : SetGadgetState(EG,cFlag) : ComboERROR() : EndIf

    Case #PB_EventType_LostFocus

    EndSelect
EndProcedure



; Declare StringERROR()
Procedure StringERROR()
    ;~~~~~~~~~~ Result = MessageRequester(Title,Text,[Flags]) ;~~~~~~~~~~ 2= CANCEL  6= YES  7= NO
    ;~~~~~~~~~~ Flag = #PB_MessageRequester_Ok                ;~~~~~~~~~~ 'OK' only one button (Standard)
    ;~~~~~~~~~~ Flag = #PB_MessageRequester_YesNo             ;~~~~~~~~~~ 'YES' or 'NO' buttons
    ;~~~~~~~~~~ Flag = #PB_MessageRequester_YesNoCancel       ;~~~~~~~~~~ 'YES', 'NO' and 'CANCEL' buttons
    Title = "ERROR  :  Input  not  within  the  Valid  Range"
    Text = "Input value is not within the minimum to maximum allowed range ...." + #CRLF$ + #CRLF$ +
           "Please enter a Value within the Valid Range"
    MessageRequester(Title,Text,#PB_MessageRequester_Ok)
EndProcedure



; Declare StringInput()
Procedure StringInput()
    Units = 0
    Select EventType()
    Case #PB_EventType_Focus
         SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
         ;Help(EG) ;<<--- call Help Procedure to display Help text for each User's input or choice
         Select Units
         Case 0 ;~~~~~ English Units
              Var(EG) = ValD(GetGadgetText(EG))
         Case 1 ;~~~~~ Metric Units
              VarM(EG) = ValD(GetGadgetText(EG))
         EndSelect

    Case #PB_EventType_Change
         Select Units
         Case 0 ;~~~~~ English Units
              Var(EG) = ValD(GetGadgetText(EG))
              If Var(EG) > Max(EG)
                 StringERROR()
                 SetGadgetText(EG,"")
                 SetActiveGadget(EG)
              EndIf
         Case 1 ;~~~~~ Metric Units
              VarM(EG) = ValD(GetGadgetText(EG))
              If VarM(EG) > MaxM(EG)
                 StringERROR()
                 SetGadgetText(EG,"")
                 SetActiveGadget(EG)
              EndIf
         EndSelect
      
         SetGadgetText(G6,"")
      
         Select EG
         Case G1 To G5 : DirtyS = 1 ;<<--- set only the User's StringGadgets to Dirty if they change a StringGadget value
         EndSelect
      
    Case #PB_EventType_LostFocus
         Select Units
         Case 0 ;~~~~~ English Units
              Var(EG) = ValD(GetGadgetText(EG))
              If Var(EG) >= Min(EG) And Var(EG) <= Max(EG)
                 SetGadgetText(EG,StrD(Var(EG),Dec(EG)))
              Else
                 SetGadgetText(EG,"")
              EndIf
         Case 1 ;~~~~~ Metric Units
              VarM(EG) = ValD(GetGadgetText(EG))
              If VarM(EG) >= MinM(EG) And VarM(EG) <= MaxM(EG)
                 SetGadgetText(EG,StrD(VarM(EG),Dec(EG)))
              Else
                 SetGadgetText(EG,"")
              EndIf
         EndSelect
    EndSelect
EndProcedure



; Declare ETFactor()
Procedure ETFactor()
    Protected.d ETFactor

    SetGadgetText(G6,"")
    SetActiveGadget(#Dummy_Focus)

    ;====== make sure all Inputs have Valid Range Values
    Select Units
    Case 0 ;~~~~~ English Units
         For Cnt = G1 To G5
             If Var(Cnt) < Min(Cnt)
                SetGadgetText(Cnt,"")
                SetActiveGadget(Cnt) ;<<--- sets Focus to the Gadget that has an invalid value
                StringERROR()         
                ProcedureReturn ;<<--- exits the ETFactor() Procedure without calculating anything if User did not enter all valid input values
             EndIf
         Next Cnt
    Case 1 ;~~~~~ Metric Units
         For Cnt = G1 To G5
             If VarM(Cnt) < MinM(Cnt)
                SetGadgetText(Cnt,"")
                SetActiveGadget(Cnt) ;<<--- sets Focus to the Gadget that has an invalid value
                StringERROR()         
                ProcedureReturn ;<<--- exits the ETFactor() Procedure without calculating anything if User did not enter all valid input values
             EndIf
         Next Cnt
    EndSelect

    ETFactor = ((Var(G5) - Var(G2)) * Var(G3)) / (Var(G4) - Var(G1))
    SetGadgetText(G6,StrD(ETFactor,Dec(G6)))
EndProcedure


 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
Post Reply