Srex Posted July 6, 2014 Posted July 6, 2014 hi forum i have this code, which will make the user select an output location. Case $ButtonBrowseOutputLoc $sFileSelectFolder = FileSelectFolder("Select output location", "") ElseIf Not @error Then $OutPutLoc = $sFileSelectFolder & '\settings.ini' GUICtrlSetData($InputCheatDir, $OutPutLoc) EndIf It works great and all BUT if they select the root of a drive (for example 'c') Then it says "C:settings.ini" instead of "C:settings.ini" i tried putting up a condition that if $sFileSelectfolder (this variable doesnt include the root part theres a seperate function for that) is empty then "settings.ini" else "/settings.ini" but it doesnt work for me any suggestions? Also with this im having a bug, so if the user doesnt filll out the output location it just disapears upon creation. instead of defaulting to the @scriptdir .. i either need to: 1: force the user to select (not prefered) 2: make it default at @scriptdir
Jfish Posted July 6, 2014 Posted July 6, 2014 (edited) If Not @error Then If $sFileSelectFolder="C:\" Then ConsoleWrite("c has been selected"&@crlf) $OutPutLoc = $sFileSelectFolder & 'settings.ini' Else $OutPutLoc = $sFileSelectFolder & '\settings.ini' EndIf ConsoleWrite($OutPutLoc) For your "bug" on a default location just do this at the top somewere .... $sFileSelectFolder=@scriptdir That way if they never push the button or cancel it will still be set to the @scriptdir. If they do choose a different location the default will get overridden. Edited July 6, 2014 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
JohnOne Posted July 6, 2014 Posted July 6, 2014 $fol = FileSelectFolder("Select output location", "") If StringRight($fol, 1) = "\" Then $fol = StringTrimRight($fol, 1) EndIf $fol &= "\folder\file.ext" ConsoleWrite($fol & @LF) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Srex Posted July 6, 2014 Author Posted July 6, 2014 If Not @error Then If $sFileSelectFolder="C:\" Then ConsoleWrite("c has been selected"&@crlf) $OutPutLoc = $sFileSelectFolder & 'settings.ini' Else $OutPutLoc = $sFileSelectFolder & '\settings.ini' EndIf ConsoleWrite($OutPutLoc) For your "bug" on a default location just do this at the top somewere .... $sFileSelectFolder=@scriptdir That way if they never push the button or cancel it will still be set to the @scriptdir. If they do choose a different location the default will get overridden. If I chose that I'd need to set a case because they can choose every drive from a-z and store the settings.ini in a variable instead hmm
Srex Posted July 6, 2014 Author Posted July 6, 2014 $fol = FileSelectFolder("Select output location", "") If StringRight($fol, 1) = "\" Then $fol = StringTrimRight($fol, 1) EndIf $fol &= "\folder\file.ext" ConsoleWrite($fol & @LF) always enjoy reading your soloutions sir. I shall read up on stringright and stringtrimright to understand its purpose
Jfish Posted July 6, 2014 Posted July 6, 2014 (edited) @JohnOne always has a more elegant solution @Srex I am not sure what you mean with your last comment. Are you talking about the default directory? Edited July 6, 2014 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Srex Posted July 6, 2014 Author Posted July 6, 2014 @JohnOne always has a more elegant solution @Srex I am not sure what you mean with your last comment. Are you talking about the default directory? of OP? Yes I mean if the user does not select an output location for the settings file then it will be put at @scriptdir otherwise it should be put where the user tells it to
Jfish Posted July 6, 2014 Posted July 6, 2014 @Srex, no, I meant I don't follow this: If I chose that I'd need to set a case because they can choose every drive from a-z and store the settings.ini in a variable instead hmm Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Srex Posted July 6, 2014 Author Posted July 6, 2014 (edited) @Srex, no, I meant I don't follow this: ohh excuse me. because this If $sFileSelectFolder="C:\" Then only returns true if they select the root of the c drive i have no clue what letter their drive is so i need to make one for every letter can i have cases within cases? like: case $ButtonBrowseOutpuLoc case $sFileSelectFolder="C:\" $OutPutLoc = $sFileSelectFolder & 'settings.ini' case $sFileSelectFolder="D:\" $OutPutLoc = $sFileSelectFolder & 'settings.ini' etc etc so case button gets pressed, run these cases Edited July 6, 2014 by Srex
JohnOne Posted July 6, 2014 Posted July 6, 2014 There is also the Ternary way. $fol = FileSelectFolder("Select output location", "") $fol = (StringRight($fol, 1) = "\") ? StringTrimRight($fol, 1) : $fol $fol &= "\folder\file.ext" ConsoleWrite($fol & @LF) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Jfish Posted July 6, 2014 Posted July 6, 2014 @Srex, @JohnOne's solution is agnostic as to drive letter ... that should work for you. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Srex Posted July 6, 2014 Author Posted July 6, 2014 There is also the Ternary way. $fol = FileSelectFolder("Select output location", "") $fol = (StringRight($fol, 1) = "\") ? StringTrimRight($fol, 1) : $fol $fol &= "\folder\file.ext" ConsoleWrite($fol & @LF) okay I need to try and understand what this actually does But it looks very good and efficient sir
Moderators Melba23 Posted July 6, 2014 Moderators Posted July 6, 2014 Srex,You do realise that Windows is quite happy to accept "" in place of "" and so it does not matter whether there is an additional "" in the path? M23 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
Srex Posted July 6, 2014 Author Posted July 6, 2014 Srex, You do realise that Windows is quite happy to accept "" in place of "" and so it does not matter whether there is an additional "" in the path? M23 Really? Are you kidding me
JohnOne Posted July 6, 2014 Posted July 6, 2014 They are both exactly the same really, ? : just replaces if then. If the rightmost character is then that will trimmed off, else it stays the same. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
JohnOne Posted July 6, 2014 Posted July 6, 2014 That's true, but if you are manipulating the path in some way like splitting it at , things could go awry. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Srex Posted July 6, 2014 Author Posted July 6, 2014 (edited) They are both exactly the same really, ? : just replaces if then. If the rightmost character is then that will trimmed off, else it stays the same. aaah i see thanks dude yeah but theres a read only input box, so I would like it to look correct for the user, so he/she doesn't think it will bug As for the case being almost the same I heard from a coder friend that case is far more efficient And I prefer to learn it the best way in the beginning so i don't have to go back and reschool myself Edited July 6, 2014 by Srex
Moderators Solution Melba23 Posted July 6, 2014 Moderators Solution Posted July 6, 2014 Srex, I would like it to look correct for the userif you are manipulating the path in some way like splitting it at ,Just run StringReplace($sPath, "", "") on the path before using it. M23 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
JohnOne Posted July 6, 2014 Posted July 6, 2014 Now there's a solution^^ AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Srex Posted July 6, 2014 Author Posted July 6, 2014 (edited) Srex, Just run StringReplace($sPath, "", "") on the path before using it. M23 yeah this is perfect Case $ButtonBrowseOutputLoc $sFileSelectFolder = FileSelectFolder("Select output location", "") If Not @error Then $OutPutLoc = $InputWinLocation & $sFileSelectFolder & '\settings.ini' StringReplace($OutPutLoc, "\\", "\") GUICtrlSetData($InputChDir, $OutPutLoc) EndIf But then it still does + i writes "43" infront of the windows location $InputWinLocation is btw the user input for the root of the drive '> Edited July 6, 2014 by Srex
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