Sign in to follow this  
Followers 0
Leonick91

FIleOpenDialogue gicing me trouble

6 posts in this topic

#1 ·  Posted (edited)

Ok, so I am working on a little tool here (Some of you might have heard of Rainmeter, eve used it and seen the config tools some skins use, this is a mod of one such tool).

Anyway, Wouldn't surprise me if many here can see exactly what I am trying to do and what goes wrong as soon as they see the code but I am going to describe the problem a little for you.

So basically, this script loads its information from a file, let's you select an entry, type whatever yo desire in the input field and click set and it will be saved to the file.

What I am trying to do is make it so that you can click a browse button and browse for a certain file, this so you don't have to copy+paste or write in entire file paths.

I've got the button in, and when clicked you get a browse dialogue and whatever file you select is put into the input field, which is exactly what I wanted.

The problem is, it seem using the browse button kills the input field, the field stops getting updated when you select something in the list and clicking the set button no longer writes any new info to the file.

Here is the full code of the script, guessing the error is somewhere in the switch towards the bottom "Switch $nMsg", migh have done something wrong with the FileOpenDialogue

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <array.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <GuiButton.au3>
#include <Misc.au3>
#include <String.au3>
#Include <File.au3>
Opt("TrayIconHide", 1)
$dll = DllOpen("user32.dll")
$refreshpath = "/!RainmeterRefresh SuperBar\Addons\Apps"

$Gui = GUICreate("Configure", 280, 300, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetBkColor(0xF4F4F4)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$Drag = GUICtrlCreatePic("header.jpg", 0, 0, 280, 40, Default, $GUI_WS_EX_PARENTDRAG)
$ExitButton = GUICtrlCreateLabel("X", 263, 40, 20, 18, $SS_CENTER)
GUICtrlSetOnEvent($ExitButton, "clickedExit")
GUICtrlSetCursor(-1, 0)
$VariableList = GUICtrlCreateList("", 15, 58, 250, 170, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$WS_HSCROLL,$WS_VSCROLL))
$VariableDescripton = GUICtrlCreateLabel("", 15, 230, 260, 30)
$VariableInput = GUICtrlCreateInput("", 15, 266, 140, 21)
GUICtrlSetCursor(-1, 5)
$BrowseButton = GUICtrlCreateButton("Browse", 160,265,50,23)
$SetButton = GUICtrlCreateButton("Set", 215, 265, 50, 23)
GUICtrlSetCursor(-1, 0)

GUISetState(@SW_SHOW)

Dim $VarName[200]
Dim $VarDescription[200]
Dim $iniFiles[200]
Dim $VarCount = 0
Dim $FilesCount = 0
Dim $EndIt = 0
Dim $Foundini = 0

$CfgFile = FileOpen ("RainConfigure.cfg", 0)
$VariableSection = FileReadLine ($CfgFile)

Do
    $VarCount = $VarCount + 1
    $VarName[$VarCount] = FileReadLine ($CfgFile)
    $VarDescription[$VarCount] = FileReadLine ($CfgFile)
    If $VarName[$VarCount] = "[Files]" Then $EndIt = 1
Until $EndIt = 1

$iniFiles[1] = $VarDescription[$VarCount]
$FilesCount = $FilesCount + 1

While @error <> -1
    $FilesCount = $FilesCount + 1
    $iniFiles[$FilesCount] = FileReadLine ($CfgFile)
WEnd

FileClose ($CfgFile)
$VarCount = $VarCount - 1
$FilesCount = $FilesCount - 1

For $ListCount = 1 to $VarCount
GUICtrlSetData($VariableList,$VarName[$ListCount] & "|")
Next

GUICtrlSetData($VariableList,$VarName[1])
$CurrentVarName = GUICtrlRead($VariableList)
GUICtrlSetData($VariableDescripton, $VarDescription[1])
GUICtrlSetData($VariableInput, IniRead($iniFiles[1], "Variables", $VarName[1],""))

While 1

    $nMsg = GUIGetMsg()

    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            FileClose($CfgFile)
            ShellExecute("refresh.exe", $refreshpath)
            DllClose($dll)
            Exit
            
        Case $ExitButton
            FileClose($CfgFile)
            Sleep(300)
            Exit

        Case $VariableList
            $CurrentVarName = GUICtrlRead($VariableList)
            For $ListCount = 1 to $VarCount
                if $VarName[$ListCount] = $CurrentVarName Then
                    $CurrentVarDescription = $VarDescription[$ListCount]
                EndIf
            Next
            GUICtrlSetData($VariableDescripton, $CurrentVarDescription)
            For $ListCount = 1 to $FilesCount
                $Temp = IniRead($iniFiles[$ListCount], "Variables", $CurrentVarName,"")
                If $Temp <> "" then
                    $ini2Edit = $iniFiles[$ListCount]
                    GUICtrlSetData($VariableInput, $Temp)
                    ExitLoop
                EndIf
            Next
            
        Case $BrowseButton
            $Var = FileOpenDialog("Browse", @ProgramFilesDir & "\", "All (*.*)|Executable files (*.EXE)", 1 + 2 )
            GUICtrlSetData($VariableInput, $Var)

        Case $SetButton
            For $ListCount = 1 to $FilesCount
                $Temp = IniRead($iniFiles[$ListCount], "Variables", $CurrentVarName,"")

                If $Temp <> "" then
                    IniWrite ($iniFiles[$ListCount], "Variables", $CurrentVarName, GUICtrlRead($VariableInput))
                EndIf
            Next

EndSwitch
WEnd

I searched a little for the error myself by putting a message box in to certain parts of the script.

Putting it directly beneath "Case $VariableList" the boxs will appear when clicking a anything in the list, just like it should, things are still getting selected so no surprise there.

However if you go further in to that case and put the message box after "GUICtrlSetData($VariableInput, $Temp)" then you won't see any message, but this is only if you have fully selected something trough the dialogue, before you do that everything works...

I really hope someone can see what's wrong.

Edited by Leonick91

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

ERROR: clickedExit(): undefined function.

A function is missing ! Posted Image

It seems that $VarCount go over 200

so I get ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$VarName[$VarCount] = FileReadLine ($CfgFile)

^ ERROR

try :

_ArrayAdd ( $VarName, FileReadLine ($CfgFile) )

_ArrayAdd ( $VarDescription, FileReadLine ($CfgFile) )

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hmm, yea it might not run without the file it gets it's data from...

here are all the files it need, should work better

http://dl.dropbox.com/u/732993/Apps.zip

Those parts you mentioned are old and works fine with all the files, those parts I haven't even written, but I am pretty sure that's not where the error is.

Edited by Leonick91

Share this post


Link to post
Share on other sites

OK, So I've figured out what's wrong but now I need help solving it.

For the input box to update when I click an item in the list and for the script to save the data I put it it needs access to files in the scripts directory, when I use the FileOpenDialogue this changes the Working Directory and the script can't find those files any more.

So what I need now is a way to change the Working Directory back again after I have gotten the data I need from the FileOpenDialogue. Any way to do this? Must be...

Share this post


Link to post
Share on other sites

There is: look up FileChangeDir()

HTH,

whim

Share this post


Link to post
Share on other sites

Yea just found it after having tried a few different things and then looked trough the functions about 5 times.

That did it ;)

FileOpenDialogue should have an option not to change working dir ^^

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  
Followers 0