Page 1 of 1
Small Problem
Posted: Sun Jul 25, 2004 10:59 pm
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?
Posted: Sun Jul 25, 2004 11:06 pm
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.}
Re: Small Problem
Posted: Sun Jul 25, 2004 11:07 pm
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
;
Posted: Sun Jul 25, 2004 11:29 pm
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.
Posted: Sun Jul 25, 2004 11:41 pm
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.
Posted: Mon Jul 26, 2004 6:36 am
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.
Posted: Mon Jul 26, 2004 8:31 am
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.
Posted: Mon Jul 26, 2004 8:43 am
by Antdizzle
Thanks a lot, that is exactly what I needed.
