Jump to content

GUICtrlRead Edit and reverse Strings line by line


Go to solution Solved by FireFox,

Recommended Posts

Hey guys! I just started to work on a script to convert/encrypt strings in a simple GUI. First of all, here is my code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>

$Form1 = GUICreate("Form1", 615, 438, 574, 290)
$Text = GUICtrlCreateEdit("", 8, 40, 601, 353)
GUICtrlSetData(-1, "")
$Convert = GUICtrlCreateButton("Convert", 8, 400, 297, 33)
$Close = GUICtrlCreateButton("Close", 312, 400, 297, 33)
$StringReverse = GUICtrlCreateRadio("String Reverse", 16, 8, 89, 17)
$StringEncrypt = GUICtrlCreateRadio("String Encrypt", 128, 8, 89, 17)
$Frame1 = GUICtrlCreateGroup("", 8, 0, 105, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Password = GUICtrlCreateInput("", 216, 8, 385, 21)
$Frame2 = GUICtrlCreateGroup("", 120, 0, 489, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Close
            Exit
        Case $Convert
            If GUICtrlRead($StringReverse) = 1 Then
                $ReadText = GUICtrlRead($Text)
                $ReverseText = _StringReverse($ReadText)
                GUICtrlSetData($Text, $ReverseText)
            ElseIf GUICtrlRead($StringEncrypt) = 1 Then
                $ReadText = GUICtrlRead($Text)
                $ReadPassword = GUICtrlRead($Password)
                If $ReadPassword = Not 0 Then
                    $TextEncrypt = _StringEncrypt(1, $ReadText, $ReadPassword)
                    GUICtrlSetData($Text, $TextEncrypt)
                Else
                    MsgBox(0,"Error","String encryption requires a password")
                EndIf
            Else
                MsgBox(0,"Error","No manipulation method specified")
            EndIf
    EndSwitch
WEnd

The problem with this is, if i want to convert for example somthing like this:

"String1"

"String2"

"String3"

GUICtrlRead will read it as "String1""String2""String3". I tried to mess around with StringSplit, but can't get it to work. Any indeas? :)

Link to comment
Share on other sites

  • Solution

Or...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
 
$Form1 = GUICreate("Form1", 615, 438, 574, 290)
$Text = GUICtrlCreateEdit("", 8, 40, 601, 353)
$Convert = GUICtrlCreateButton("Convert", 8, 400, 297, 33)
$Close = GUICtrlCreateButton("Close", 312, 400, 297, 33)
$StringReverse = GUICtrlCreateRadio("String Reverse", 16, 8, 89, 17)
$StringEncrypt = GUICtrlCreateRadio("String Encrypt", 128, 8, 89, 17)
$Frame1 = GUICtrlCreateGroup("", 8, 0, 105, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Password = GUICtrlCreateInput("", 216, 8, 385, 21)
$Frame2 = GUICtrlCreateGroup("", 120, 0, 489, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Close
            Exit
        Case $Convert
            If GUICtrlRead($StringReverse) = 1 Then
                $ReadText = GUICtrlRead($Text)
                GUICtrlSetData($Text, "")
 
                $aText = StringSplit($ReadText, @CRLF, 1)
                $sText = ""
                For $i = 1 To $aText[0]
                    $sText &= _StringReverse($aText[$i]) & @CRLF
                Next
                GUICtrlSetData($Text, StringTrimRight($sText, 2))
            ElseIf GUICtrlRead($StringEncrypt) = 1 Then
                $ReadText = GUICtrlRead($Text)
                $ReadPassword = GUICtrlRead($Password)
                If $ReadPassword = Not 0 Then
                    $TextEncrypt = _StringEncrypt(1, $ReadText, $ReadPassword)
                    GUICtrlSetData($Text, $TextEncrypt)
                Else
                    MsgBox(0, "Error", "String encryption requires a password")
                EndIf
            Else
                MsgBox(0, "Error", "No manipulation method specified")
            EndIf
    EndSwitch
WEnd
Br, FireFox.
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

×
×
  • Create New...