Jump to content
Sign in to follow this  
Clipper34

Problem with input box

Recommended Posts

Clipper34

Hey guys, i've came across a problem in my code, i have a input box. But on the side of it it has a button called browse. And when you click it you can browse for an .exe, and with that theres a buton that runs the .exe. The problem is the browse part or start part wont work. Any ideas/suggestions? Thanks.

;Include gui constants
#include <GuiConstants.au3>

;Create the GUI
GUICreate("Test", 550, 550)
GUISetIcon(@SystemDir & "\taskmgr.exe", 0)

$exe = GuiCtrlCreateInput("Run .exe's here", 200, 420, 220, 20)
$browsebutton = GUICtrlCreateButton("Browse", 130, 420, 70, 20)

$startbutton = GUICtrlCreateButton("Start .exe", 130, 450, 70, 20)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $exe
        
        Case $msg = $browsebutton
    $var = FileOpenDialog("", "C:\", "(*.exe):)
    FileOpen($var)
    
Case $msg = $filemenuitem
    $copy = InputBox("File Manager - File Copy", "Type a filename to copy:")
    $dest = InputBox("File Manager - File Copy", "Type the destination:")
    FileCopy($copy, $dest)
    
Case $msg = $startbutton
    Run($exe)
EndSelect
WEnd
GUIDelete()

Share this post


Link to post
Share on other sites
BrettF

Not sure how you meant to do this with the way you chose, or what $filemenuitem is, but this now works.

;Include gui constants
#include <GuiConstants.au3>

;Create the GUI
GUICreate("Test", 550, 550)
GUISetIcon(@SystemDir & "\taskmgr.exe", 0)

$exe = GUICtrlCreateInput("Run .exe's here", 200, 420, 220, 20)
$browsebutton = GUICtrlCreateButton("Browse", 130, 420, 70, 20)

$startbutton = GUICtrlCreateButton("Start .exe", 130, 450, 70, 20)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = -3;$GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $exe
            Run(GUICtrlRead ($exe))
        Case $msg = $browsebutton
            $var = FileOpenDialog("", "C:\", "(*.exe)")
            GUICtrlSetData ($exe, $var)
        Case $msg = $startbutton
            Run(GUICtrlRead ($exe))
    EndSelect
WEnd
GUIDelete()

Share this post


Link to post
Share on other sites
Clipper34

Thanks Bert it works great :), and one more question. Could you give me a hint on where to start on how to display the contents of a defined directory in a list view? Thanks.

Share this post


Link to post
Share on other sites
BrettF

Share this post


Link to post
Share on other sites
Clipper34

Thanks again Bert, and one more question lol. Is it my pure stupidity or i just cant get FileOpenDialog to work in a button? I'm assuming its like the way you did further up the page for the browse and start buttons. Thanks for the help :)

Share this post


Link to post
Share on other sites
TehWhale

You can get FileOpenDialog to work when you press a button. Use it in your loop

If using a Switch GUIGetMsg() statement then:

Case $ButtonName
FileOpenDialog(...)

Else...

Case $GUIGetMsgReturn = $ButtonName
FileOpenDialog(...)

Share this post


Link to post
Share on other sites
Clipper34

Yeah that works perfectly, but the fact is when you try to click something and open it. It does not work.

Share this post


Link to post
Share on other sites
TehWhale

You must tell AutoIt what to do with what it found. Try this:

Case $GUIGetMsgReturn = $OpenButton
$OpenFile = FileOpenDialog(...)
ShellExecute($OpenFile)

How does that work for you?

Share this post


Link to post
Share on other sites
Clipper34

Thanks JasonB it works perfectly, I'm not that familiar with ShellExecute. So basically if your using something like FileOpenDialog you use ShellExecute to open the file? Thanks for the help :)

Edited by Clipper34

Share this post


Link to post
Share on other sites
TehWhale

Is what your doing is, getting the picked file from FileOpenDialog() and then, shellexecute is basically like run, so it's running that file. To save your file, you need to write your own function to open the file, write it, close it, and so on. (I might even write one for you)

Best of Luck, J.B.

Edited by JasonB

Share this post


Link to post
Share on other sites
TehWhale

I decided to write this for you. I might try to get it included with the AutoIt install set.

EDIT: Fixed It Up!

