Jump to content

Recommended Posts

Posted

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

Posted (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 by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Posted
  On 7/6/2014 at 3:44 PM, Jfish said:
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

Posted

  On 7/6/2014 at 3:55 PM, Jfish said:

@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

Posted (edited)
  On 7/6/2014 at 4:03 PM, Jfish said:

@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 by Srex
  • Moderators
Posted

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? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

Posted

  On 7/6/2014 at 4:13 PM, Melba23 said:

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? :huh:

M23

Really?

Are you kidding me :D

Posted (edited)
  On 7/6/2014 at 4:15 PM, JohnOne said:

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 :P

Edited by Srex
  • Moderators
  • Solution
Posted

Srex,

 

  Quote

I would like it to look correct for the user

  Quote

if you are manipulating the path in some way like splitting it at ,

Just run StringReplace($sPath, "", "") on the path before using it. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

Posted (edited)

  On 7/6/2014 at 4:23 PM, Melba23 said:

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 by Srex

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...