Small Problem
Small Problem
Right now I am making a converter that will convert numbers between imperial and metric.  I have a problem.  I want to check and see if two options are checked, there is a number in a string box, and the 'convert' button is pressed. Then I need to multiply the number in the string box and put it into another string box. How would I be able to check this?
			
			
									
									
						Re: Small Problem
Antdizzle wrote:Right now I am making a converter that will convert numbers between imperial and metric. I have a problem. I want to check and see if two options are checked, there is a number in a string box, and the 'convert' button is pressed. Then I need to multiply the number in the string box and put it into another string box. How would I be able to check this?
Code: Select all
; PureBasic Visual Designer v3.90 build 1360
Enumeration
  #Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
  #String_0
  #CheckBox_0
  #CheckBox_1
  #Button_0
EndEnumeration
Procedure Open_Window_0()
  If OpenWindow(#Window_0, 430, 293, 228, 39,  #PB_Window_SystemMenu | #PB_Window_TitleBar , "")
    If CreateGadgetList(WindowID())
      StringGadget(#String_0, 10, 10, 90, 20, "")
      CheckBoxGadget(#CheckBox_0, 110, 10, 20, 20, "")
      CheckBoxGadget(#CheckBox_1, 130, 10, 20, 20, "")
      ButtonGadget(#Button_0, 150, 10, 70, 20, "Convert")
      
    EndIf
  EndIf
EndProcedure
Open_Window_0()
Repeat
  
  Event = WaitWindowEvent()
  
  If Event = #PB_EventGadget
    
    ;Debug "WindowID: " + Str(EventWindowID())
    
    GadgetID = EventGadgetID()
    
    If GadgetID = #String_0
      
    ElseIf GadgetID = #CheckBox_0
    ElseIf GadgetID = #CheckBox_1
      
    ElseIf GadgetID = #Button_0
      
      Debug "----"
      Debug "GadgetID: #String_0"
      Debug " "+GetGadgetText(#String_0)
      Debug "GadgetID: #CheckBox_0"
      Debug " "+Str(GetGadgetState(#Checkbox_0))
      Debug "GadgetID: #CheckBox_0"
      Debug " "+Str(GetGadgetState(#Checkbox_1))
            
    EndIf
    
  EndIf
  
Until Event = #PB_EventCloseWindow
End
;Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
						Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
Well I couldn't get that to work with my code.  I need something that will check and see if 4 things are true(a number in the string gadget, a option box on one side, another option box on another side, and the convert button has been pressed), then I need to take the number from the string gadget, convert it to a float, multiply it by the conversion number, convert it back into a string and then send that number to another string box.
			
			
									
									
						I can only gues as to the significance of the option boxes, but:
As to checking that the first string gadget, contains a number, someone posted a little routine (fweil I think) previously which does a good job of checking.
			
			
									
									Code: Select all
;GET NUMBER FROM STRING GADGET 1
Number1.f = ValF(GetGadgetText(#StringGad1))Code: Select all
;MULTIPLY BY CONVERSION
Number1 = Number1 * 2.5;  E.g. inches to cm.Code: Select all
;SEND NUMBER TO ANOTHER STRING GADGET
SetGadgetText(#StringGad2, StrF(Number1))I may look like a mule, but I'm not a complete ass.
						Did you have the Debugger enabled? If yes, then that bit of code should get you have gotten you the desired output.Antdizzle wrote:Well I still haven't been able to figure out how to do this. All I have right now is the visual part of the converter.
The following does very simple currency conversion. #Checkbox_0 is the option for the conversion direction (USD/EUR, EUR/USD).
#Checkbox_1 is a switch if you want to reverse the direction (i.e. #Checkbox_0) after the operation.
Just remember what you initially did input to the string gadget and play with the options; you will see what I mean.
Code: Select all
; PureBasic Visual Designer v3.90 build 1360 
Enumeration 
  #Window_0 
EndEnumeration 
;- Gadget Constants 
; 
Enumeration 
  #String_0 
  #CheckBox_0 
  #CheckBox_1 
  #Button_0 
EndEnumeration 
Procedure Open_Window_0() 
  If OpenWindow(#Window_0, 430, 293, 228, 39,  #PB_Window_SystemMenu | #PB_Window_TitleBar , "") 
    If CreateGadgetList(WindowID()) 
      StringGadget(#String_0, 10, 10, 90, 20, "") 
      CheckBoxGadget(#CheckBox_0, 110, 10, 20, 20, "") 
      CheckBoxGadget(#CheckBox_1, 130, 10, 20, 20, "") 
      ButtonGadget(#Button_0, 150, 10, 70, 20, "Convert") 
      
    EndIf 
  EndIf 
EndProcedure 
Open_Window_0() 
Repeat 
  
  Event = WaitWindowEvent() 
  
  If Event = #PB_EventGadget 
    
    ;Debug "WindowID: " + Str(EventWindowID()) 
    
    GadgetID = EventGadgetID() 
    
    If GadgetID = #String_0 
      
    ElseIf GadgetID = #CheckBox_0 
    ElseIf GadgetID = #CheckBox_1 
      
    ElseIf GadgetID = #Button_0 
      
     OneEuroIsInUSD.f = 1.11
      MoneyEntered.f = ValF(GetGadgetText(#String_0))
 
      IsCheckbox0_Checked = GetGadgetState(#Checkbox_0) 
      IsCheckbox1_Checked = GetGadgetState(#Checkbox_1) 
      
      If MoneyEntered.f<>0
        ;CheckBox0 checked means conversion from USD to EURO
        Text.s=StrF(MoneyEntered,2)
        If IsCheckbox0_Checked = 0
          MoneyConverted.f = MoneyEntered.f * OneEuroIsInUSD.f
          Text.s = Text+" EURO in USD is "
        Else
          ;CheckBox0 not checked, thus EURO to USD
          MoneyConverted.f = MoneyEntered.f / OneEuroIsInUSD.f
          Text.s = Text+" USD in EURO is "
        EndIf
        
        Text.s = Text.s + StrF(MoneyConverted.f,2)
        Result = MessageRequester("Currency conversion",Text.s,#PB_MessageRequester_Ok )
      
        ;Checkbox1 checked means you want the output to be in the String gadget and inverse the calculation
        If IsCheckbox1_Checked = 1
          SetGadgetText(#String_0,StrF(MoneyConverted.f,2))
          If IsCheckbox0_Checked = 1
            SetGadgetState(#Checkbox_0,0)
          Else
            SetGadgetState(#Checkbox_0,1)
          endif
        EndIf
            
      EndIf 
    
    EndIf
  
  EndIf  
 
  
Until Event = #PB_EventCloseWindow 
End 
					Last edited by Max. on Mon Jul 26, 2004 8:47 am, edited 1 time in total.
									
			
									Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
						Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0


