Jump to content

Replace Text on User Input


Recommended Posts

Ok Well I'm working on an AutoIt script that requires user input to change information in a batch file. This is what I've go so far:

;====================================================
;=================== FTP Information ================
;====================================================
; Version: 2.0.0
; Language: English
; Author: iTpHo3NiX
;====================================================
;=================== FTP Information ================
;====================================================

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $filemenu, $fileitem, $recentfilesmenu, $separator1
    Local $exititem, $helpmenu, $optionmenu, $optionitem, $aboutitem, $okbutton, $cancelbutton
    Local $msg, $file
    Local $server, $username, $password, $text
    #forceref $separator1

    GUICreate("FTP Generator by iTpHo3NiX", 400, 250)
    $server = GUICtrlCreateInput("FTP Server", 40, 25, 245, 21); creats a blank textbox in the GUI window
    $username = GUICtrlCreateInput("FTP Username", 40, 65, 245, 21); creats a blank textbox in the GUI window
    $password = GUICtrlCreateInput("FTP Password", 40, 105, 245, 21); creats a blank textbox in the GUI window

    $filemenu = GUICtrlCreateMenu("File")
    $fileitem = GUICtrlCreateMenuItem("Open...", $filemenu)
    $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu)
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $optionmenu = GUICtrlCreateMenu("Options")
    $optionitem = GUICtrlCreateMenuItem("Test FTP", $optionitem)
    $helpmenu = GUICtrlCreateMenu("Help")
    $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)
    

    $okbutton = GUICtrlCreateButton("Generate", 50, 175, 70, 20)

    $cancelbutton = GUICtrlCreateButton("Close", 180, 175, 70, 20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
                ExitLoop

            Case $msg = $fileitem
                $file = FileOpenDialog("Choose file...", @TempDir, "Batch Files (*.bat)")
                If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu)

            Case $msg = $exititem
                ExitLoop

            Case $msg = $okbutton
                    $text = FileRead($file)
                    $text = StringReplace($text, "ftpserver", $server)
                    $text = StringReplace($text, "ftpusername", $username)
                    $text = StringReplace($text, "ftppassword", $password)

                    FileDelete($file)
                    FileWrite($file, $text)
                    MsgBox(0, "Generated", "File generated successfully!")
                
            Case $msg = $aboutitem
                MsgBox(0, "About", "This is a FTP Information Generater that is coded in Batch and AutoItv3 by iTpHo3NiX. For and help or questions email iTpHo3NiX at itpho3nix@gmail.com")
        EndSelect
    WEnd

    GUIDelete()

    Exit
EndFunc   ;==>_Main

Now when I select what file I want to open with the proper string in the file, all it gets replaced with is 3, 4, and 5 for the different things when its supposed to replace with whatever the user input is. Thanks in advanced for any help :idea:

Link to comment
Share on other sites

  • Developers

When you want to "read" the value from the controls and us it in your script.

The numbers you see are the Control handles and the actual content is retrieved by doing GuiCtrlRead($Server).

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...