Jump to content

A converter?


Recommended Posts

Hello, I recently started to script in autoit again, and I'm making a kind of tool. Is it possible to make an inputbox, and if you write

H and press on ok, it'll say Z

I and press on ok, it'll say O

If you write there HI, it'll say ZO.

Is that possible? Thanks already

Link to comment
Share on other sites

Yes sure should be no problem.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

lawonama,

Is that possible?

Yes. :)

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

Post what you have so far. Did you create the GUI with the input box and OK button yet? We are not going to write your script for you. To get help you need to tell us how far along you are and exactly what you are stuck on.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region  Form=
$Form1 = GUICreate("HumanGhoul Translator", 487, 226, 192, 124)
$Input1 = GUICtrlCreateInput("", 8, 72, 465, 50)
$Button1 = GUICtrlCreateButton("Translate!", 176, 128, 137, 89, $WS_GROUP)
$text1 = GUICtrlCreateLabel("Human > Ghoul.", 208, 8, 81, 17)
$Text2 = GUICtrlCreateLabel("Please insert your text here:", 184, 48, 134, 17)
GUISetState(@SW_SHOW)
#EndRegion
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    GUIDelete()
    ;Exit the script
    Exit
   Case $msg = $Button1
    MsgBox(64, "Ghoul Language", "The script")
  EndSelect
WEnd

This is my code so far, and where it says "The script" it needs to transform.

In example: If you wrote in the inputbox :

"TEST" and you press on the OK button, it says "RANDOMTEXT"

"HELLO" and you press on the OK button, it says "TheSecondRandomText"

Edited by lawonama
Link to comment
Share on other sites

Here's a tweak to put the transcription in a function:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Form1, $Input1, $Button1, $text1, $Text2
#region  Form
$Form1 = GUICreate("HumanGhoul Translator", 487, 226, 192, 124)
$Input1 = GUICtrlCreateInput("", 8, 72, 465, 50)
$Button1 = GUICtrlCreateButton("Translate!", 176, 128, 137, 89, $WS_GROUP)
$text1 = GUICtrlCreateLabel("Human > Ghoul.", 208, 8, 81, 17)
$Text2 = GUICtrlCreateLabel("Please insert your text here:", 184, 48, 134, 17)
GUISetState(@SW_SHOW)
#endregion  Form
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   GUIDelete()
   ;Exit the script
   Exit
  Case $msg = $Button1
   MsgBox(64, "Ghoul Language", _Transcribe())
EndSelect
WEnd
; Returns transcribed text
Func _Transcribe()
Local $sInput, $sOutput
$sInput = GUICtrlRead($Input1)
$sOutput = StringUpper($sInput) ;  <---  Apply your transcription rules here
Return $sOutput
EndFunc

Edit the function to take the $sInput string variable and apply all your transcription rules to it. How best to apply those rules depends on how many there are and how complex they are. In this simple example, all it does is make the string all upper case.

How many rules are there, and how complex are they?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I already made it on my own, thanks tho.

Got another question, i have:

While 1
$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit

Case $msg = $Button1
If $Input1 <> "a" Then
MsgBox(4096, "Translator", "b")
ElseIf $Input1 <> "b" Then
MsgBox(4096, "Translator", "c")
Endif

EndSelect

WEnd

When I write A, the inputbox says B

When I write B, the inputbox says C

But when I write AB, the inputbox says only B instead of BC. How to fix this without adding AB > BC to the list?

Link to comment
Share on other sites

  • Moderators

lawonama,

Use StringSplit to separate the letters into an array. Then loop through the array and action each letter. Finally use _ArrayToString to put it back into string form and rewrite it to the input. :)

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

  • Moderators

lawonama,

And what about trying to code something yourself to see how the various functions work? Do you want it all on a plate? Where is the fun in that? :)

But if you do get stuck then take a look here: ;)

#include <Array.au3>

; Here is the text
$sText = "ABCDEF"

