Sign in to follow this  
Followers 0
LiquidNitrogen

String Converter (Updated)

9 posts in this topic

#1 ·  Posted (edited)

Converts:

- String to Binary

- String to Hex

- Binary to String

- Hex to String

Added Error Checking.

#Include <EditConstants.au3>
#include <String.au3>
#NoTrayIcon


Main()
StringToB()
StringToH()
BinaryToS()
HexToS()


Func Main()

    GUIDelete()

    $Main = GUICreate("String Converter", 250, 230)
    $title = GUICtrlCreateLabel("String Converter by ReaperX", 55, 20)
    $StringToB = GUICtrlCreateButton("String -> Binary", 75, 60, 100, 30)
    $StringToH = GUICtrlCreateButton("String -> Hex", 75, 90, 100, 30)
    $BinaryToS = GUICtrlCreateButton("Binary -> String", 75, 120, 100, 30)
    $HexToS = GUICtrlCreateButton("Hex -> String", 75, 150, 100, 30)
    $about = GUICtrlCreateButton("About", 0, 210, 80, 20)
    $exit = GUICtrlCreateButton("Exit", 170, 210, 80, 20)


    GUISetState()


    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                Exit
            Case $StringToB
                StringToB()
            Case $StringToH
                StringToH()
            Case $BinaryToS
                BinaryToS()
            Case $HexToS
                HexToS()
            Case $about
                MsgBox(0, "About", "Created By ReaperX (C) 2011.")
            Case $exit
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Main


