veda2010 Posted April 13, 2015 Posted April 13, 2015 Hello Everyone. This is Veda, First of all, i'm not familiar with AutoIt tool. I heard about this in internet about Automation of few tasks, Apps, etc. I am looking for a some tool to show the MM to Inch conversion in Fractions. Can anyone help me with this? It would be better if there is GUI converter for this. Example: 20.63 MM = 13/16" Thanks Veda
Moderators Melba23 Posted April 13, 2015 Moderators Posted April 13, 2015 veda2010,Welcome to the AutoIt forums. Here is a simple example which should get you started: expandcollapse popup#include <GUIConstantsEx.au3> ; Create a GUI $hGUI = GUICreate("Test", 500, 500) ; Create a couple of inputs GUICtrlCreateLabel("Inches", 10, 20, 200, 30) $cInches = GUICtrlCreateInput("", 10, 50, 200, 40) GUICtrlSetFont($cInches, 24) GUICtrlCreateLabel("Millimetres", 10, 120, 200, 30) $cMilli = GUICtrlCreateInput("", 10, 150, 200, 40) GUICtrlSetFont($cMilli, 24) ; And a couple of buttons $cConvert = GUICtrlCreateButton("Convert", 10, 300, 80, 30) $cClear = GUICtrlCreateButton("Clear", 200, 300, 80, 30) GUISetState() While 1 ; Look for an event to occur Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Close [X] Exit Case $cClear ; Clear button ; So empty the inputs GUICtrlSetData($cInches, "") GUICtrlSetData($cMilli, "") Case $cConvert ; Convert button ; If there is something in the "inches" input If GUICtrlRead($cInches) <> "" Then ; Convert it to mm and display the result $nMM = Number(GUICtrlRead($cInches)) * 254 GUICtrlSetData($cMilli, $nMM) Else ; We need to convert mm to inches $nInches = Round(GUICtrlRead($cMilli) / 254, 5) GUICtrlSetData($cInches, $nInches) EndIf EndSwitch WEndAs you say you are new to AutoIt (and no problem there because we all were at some time) reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at this excellent tutorial - you will find other tutorials in the Wiki (the link is at the top of the page). M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
UEZ Posted April 13, 2015 Posted April 13, 2015 I modified M23's example to display the result as fraction. expandcollapse popup#include <GUIConstantsEx.au3> ; Create a GUI $hGUI = GUICreate("Test", 500, 500) ; Create a couple of inputs GUICtrlCreateLabel("Inches", 10, 20, 200, 30) $cInches = GUICtrlCreateInput("", 10, 50, 400, 40) GUICtrlSetFont($cInches, 24) GUICtrlCreateLabel("Millimetres", 10, 120, 200, 30) $cMilli = GUICtrlCreateInput("", 10, 150, 400, 40) GUICtrlSetFont($cMilli, 24) ; And a couple of buttons $cConvert = GUICtrlCreateButton("Convert", 10, 300, 80, 30) $cClear = GUICtrlCreateButton("Clear", 200, 300, 80, 30) GUISetState() While 1 ; Look for an event to occur Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Close [X] Exit Case $cClear ; Clear button ; So empty the inputs GUICtrlSetData($cInches, "") GUICtrlSetData($cMilli, "") Case $cConvert ; Convert button ; If there is something in the "inches" input If GUICtrlRead($cInches) <> "" Then ; Convert it to mm and display the result $nMM = Number(GUICtrlRead($cInches)) * 254 GUICtrlSetData($cMilli, Float2Frac($nMM)) GUICtrlSetTip($cMilli, $nMM) Else ; We need to convert mm to inches $nInches = Round(GUICtrlRead($cMilli) / 254, 5) GUICtrlSetData($cInches, Float2Frac($nInches)) GUICtrlSetTip($cInches, $nInches) EndIf EndSwitch WEnd Func Float2Frac($fFloat, $iAccuracy = 5) ;coded by UEZ If Not IsNumber($fFloat) Then Return SetError(1, 0, 0) Local $iDec = StringLen(StringRegExpReplace($fFloat, "\d+\.(\d*)", "\1")) $iAccuracy = $iAccuracy > 10 ? 10 : $iAccuracy $iDec = $iDec > $iAccuracy ? $iAccuracy : $iDec Local $iZaehler = Round($fFloat * 10 ^ $iDec, 0) Local $iNenner = 10 ^ $iDec Local $iGGT = Number(ggT(Int($iZaehler), Int($iNenner))) ConsoleWrite("Float: " & $fFloat & @CRLF) ConsoleWrite("Dec: " & $iDec & @CRLF) ConsoleWrite("Zaehler: " & $iZaehler & @CRLF) ConsoleWrite("Nenner: " & $iNenner & @CRLF) ConsoleWrite("$iGGT: " & $iGGT & @CRLF) ConsoleWrite($fFloat & " -> " & $iZaehler / $iGGT & " / " & $iNenner / $iGGT & @CRLF & @CRLF) If $iGGT < 0 Then $iZaehler /= $iGGT * -1 $iNenner /= $iGGT * -1 Else $iZaehler /= $iGGT $iNenner /= $iGGT EndIf Return $iZaehler & " / " & $iNenner EndFunc ;==>Float2Frac Func ggT($a, $b) ;coded by UEZ 2012 If Not IsInt($a) Then Return SetError(1, 0, 0) If Not IsInt($b) Then Return SetError(2, 0, 0) If $a = $b Then Return Abs($a) If Not $a And $b Then Return Abs($a) If $a And Not $b Then Return Abs($b) If ($a And $b = 1) Or ($a = 1 And $b) Then Return 1 Local $iMod Do $iMod = Mod($a, $b) If Not $iMod Then ExitLoop $a = $b $b = $iMod Until False Return $b EndFunc Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
veda2010 Posted April 13, 2015 Author Posted April 13, 2015 Thanks for the quick response M23 & UEZ. I was trying to run the script and it says some error Error Message $iAccuracy= $iAccuracy>10 ? 10 : $iAccuracy $iAccuracy = $iAccuracy > 10 ^ ERROR
Moderators Melba23 Posted April 13, 2015 Moderators Posted April 13, 2015 veda2010,Those ternary operators were introduced in v3.3.10.0 - what version are you running? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
veda2010 Posted April 13, 2015 Author Posted April 13, 2015 I'm using Version 3.3.8.1 let me try with new version. Thanks Veda
veda2010 Posted April 15, 2015 Author Posted April 15, 2015 (edited) Thanks again UEZ. & M23. I tried with latest version (v3.3.12) and the code working fine. Thanks Veda Edited April 15, 2015 by veda2010
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now