; Which we split
$aText = StringSplit($sText, "")

; Like this
_ArrayDisplay($aText)

; Now we loop through the letters
For $i = 1 To $aText[0]

    ; And move each letter one up
    $aText[$i] = Chr(Asc($aText[$i]) + 1)

Next

; So we get this
_ArrayDisplay($aText)

; Now we reasemble the string
$sCodedText = _ArrayToString($aText, "", 1)

; And here is the result
MsgBox(0, "Done", $sText & @CRLF & "now reads" & @CRLF & $sCodedText)

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

Iawonama,

This piqued my curiousity and I need the experience working with Gui's so I coded this ditty that you may find usefull.

#include <ButtonConstants.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


Local $a_Input_letter[4]
Local $a_transposition_letter[4]

; all letters that can be input

$a_Input_letter[0] = 'a'
$a_Input_letter[1] = 'b'
$a_Input_letter[2] = 'c'
$a_Input_letter[3] = 'd'

; what each input letter will transpose to

$a_transposition_letter[0] = 'z'
$a_transposition_letter[1] = 'f'
$a_transposition_letter[2] = 'y'
$a_transposition_letter[3] = 'l'

; el guio

Local  $gui010  = GUICreate('Letter X-pose Example',500,400)
                  GUICtrlCreatelabel('Enter Letter to Transpose',100,80,300,40)
global $inp010  = GUICtrlCreateInput('',100,100,300,20)
                  GUICtrlCreatelabel('Transposition',100,130,300,40)
global $out010  = GUICtrlCreateLabel('',100,150,300,20,$ss_sunken)
Local  $btn010  = GUICtrlCreatebutton('Transpose',100,300,300,30)
                  GUISetState()
Local $msg

Do

    $msg = GUIGetMsg()
    select
        Case $msg = $btn010
            transpose()
        Case else
    endselect

until $msg = $gui_event_close

exit

Func transpose()

    Local $in, $out, $hit = false

    GUICtrlSetData($out010,'')
    Local $in = stringsplit(GUICtrlRead($inp010),"")

    ;_arraydisplay($in)

    For $i = 1 To $in[0]
        For $j = 0 To UBound($a_Input_letter) - 1
            If $a_Input_letter[$j] = $in[$i] Then
                $out &= $a_transposition_letter[$j]
                $hit = true
            endif
        next
        If Not $hit Then $out &= '-'
        $hit = false
    Next
    GUICtrlSetData($out010,$out)
    GUICtrlSetState($inp010,$gui_focus)

endfunc

@M23 - Sorry if I'm stepping on your toes...

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

On XP and later you should have Scripting.Dictionary on the machine. Basically it's an array indexed by a key rather than an index number. Instead of $myArray[5] = "Some Text" you would say $myArray("Jimi") = "Hendrix" or whatever.

Makes it easy to look up using one string and return another. I find it nice for lists of color values. Access the color hex value by the color name etc.. But you can use it for most any kind of text substitution. The dictionary lookup does the search instead of looping through an array.

I made a few wrapper functions for Scripting.Dictionary object.

#include <Array.au3>

;use Scripting.Dictionary object for simple associative arrays
Func _AssocArray()
Local $aArray = ObjCreate("Scripting.Dictionary")
If @error Then
  Return SetError(1, 0, 0)
EndIf
$aArray.CompareMode = 1 ; not case sensitive string compare
Return $aArray
EndFunc   ;==>_AssocArray

Func _AssocArrayDestroy(ByRef $aArray)
If Not IsObj($aArray) Then
  Return False
EndIf
$aArray.RemoveAll()
$aArray = 0
Return True
EndFunc   ;==>_AssocArrayDestroy

;filter out empty array strings ("")
Func _ArrayDelBlanks(ByRef $someArray)
Local $index = -1
While UBound($someArray) > 0
  $index = _ArraySearch($someArray, "")
  If $index > -1 Then
   _ArrayDelete($someArray, $index)
  Else
   ExitLoop
  EndIf