Func StringToB()

    GUIDelete()

    GUICreate("String Converter", 300, 260)
    $title = GUICtrlCreateLabel("String To Binary", 110, 50)
    $text_label = GUICtrlCreateLabel("Text String:", 15, 101)
    $text = GUICtrlCreateInput("", 75, 100, 170, 18)
    GUICtrlSetTip($text, "String to Convert to Binary.")
    $result = GUICtrlCreateInput("", 75, 130, 170, 18, BitOr($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
    GUICtrlSetTip($result, "Conversion Displayed Here.")
    $result_label = GUICtrlCreateLabel("Result:", 35, 131)
    $convert = GUICtrlCreateButton("Convert", 130, 160, 50, 30)
    $back = GUICtrlCreateButton("<- Back", 0, 0, 45, 20)
    $copy = GUICtrlCreateButton("Copy To Clipboard", 105, 200, 100, 20)
    GUICtrlSetTip($copy, "Copy Conversion Result to Clipboard.")
    $converter = ""

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                Exit
            Case $convert
                $read = GUICtrlRead($text)
                $converter = StringToBinary($read)
                GUICtrlSetData($result, $converter)
            Case $back
                Main()
            Case $copy
                ClipPut($converter)
                MsgBox(0, "Copied!", "Conversion Copied to Clipboard!")
        EndSwitch
    WEnd
EndFunc   ;==>StringToB

Func StringToH()

    GUIDelete()

    GUICreate("String Converter", 300, 260)
    $title = GUICtrlCreateLabel("String To Hex", 110, 50)
    $text_label = GUICtrlCreateLabel("Text String:", 15, 101)
    $text = GUICtrlCreateInput("", 75, 100, 170, 18)
    GUICtrlSetTip($text, "String to Convert to Hex.")
    $result = GUICtrlCreateInput("", 75, 130, 170, 18, BitOr($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
    GUICtrlSetTip($result, "Conversion Displayed Here.")
    $result_label = GUICtrlCreateLabel("Result:", 35, 131)
    $convert = GUICtrlCreateButton("Convert", 130, 160, 50, 30)
    $back = GUICtrlCreateButton("<- Back", 0, 0, 45, 20)
    $copy = GUICtrlCreateButton("Copy To Clipboard", 105, 200, 100, 20)
    GUICtrlSetTip($copy, "Copy Conversion Result to Clipboard.")
    $converter = ""

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                Exit
            Case $convert
                $read = GUICtrlRead($text)
                $converter = _StringToHex($read)
                GUICtrlSetData($result, $converter)
            Case $back
                Main()
            Case $copy
                ClipPut($converter)
                MsgBox(0, "Copied!", "Conversion Copied to Clipboard!")
        EndSwitch
    WEnd
EndFunc   ;==>StringToH


Func BinaryToS()

    GUIDelete()

    GUICreate("String Converter", 300, 260)
    $title = GUICtrlCreateLabel("Binary To String", 110, 50)
    $text_label = GUICtrlCreateLabel("Binary String:", 8, 101)
    $text = GUICtrlCreateInput("", 75, 100, 170, 18)
    GUICtrlSetTip($text, "Binary String to Convert to Text.")
    $result = GUICtrlCreateInput("", 75, 130, 170, 18, BitOr($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
    GUICtrlSetTip($result, "Conversion Displayed Here.")
    $result_label = GUICtrlCreateLabel("Result:", 35, 131)
    $convert = GUICtrlCreateButton("Convert", 130, 160, 50, 30)
    $back = GUICtrlCreateButton("<- Back", 0, 0, 45, 20)
    $copy = GUICtrlCreateButton("Copy To Clipboard", 105, 200, 100, 20)
    GUICtrlSetTip($copy, "Copy Conversion Result to Clipboard.")
    $converter = ""

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                Exit
            Case $convert
                If StringInStr(GUICtrlRead($text), "0x") And Not StringTrimLeft(GUICtrlRead($text), 2) = "" Then
                $read = GUICtrlRead($text)
                $converter = BinaryToString($read)
                GUICtrlSetData($result, $converter)
            Else
                MsgBox(16, "Error!", "The Binary String Entered is Not Valid!")
                GUICtrlSetData($text, "")
                GUICtrlSetData($result, "")
            EndIf
            Case $back
                Main()
            Case $copy
                ClipPut($converter)
                MsgBox(0, "Copied!", "Conversion Copied to Clipboard!")
        EndSwitch
    WEnd
EndFunc   ;==>BinaryToS


Func HexToS()

    GUIDelete()

    GUICreate("String Converter", 300, 260)
    $title = GUICtrlCreateLabel("Hex To String", 110, 50)
    $text_label = GUICtrlCreateLabel("Hex String:", 15, 101)
    $text = GUICtrlCreateInput("", 75, 100, 170, 18)
    GUICtrlSetTip($text, "Hex String to Convert to Text.")
    $result = GUICtrlCreateInput("", 75, 130, 170, 18, BitOr($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
    GUICtrlSetTip($result, "Conversion Displayed Here.")
    $result_label = GUICtrlCreateLabel("Result:", 35, 131)
    $convert = GUICtrlCreateButton("Convert", 130, 160, 50, 30)
    $back = GUICtrlCreateButton("<- Back", 0, 0, 45, 20)
    $copy = GUICtrlCreateButton("Copy To Clipboard", 105, 200, 100, 20)
    GUICtrlSetTip($copy, "Copy Conversion Result to Clipboard.")
    $converter = ""

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                Exit
            Case $convert
                If StringIsXDigit(GUICtrlRead($text)) Then
                $read = GUICtrlRead($text)
                $converter = _HexToString($read)
                GUICtrlSetData($result, $converter)
            Else
                MsgBox(16, "Error!", "The Hex String Entered is Not Valid!")
                GUICtrlSetData($text, "")
                GUICtrlSetData($result, "")
            EndIf
            Case $back
                Main()
            Case $copy
                ClipPut($converter)
                MsgBox(0, "Copied!", "Conversion Copied to Clipboard!")
        EndSwitch
    WEnd
EndFunc   ;==>HexToS
Edited by ReaperX

Formerly ReaperX

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

ReaperX

Hex String: 0xzz

Result: 0xzz

There is No "0xzz" in Hex. Otherwise It Would Work.

Edited by ReaperX

Formerly ReaperX

Share this post


Link to post
Share on other sites

You should check for invalid chars and return an error.

Good Idea. Ill Work on that and Update it.


Formerly ReaperX

Share this post


Link to post
Share on other sites

ReaperX

StringIsXDigit

I Dont get What You are Saying...


Formerly ReaperX

Share this post


Link to post
Share on other sites

Oh Ok. Thanks.


Formerly ReaperX

Share this post


Link to post
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
Sign in to follow this  
Followers 0