Temp. Converter

Recommended Posts

I am creating a Fahrenheit and Celsius converter and am having some trouble. Before anyone asks, I know I can download one, I am only doing this for the challenge, and to learn more about using GUIs in autoit.

here's my script

CODE

Local \$FtoC, \$IF, \$IC, \$RF, \$RC, \$IFD, \$ICD

\$FtoC = Number (2)

\$IF = GUICtrlCreateInput (\$IFD, 6, 17)

\$IC = GUICtrlCreateInput (\$ICD, 6, 55)

\$IFD = Number (0)

\$ICD = Number (0)

GUICreate ("F&C", 130, 140)

GUISetState (@SW_SHOW)

GUICtrlCreateRadio ("Fahrenheit to Celsius", 5, 120)

GUICtrlSetOnEvent (-1, "FtoC")

GUICtrlCreateRadio ("Celsius to Fahrenheit", 5, 100)

GUICtrlSetOnEvent (-1, "CtoF")

GUICtrlCreateInput (\$IFD, 6, 17)

GUICtrlCreateInput (\$ICD, 6, 55)

GUICtrlCreateLabel ("Fahrenheit", 6, 2)

GUICtrlCreateLabel ("Celsius", 6, 40)

GUICtrlCreateButton("Convert", 5, 78, 120)

GUICtrlSetOnEvent (-1, "ConvertPressed")

Opt ("guioneventmode", 1)

While 1 = 1

Sleep (100)

WEnd

Func FtoC ()

\$FtoC = Number (1)

EndFunc

Func CtoF ()

\$FtoC = Number (0)

EndFunc

Func ConvertPressed ()

If \$FtoC = Number (1) Then

\$ICD = Number ((5/9)*(\$RF-32))

GUICtrlSetData (6, \$ICD)

EndIf

If \$FtoC = Number (0) Then

\$IFD = Number ((9/5)*\$RC+32)

GUICtrlSetData (5, \$IFD)

EndIf

EndFunc

It always shows the same numbers when I click convert. I don't know why.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share on other sites

Local \$FtoC, \$IF, \$IC, \$RF, \$RC, \$IFD, \$ICD Is all wrong. Just comment it out. \$FtoC, \$IF, \$IC, \$RF, \$RC will all be declared globally and the rest will be declared locally inside the functions that use them so you don't need that line at all.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share on other sites

Local \$FtoC, \$IF, \$IC, \$RF, \$RC, \$IFD, \$ICD Is all wrong. Just comment it out. \$FtoC, \$IF, \$IC, \$RF, \$RC will all be declared globally and the rest will be declared locally inside the functions that use them so you don't need that line at all.

I think thats what I tried first, but when I tried running it came up with an error that said that there was a variable used without being declared.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share on other sites

Hi and Thank You,

I wondered what the maths was to convert between Celsius and Fahrenheit.

(As I'm practically maths illiterate.. lol)

```#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Opt ("guioneventmode", 1)

\$hGui = GUICreate ("F&C", 130, 145)
GUISetOnEvent(\$GUI_EVENT_CLOSE, "Event", \$hGui)
GUICtrlCreateLabel("Temperature to Convert", 5, 5, 120, 15)
\$Input = GUICtrlCreateInput("", 5, 20, 120, 20, \$ES_NUMBER)
\$F2C = GUICtrlCreateRadio ("Fahrenheit to Celsius", 5, 45, 120, 15)
GUICtrlSetOnEvent (-1, "Event")
GUICtrlSetState(-1, \$GUI_CHECKED)
\$C2F = GUICtrlCreateRadio ("Celsius to Fahrenheit", 5, 60, 120, 15)
GUICtrlSetOnEvent (-1, "Event")
GUICtrlCreateLabel ("Converted Temperature", 5, 80, 120, 15)
\$Output = GUICtrlCreateInput("", 5, 95, 120, 20, \$ES_READONLY)
GUICtrlSetBkColor(-1, 0xFFFFFF)
\$Convert = GUICtrlCreateButton("Convert", 5, 120, 120, 20)
GUICtrlSetOnEvent (-1, "Event")
GUISetState (@SW_SHOW, \$hGui)

While 1
Sleep (100)
WEnd

Func Event()
Switch @GUI_CtrlId
Case \$GUI_EVENT_CLOSE
Exit
Case \$Convert
If GUICtrlRead(\$Input) = "" Then Return
Else
EndIf
EndSwitch
EndFunc```

Cheers

Edit: I think I'm also english illiterate as well, corrected some of my spelling

Edited by smashly

Share on other sites

Thanks here too!

I did not know that calculation

8)

Share on other sites

Hi and Thank You,

I wondered what the maths was to convert between Celsius and Fahrenheit.

(As I'm practically maths illiterate.. lol)

```#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Opt ("guioneventmode", 1)

\$hGui = GUICreate ("F&C", 130, 145)
GUISetOnEvent(\$GUI_EVENT_CLOSE, "Event", \$hGui)
GUICtrlCreateLabel("Temperature to Convert", 5, 5, 120, 15)
\$Input = GUICtrlCreateInput("", 5, 20, 120, 20, \$ES_NUMBER)
\$F2C = GUICtrlCreateRadio ("Fahrenheit to Celsius", 5, 45, 120, 15)
GUICtrlSetOnEvent (-1, "Event")
GUICtrlSetState(-1, \$GUI_CHECKED)
\$C2F = GUICtrlCreateRadio ("Celsius to Fahrenheit", 5, 60, 120, 15)
GUICtrlSetOnEvent (-1, "Event")
GUICtrlCreateLabel ("Converted Temperature", 5, 80, 120, 15)
\$Output = GUICtrlCreateInput("", 5, 95, 120, 20, \$ES_READONLY)
GUICtrlSetBkColor(-1, 0xFFFFFF)
\$Convert = GUICtrlCreateButton("Convert", 5, 120, 120, 20)
GUICtrlSetOnEvent (-1, "Event")
GUISetState (@SW_SHOW, \$hGui)

While 1
Sleep (100)
WEnd

Func Event()
Switch @GUI_CtrlId
Case \$GUI_EVENT_CLOSE
Exit
Case \$Convert
If GUICtrlRead(\$Input) = "" Then Return
Else
EndIf
EndSwitch
EndFunc```

Cheers

Edit: I think I'm also english illiterate as well, corrected some of my spelling

Thanks for fixing my script. Although I've been writing scripts for a while, this is the first time I've used a GUI.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Create an account

Register a new account