WEnd
EndFunc   ;==>_ArrayDelBlanks

Creating a new Associative Array is a one-liner

$myArray = _AssocArray()

If @error then

notify there was an error etc..

Edited by MilesAhead
Link to comment
Share on other sites

btw when using the dictionary always test that a key exists with

If $myArray.Exists("NavyBlue") then

otherwise as soon as you present it with a key even on the right hand side of an assignment, it will create an entry with an empty value. So if the key doesn't exist and you do

$myValue = $myArray("NavyBlue")

the variable $myValue will be set to "" (empty string)

(I wrote that delete blanks function before I fully understood how to use the dictionary) :)

Edited by MilesAhead
Link to comment
Share on other sites

You may be able to alter this example to get it to perform the way you would like.

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $Form1, $Input1, $Button1, $text1, $Text2

#region  Form
$Form1 = GUICreate("HumanGhoul Translator", 487, 226, 192, 124)
$Input1 = GUICtrlCreateEdit('Hi, "HI H TEXT A AB" is a TEST.' & @CRLF & @CRLF & @CRLF & "HELLO everbody.", 8, 72, 465, 80)
$Button1 = GUICtrlCreateButton("Translate!", 176, 158, 137, 59, $WS_GROUP)
$text1 = GUICtrlCreateLabel("Human > Ghoul.", 208, 8, 81, 17)
$Text2 = GUICtrlCreateLabel("Please insert your text here:", 184, 48, 134, 17)
GUISetState(@SW_SHOW)
#endregion  Form

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(64, "Ghoul Language", _Transcribe())
    EndSwitch
WEnd


; Returns transcribed text
Func _Transcribe()
    Local $iIndex, $sInput, $sOutput, $aOutput

    ; Substitution encryption array ($aArray2D[n][0] is substituted with $aArray2D[n][1]). eg.
    ; "H" is substituted with "Z", "TEST" is substituted with "RANDOMTEXT", etc.
    Local $aArray2D[10][2] = [ _
            ["H", "Z"],["I", "O"],["HI", "ZO"],["TEST", "RANDOMTEXT"],["HELLO", "TheSecondRandomText"], _
            ["TEXT", "ABCD"],["EXAMPLE", "TEST2"],["A","B"],["B", "C"],["AB","BC"]]

    $sInput = GUICtrlRead($Input1)
    $sInput = StringRegExpReplace($sInput, '(,|.|")', " 1 ") ; Surround coma, fullstop, and/or double quotes with spaces, preparing for StringSplit() on spaces.
    $sInput = StringRegExpReplace($sInput, "(v{1,2})", " <^> ") ; Replace @LF or @CRLF with " <^> "
    $sInput = StringStripWS($sInput, 7) ; Remove trailing and leading spaces, and, replace double or more adjacent spaces with one space.
    $aOutput = StringSplit($sInput, " ", 2) ; Split the string at each space into an array.
    ;_ArrayDisplay($aOutput)

    For $i = 0 To UBound($aOutput) - 1

        If $aOutput[$i] = "<^>" Then ; Convert "<^>" back to @LF
            $sOutput &= @LF
        ElseIf StringRegExp($aOutput[$i], '[,."]') Then ; Coma, fullstop, and double quotes are un-encrypted.
            $sOutput &= $aOutput[$i]
        Else
            $iIndex = _ArraySearch($aArray2D, $aOutput[$i], 0, 0, 1) ; Case sensitive.
            If @error = 6 Then ; If text not found in substitution array then return original text un-encrypted.
                $sOutput &= " " & $aOutput[$i]
            Else
                $sOutput &= " " & $aArray2D[$iIndex][1] ; Return encrypted text from substitution array.
            EndIf
        EndIf

    Next

    Return StringStripWS($sOutput, 1) ; Remove leading space and return.
EndFunc   ;==>_Transcribe
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...