;===============================================================================
;
; Function Name:   _FileSave ( $Title, $TextToSave, [$InitialDir [, $Filter [, $DefaultName]]] )
; Description::    Using FileSaveDialog() It writes to a file the text given
; Parameter(s):    $Title - The title of the FileSaveDialog
;                  $TextToSave - The text to write to the file, either a string or array
;                  $InitialDir - The directory for the FileSaveDialog to first look at
;                  $Filter - The filter for which to save the file
;                  $DefaultName - The name for the file to be saved as
; Requirement(s):  AutoIt, 3.2.8.10+
; Return Value(s): On Success: Returns 1
;                  On Failure: Returns 0 and sets @error to:
;
;                  1 = $TextToSave is not valid
;                  2 = The file chosen to save is not valid
;                  3 = Could not open the save file for writing
;                  4 = Could not write the array to the file
; Author(s):       Jason Briggs (Aka: JasonB)
; Example(s):
;                  #Include <File.au3>
;                  _FileSave(Default, "This is a test string")
;                  If @error Then MsgBox(0, "_FileSave() Failure", "_FileSave() Failed with: @error set to: "&@error)
;===============================================================================
;


Func _FileSave($Title, $TextToSave, $InitialDir = @MyDocumentsDir, $Filter = "All (*.*)", $DefaultName = "")
    If $InitialDir = -1 Or $InitialDir = Default Then $InitialDir = @MyDocumentsDir
    If $Filter = -1 Or $Filter = Default Then $Filter = "All (*.*)"
    If $DefaultName = -1 Or $DefaultName = Default Then $DefaultName = ""
    If $TextToSave = "" Or $TextToSave = Default Or $TextToSave = -1 Then Return SetError(1, 0, 0)
    If $Title = "" Or $Title = -1 Or $Title = Default Then $Title = "Please select file to save"
    Local $_Choosen = FileSaveDialog($Title, $InitialDir, $Filter, 16, $DefaultName)
    If @error Or $_Choosen = "" Then Return SetError(2, 0, 0)
    Local $_FileHand = FileOpen($_Choosen, 2)
    If $_FileHand = -1 Then Return SetError(3, 0, 0)
    If Not IsArray($TextToSave) Then
        FileWrite($_FileHand, $TextToSave)
    Else
        Local $last = UBound($TextToSave) - 1
        Local $i_UBound = -1
        Local $i_Base = -1
        If $i_UBound < 1 Or $i_UBound > $last Then $i_UBound = $last
        If $i_Base < 0 Or $i_Base > $last Then $i_Base = 0
        Local $ErrorSav = 0
        For $x = $i_Base To $i_UBound
            If FileWrite($_Choosen, @CRLF & $TextToSave[$x]) = 0 Then
                FileClose($_FileHand)
                Return SetError(4, 0, 0)
            EndIf
        Next
    EndIf
    FileClose($_FileHand)
    Return 1
EndFunc
Edited by JasonB

Share this post


Link to post
Share on other sites
Clipper34

Nice program!, heres one of mine i made a while back but fixed up

$MyDocsFolder = @MyDocumentsDir
While 1
    $saveOption = InputBox("", "Do you wish to be asked to overwrite files? (yes/no): ")
    If $saveOption = "yes" OR $saveOption = "no" Then
        ExitLoop
    Else
        MsgBox(0, "", "Choose your option please: ")
    EndIf
WEnd
If $saveOption = "yes" Then
$saveOption = 16
Else
    $saveOption = ""
    EndIf
$file = FileSaveDialog("Save Dialouge", $MyDocsFolder, "Text files(*.txt)", 16)
FileWrite("", $file)
$exitoption = InputBox("Options?", "Do you want to exit or open a folder? (yes/no): ")
ShellExecute($exitoption)
If @error Then 
    MsgBox(4096, "ERROR", "No File(s) typed")
Else
    $var = StringReplace($var, "|", @CRLF)
    MsgBox(4096, "Selection", "You chose " & $var)
    EndIf
if $exitoption = "yes" OR $exitoption = "no" Then
Else
    MsgBox(0, "Choose", "Choose your option please: ")
EndIf
If $exitoption = "yes" Then
    FileOpenDialog(0, "Save Dialouge/Open", $MyDocsFolder, "", 12)
    EndIf

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  

×