Jump to content
Sign in to follow this  
iTpHo3NiX

Replace Text on User Input

Recommended Posts

iTpHo3NiX

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:

Share this post


Link to post
Share on other sites
iTpHo3NiX

Ok do you think you can go more into specifics and when I would use GUICtrlRead()?

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
iTpHo3NiX

Thank you with that simple change its completely working now. Thank you.

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  

×