Tac0s Posted August 14, 2015 Posted August 14, 2015 Hi!New to the forums, hopefully you can help.I am trying to use a gui input as a variable for the rest of the script, but cannot seem to make it work.We need to get the client to indicate his username, and using that input and declaring it as a variable we can then indicate the path to his userprofile (in order to install some files on their profile - We are running a software installation with admin rights and unfortunately some of the necessary files end up in the Admin account used to run the setup.exe).So looking at my code below, could you perhaps help to clarify what could be wrong?Thanks!#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Const $Username = GUICtrlRead ("") Const $Profile = "C:\users" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("title", 347, 317, 379, 128) $Label1 = GUICtrlCreateLabel("Please Write your Username:", 24, 136, 300, 65) $Input1 = GUICtrlCreateInput("", 32, 216, 297, 21) $Button1 = GUICtrlCreateButton("OK", 128, 248, 81, 33) $Pic1 = GUICtrlCreatePic("", 8, 0, 332, 108) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlRead($Input1) If FileExists ($Profile & $Input1) Then MsgBox (0, "Info", "Username Exists" , 0, "") Else MsgBox (0, "Info", "Wrong Username", 0, "") EndIf If FileExists ($Profile & $Input1) Then ExitLoop EndIf EndSwitch WEnd getlocalusernameAUTOIT.au3
jguinch Posted August 14, 2015 Posted August 14, 2015 1/ You have to retrieve the control value with GUICtrlRead$username = GUICtrlRead($Input1)2/ The FileExists needs a "\" (or add a "\" to the $Profile value)If FileExists ($Profile & "\" & $username) ...3/ You can put the ExitLoop just after the MsgBox and then remove the second FileExits testHere is a corrected version :#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Local $Username Const $Profile = "C:\users" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("title", 347, 317, 379, 128) $Label1 = GUICtrlCreateLabel("Please Write your Username:", 24, 136, 300, 65) $Input1 = GUICtrlCreateInput("", 32, 216, 297, 21) $Button1 = GUICtrlCreateButton("OK", 128, 248, 81, 33) $Pic1 = GUICtrlCreatePic("", 8, 0, 332, 108) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $username = GUICtrlRead($Input1) If FileExists ($Profile & "\" & $username) Then MsgBox (0, "Info", "Username Exists" , 0, "") ExitLoop Else MsgBox (0, "Info", "Wrong Username", 0, "") EndIf EndSwitch WEnd Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Moderators Melba23 Posted August 14, 2015 Moderators Posted August 14, 2015 (edited) Tac0s,Welcome to the AutoIt forums.Look at the changes I made:expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Const $Username = GUICtrlRead ("") Const $Profile = "C:\users\" ; Add a "\" here #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("title", 347, 317, 379, 128) $Label1 = GUICtrlCreateLabel("Please Write your Username:", 24, 136, 300, 65) $Input1 = GUICtrlCreateInput("", 32, 216, 297, 21) $Button1 = GUICtrlCreateButton("OK", 128, 248, 81, 33) $Pic1 = GUICtrlCreatePic("", 8, 0, 332, 108) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $sUsername = GUICtrlRead($Input1) ; You need to put the content into a variable... If FileExists ($Profile & $sUsername) Then ; ...which you then use here MsgBox (0, "Info", "Username Exists" , 0, "") ExitLoop ; And you can put this here rather then ask the same queston again Else MsgBox (0, "Info", "Wrong Username", 0, "") EndIf EndSwitch WEndPlease ask if you have any questions.M23Edit: Getting slow in my old age! Edited August 14, 2015 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now