Jump to content

Looking for MM to Inch (fraction) conveter.


veda2010
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

veda2010,

Welcome to the AutoIt forums. :)

Here is a simple example which should get you started: ;)

#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

WEnd
As 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I modified M23's example to display the result as fraction.

#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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Moderators

veda2010,

Those ternary operators were introduced in v3.3.10.0 - what version are you running? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...