Small Problem

Just starting out? Need help? Post your questions and find answers here.
Antdizzle
User
User
Posts: 21
Joined: Sun Mar 28, 2004 2:38 am
Location: United States
Contact:

Small Problem

Post by Antdizzle »

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?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sounds straight forward enough.

Best if you post some code just to make sure I understand what it is you're after.

{Sounds like you simply need to use the Val() of ValF() functions.}
I may look like a mule, but I'm not a complete ass.
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Re: Small Problem

Post by Max. »

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
Antdizzle
User
User
Posts: 21
Joined: Sun Mar 28, 2004 2:38 am
Location: United States
Contact:

Post by Antdizzle »

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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I can only gues as to the significance of the option boxes, but:

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))
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.
I may look like a mule, but I'm not a complete ass.
Antdizzle
User
User
Posts: 21
Joined: Sun Mar 28, 2004 2:38 am
Location: United States
Contact:

Post by Antdizzle »

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.
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

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.
Did you have the Debugger enabled? If yes, then that bit of code should get you have gotten you the desired output.

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 
Edit: reworded first sentence; the meaning got screwed.
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
Antdizzle
User
User
Posts: 21
Joined: Sun Mar 28, 2004 2:38 am
Location: United States
Contact:

Post by Antdizzle »

Thanks a lot, that is exactly what I needed. :D
Post Reply