Sign in to follow this  
Followers 0
Klexur

Multiple Tabs and File Access

11 posts in this topic

I'm trying to write a small program that per tab will read a text file basically and allow the user to set values for the items listed. If anybody here uses Rainmeter this is my attempt at a more advanced config tool for changing the skin variables. Basically I want each tab to open a separate file and display the contents and set values.

Here is the code I have so far, but I can't get the second tab to work like the first:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=..\Konfig.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Configures variables used by KlexMeter skins
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P
#AutoIt3Wrapper_Res_LegalCopyright=© Klexur
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
Opt("GUICloseOnESC", 1)

$varTitle = "Konfig"
$varFormBgColor = "0xFFFFFF"
$varFont = "kroeger 05_55 caps"
$varFontSize = "6"
$varListColor = "0xFFFFFF"
$varListBgColor = "0x000000"
$varBtnColor = "0x000000"
$varBtnBgColor = "0xFFFFFF"
$varCfg1 = "Konfig.cfg"
$varCfg2 = "Kalendar.cfg"
$varRefresh = "/!RainmeterRefresh KlexMeter"

#Region ### START Koda GUI section ### Form=Konfig_v2.kxf
$MainForm = GUICreate($varTitle, 345, 245)
GUISetFont($varFontSize, 400, 0, $varFont)

$VariableInput = GUICtrlCreateInput("", 5, 221, 184, 18)
GUICtrlSetColor(-1, $varListColor)
GUICtrlSetBkColor(-1, $varListBgColor)

$SetButton = GUICtrlCreateButton("&Set", 194, 220, 46, 20, $BS_DEFPUSHBUTTON)
GUICtrlSetColor(-1, $varBtnColor)
GUICtrlSetBkColor(-1, $varBtnBgColor)

$RefreshButton = GUICtrlCreateButton("&Refresh", 245, 220, 46, 20)
GUICtrlSetColor(-1, $varBtnColor)
GUICtrlSetBkColor(-1, $varBtnBgColor)

$ExitButton = GUICtrlCreateButton("E&xit", 295, 220, 46, 20)
GUICtrlSetColor(-1, $varBtnColor)
GUICtrlSetBkColor(-1, $varBtnBgColor)

$TabList = GUICtrlCreateTab(5, 5, 335, 207)
$Tab0 = GUICtrlCreateTabItem("General")
$List0 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
GUICtrlSetColor(-1, $varListColor)
GUICtrlSetBkColor(-1, $varListBgColor)

$Edit0 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
GUICtrlSetColor(-1, $varListColor)
GUICtrlSetBkColor(-1, $varListBgColor)

$Tab1 = GUICtrlCreateTabItem("Calendar")
$List1 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
GUICtrlSetColor(-1, $varListColor)
GUICtrlSetBkColor(-1, $varListBgColor)

$Edit1 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
GUICtrlSetColor(-1, $varListColor)
GUICtrlSetBkColor(-1, $varListBgColor)

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $CfgFile
_ActiveTab()

While 1
    _ActiveTab()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            FileClose($CfgFile)
            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, "")
            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 $SetButton
            For $ListCount = 1 to $FilesCount
                $Temp = IniRead($iniFiles[$ListCount], "Variables", $CurrentVarName,"")
                If $Temp <> "" then
                    IniWrite ($iniFiles[$ListCount], "Variables", $CurrentVarName, GUICtrlRead($VariableInput))
                EndIf
            Next

        Case $RefreshButton
            ;ShellExecute("Resources\refresh.exe", $varRefresh)
            $hwnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
            _SendMessage($hwnd, 273, 4001, 0)
    EndSwitch
WEnd

Func _ActiveTab()
    Local $hTab
    Global $varConfigName
    Global $VariableList
    Global $VariableDescription
    _Is_ConfigFile_Set()
    Select
        Case _GUICtrlTab_GetCurSel($hTab) = "General"
            $varConfigName = $varCfg1
            $VariableList  = $List0
            $VariableDescription = $Edit0
        Case _GUICtrlTab_GetCurSel($hTab) = "Calendar"
            $varConfigName = $varCfg2
            $VariableList  = $List1
            $VariableDescription = $Edit1
    EndSelect
    _FileOperations()
EndFunc

Func _Is_ConfigFile_Set()
    If $CfgFile <> -1 Then
        FileClose($CfgFile)
    Else
    EndIf
EndFunc

Func _FileOperations()  
    Dim $VarName[200]
    Dim $VarDescription[200]
    Dim $iniFiles[200]
    Dim $VarCount = 0
    Dim $FilesCount = 0
    Dim $EndIt = 0
    Dim $Foundini = 0
    
    If FileExists($varConfigName) Then
        $CfgFile = FileOpen ($varConfigName, 0)
    ElseIf FileExists("Resources\" & $varConfigName) Then
        $CfgFile = FileOpen ("Resources\" & $varConfigName, 0)
    Else
        MsgBox(16, "Error", $varConfigName & " was not found.")
        Exit
    EndIf
    
    $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

EndFunc

Quiet but very inquisitive

Share this post


Link to post
Share on other sites



I'm sorry, but this thing is a mess. I spent a while just trying to understand what you are trying to do.

You are reading INI files by using FileReadLine? Use INIRead or INIReadSection.

You had two colors declared a bunch of times. I cleaned that up.

You declared global variables inside functions. Either use local or declare them at the beginning of the script.

I do not have anymore time right now to clean this up. I did comment in what you need to check or fix.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=..\Konfig.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Configures variables used by KlexMeter skins
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P
#AutoIt3Wrapper_Res_LegalCopyright=© Klexur
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Opt("GUICloseOnESC", 1)
Global $CfgFile
DIM $varTitle = "Konfig"
DIM $varFont = "kroeger 05_55 caps"
DIM $varFontSize = "6"

DIM $Color  = "0xFFFFFF"
DIM $BgColor = "0x000000"

DIM $varCfg1 = "Konfig.cfg" ;you don't have a check to verify the file exist when your script first runs. You may want to fix that.
DIM $varCfg2 = "Kalendar.cfg" ;you don't have a check to verify the file exist when your script first runs. You may want to fix that.
;I see you have a check inside a function however to look, but checking at the start is better. 
DIM $varRefresh = "/!RainmeterRefresh KlexMeter"
DIM $varConfigName
DIM $VariableList
Global $VariableDescription ; what is this for? You are declaring it, but it doesn't point to anything. You have
                            ; GUICtrlSetData($VariableDescripton, "") on line 106 but what is it updating?

Dim $VarName[200]
Global $VarDescription[200]
Dim $iniFiles[200] ;you need 200 ini files? 
Dim $VarCount = 0
Dim $FilesCount = 0
Dim $EndIt = 0
Dim $Foundini = 0

$MainForm = GUICreate($varTitle, 345, 245)
$VariableInput = GUICtrlCreateInput("", 5, 221, 184, 18)
$SetButton = GUICtrlCreateButton("&Set", 194, 220, 46, 20, $BS_DEFPUSHBUTTON)
$RefreshButton = GUICtrlCreateButton("&Refresh", 245, 220, 46, 20)
$ExitButton = GUICtrlCreateButton("E&xit", 295, 220, 46, 20)
$TabList = GUICtrlCreateTab(5, 5, 335, 207)
$Tab0 = GUICtrlCreateTabItem("General")
$List0 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
$Edit0 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
$Tab1 = GUICtrlCreateTabItem("Calendar")
$List1 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
$Edit1 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
GUISetFont($varFontSize, 400, 0, $varFont) ; moved

;color-----------------------
;This can be done in an array if desired, but it won't decrease the amount of lines of code
;You used only two colors so duplicates were removed
GUICtrlSetBkColor   ($SetButton,       $Color)
GUICtrlSetBkColor   ($RefreshButton,   $Color)
GUICtrlSetBkColor   ($ExitButton,      $Color)
GUICtrlSetColor     ($VariableInput,   $Color) 
GUICtrlSetColor     ($List0,           $Color)
GUICtrlSetColor     ($Edit0,           $Color)
GUICtrlSetColor     ($List1,           $Color)
GUICtrlSetColor     ($Edit1,           $Color)
GUICtrlSetColor     ($SetButton,       $BgColor)
GUICtrlSetColor     ($RefreshButton,   $BgColor)
GUICtrlSetColor     ($ExitButton,      $BgColor)
GUICtrlSetBkColor   ($VariableInput,   $BgColor)
GUICtrlSetBkColor   ($List0,           $BgColor)
GUICtrlSetBkColor   ($Edit0,           $BgColor)
GUICtrlSetBkColor   ($List1,           $BgColor)
GUICtrlSetBkColor   ($Edit1,           $BgColor)
;-----------------------------

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
_ActiveTab()
While 1
    _ActiveTab()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            FileClose($CfgFile)
            Exit

        Case $ExitButton
            FileClose($CfgFile)
            Sleep(300) ;why is the sleep command needed? 
            Exit

        Case $VariableList
            $CurrentVarName = GUICtrlRead($VariableList)
            For $ListCount = 1 to $VarCount
                if $VarName[$ListCount] = $CurrentVarName Then
                    $CurrentVarDescription = $VarDescription[$ListCount]
                EndIf
            Next
            GUICtrlSetData($VariableDescripton, "")
            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 $SetButton
            For $ListCount = 1 to $FilesCount
                $Temp = IniRead($iniFiles[$ListCount], "Variables", $CurrentVarName,"")
                If $Temp <> "" then
                    IniWrite ($iniFiles[$ListCount], "Variables", $CurrentVarName, GUICtrlRead($VariableInput))
                EndIf
            Next

        Case $RefreshButton
            ;ShellExecute("Resources\refresh.exe", $varRefresh)
            $hwnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
            _SendMessage($hwnd, 273, 4001, 0)
    EndSwitch
WEnd

Func _ActiveTab()
    Local $hTab
    _Is_ConfigFile_Set()
    Select
        Case _GUICtrlTab_GetCurSel($hTab) = "General"
            $varConfigName = $varCfg1
            $VariableList  = $List0
            $VariableDescription = $Edit0
        Case _GUICtrlTab_GetCurSel($hTab) = "Calendar"
            $varConfigName = $varCfg2
            $VariableList  = $List1
            $VariableDescription = $Edit1
    EndSelect
    _FileOperations()
EndFunc

Func _Is_ConfigFile_Set()
    If $CfgFile <> -1 Then
        FileClose($CfgFile)
    Else
    EndIf
EndFunc

Func _FileOperations()  
    ;------------------------------------------------------------------------------------------------------------------------
    If FileExists($varConfigName) Then
        $CfgFile = FileOpen ($varConfigName, 0);you don't need FileOpen if you are reading INI files. Are they INI files? 
                                                ; If so, then use INIRead or INIReadSection.
    ElseIf FileExists("Resources\" & $varConfigName) Then
        $CfgFile = FileOpen ("Resources\" & $varConfigName, 0) 
    Else
        MsgBox(16, "Error", $varConfigName & " was not found.")
        Exit
    EndIf
    ;You have a file check in the loop. This is bad. You only need to look for the INI files when the script first starts. 
    ;------------------------------------------------------------------------------------------------------------------------
    $VariableSection = FileReadLine ($CfgFile); Why are you reading lines? Use INIRead or INIReadSection to read the file
    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

EndFunc

Share this post


Link to post
Share on other sites

I'm sorry, but this thing is a mess. I spent a while just trying to understand what you are trying to do.

You are reading INI files by using FileReadLine? Use INIRead or INIReadSection.

You had two colors declared a bunch of times. I cleaned that up.

You declared global variables inside functions. Either use local or declare them at the beginning of the script.

I do not have anymore time right now to clean this up. I did comment in what you need to check or fix.

wow, im really sorry, i didnt realize it was that messy =[ i started with a basic program and have added to it since then. im sorry i didnt mean to cause such trouble, so thank you for all your help so far. as for the INIRead commands i hadnt yet come across them yet.

the program is intended to read only an INI like file (the .cfg) which looks as follows:

[Variables]
; List of the variables contained in the .inc file
Variable1Name
Variable one's description of what it is or applies to.
Variable2Name
Variable two's description of what it is or applies to.
Variable3Name
Variable three's description of what it is or applies to.
[Files]
; Path to the variable file that is actually written to
File\Path\Variables.inc

then write the values for the variables entered by the user to the Variables.inc file

since posting this i have made a lot of changes so i will be comparing what u changed and suggested now. again, thank you for setting me straight.


Quiet but very inquisitive

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Okay here is what I managed to work out so far based on what you suggested, MPH. I'm still working on it, but this just updating my progress I guess. Again, sorry for the huge mess I made, and the ensuing frustration you probably had, this is my first big program with AutoIt.

The problem now is that the varDescription isn't being shown in Edit0 nor Edit1, also List1 isn't being updated with the variables. Also I haven't looked up how to implement INIRead yet, sorry I was just trying to clean up my mess first and still keep some progress =/

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=..\Konfig.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Configures variables used by KlexMeter skins
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P
#AutoIt3Wrapper_Res_LegalCopyright=© Klexur
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Opt("GUICloseOnESC", 1)
DIM $varTitle = "Konfig"
DIM $varFont = "kroeger 05_55 caps"
DIM $varFontSize = "6"

DIM $Color  = "0xFFFFFF"
DIM $BgColor = "0x000000"

#Region GUI
$MainForm = GUICreate($varTitle, 345, 245)
GUISetFont($varFontSize, 400, 0, $varFont)
$VariableInput = GUICtrlCreateInput("", 5, 221, 184, 18)
$SetButton = GUICtrlCreateButton("&Set", 194, 220, 46, 20, $BS_DEFPUSHBUTTON)
$RefreshButton = GUICtrlCreateButton("&Refresh", 245, 220, 46, 20)
$ExitButton = GUICtrlCreateButton("E&xit", 295, 220, 46, 20)
$TabList = GUICtrlCreateTab(5, 5, 335, 207)
$Tab0 = GUICtrlCreateTabItem("General")
$List0 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
$Edit0 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
$Tab1 = GUICtrlCreateTabItem("Calendar")
$List1 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
$Edit1 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))

;Color -----------------------
;This can be done in an array if desired, but it won't decrease the amount of lines of code
;You used only two colors so duplicates were removed
GUICtrlSetBkColor   ($SetButton,       $Color)
GUICtrlSetBkColor   ($RefreshButton,   $Color)
GUICtrlSetBkColor   ($ExitButton,      $Color)
GUICtrlSetColor     ($VariableInput,   $Color) 
GUICtrlSetColor     ($List0,           $Color)
GUICtrlSetColor     ($Edit0,           $Color)
GUICtrlSetColor     ($List1,           $Color)
GUICtrlSetColor     ($Edit1,           $Color)
GUICtrlSetColor     ($SetButton,       $BgColor)
GUICtrlSetColor     ($RefreshButton,   $BgColor)
GUICtrlSetColor     ($ExitButton,      $BgColor)
GUICtrlSetBkColor   ($VariableInput,   $BgColor)
GUICtrlSetBkColor   ($List0,           $BgColor)
GUICtrlSetBkColor   ($Edit0,           $BgColor)
GUICtrlSetBkColor   ($List1,           $BgColor)
GUICtrlSetBkColor   ($Edit1,           $BgColor)
;-----------------------------

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion

DIM $varCfg0 = "Konfig.cfg"
DIM $varCfg1 = "Kalendar.cfg"
;I see you have a check inside a function however to look, but checking at the start is better. 
DIM $varRefresh = "/!RainmeterRefresh KlexMeter"

Global $VariableList
Global $VariableDescription ; what is this for? You are declaring it, but it doesn't point to anything. You have
                            ; GUICtrlSetData($VariableDescripton, "") on line 106 but what is it updating?
Global $CfgFile
Dim $varConfigName
Global $VarName
Dim $VarName0[200]
Dim $VarName1[200]
Global $VarDescription
Dim $VarDescription0[200]
Dim $VarDescription1[200]
Dim $iniFiles[200] ;you need 200 ini files? 
Global $VarCount = 0
Dim $VarCount0 = 0
Dim $VarCount1 = 0
Dim $FilesCount = 0
Dim $EndIt = 0
Dim $Foundini = 0

_LoadTabs() ; Load names and values into list box and edit box
Func _LoadTabs()
    ; Tab0
    $varConfigName = $varCfg0
    _CheckFiles()
    $VariableList  = $List0
    $VariableDescription = $Edit0
    $VarName = $VarName0
    $VarDescription = $VarDescription0
    $VarCount = $VarCount0
    _FileOperations()
    ; Tab1
    $varConfigName = $varCfg1
    _CheckFiles()
    $VariableList  = $List1
    $VariableDescription = $Edit1
    $VarName = $VarName1
    $VarDescription = $VarDescription1
    $VarCount = $VarCount1
    _FileOperations()
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            FileClose($CfgFile)
            Exit

        Case $ExitButton
            FileClose($CfgFile)
            Exit

        Case $VariableList
            _ActiveTab()
            $CurrentVarName = GUICtrlRead($VariableList)
            For $ListCount = 1 to $VarCount
                If $VarName[$ListCount] = $CurrentVarName Then
                    $CurrentVarDescription = $VarDescription[$ListCount]
                EndIf
            Next
            ;GUICtrlSetData($VariableDescripton, "")
            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 $SetButton
            _ActiveTab()
            For $ListCount = 1 to $FilesCount
                $Temp = IniRead($iniFiles[$ListCount], "Variables", $CurrentVarName,"")
                If $Temp <> "" then
                    IniWrite ($iniFiles[$ListCount], "Variables", $CurrentVarName, GUICtrlRead($VariableInput))
                EndIf
            Next

        Case $RefreshButton
            $hwnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
            _SendMessage($hwnd, 273, 4001, 0)
    EndSwitch
WEnd

Func _CheckFiles() ; Check if cfg files are present
    If FileExists($varConfigName) Then
        $CfgFile = FileOpen ($varConfigName, 0)
        ; You don't need FileOpen if you are reading INI files. If so, then use INIRead or INIReadSection.
    ElseIf FileExists("Resources\" & $varConfigName) Then
        $CfgFile = FileOpen ("Resources\" & $varConfigName, 0) 
    Else
        MsgBox(16, "Error", $varConfigName & " was not found.")
        Exit
    EndIf
EndFunc

Func _ActiveTab()
    Select
        Case _GUICtrlTab_GetCurFocus($TabList) = 0
            $varConfigName = $varCfg0
            $VariableList  = $List0
            $VariableDescription = $Edit0
            $VarCount = $VarCount0
            ;_FileOperations()
        Case _GUICtrlTab_GetCurFocus($TabList) = 1
            $varConfigName = $varCfg1
            $VariableList  = $List1
            $VariableDescription = $Edit1
            $VarCount = $VarCount1
            ;_FileOperations()
    EndSelect
EndFunc

Func _FileOperations()  
    ; Why are you reading lines? Use INIRead or INIReadSection to read the file
    $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

EndFunc
Edited by Klexur

Quiet but very inquisitive

Share this post


Link to post
Share on other sites

bumping this hoping somebody can help =[


Quiet but very inquisitive

Share this post


Link to post
Share on other sites

ok, so i completely revamped the code, and the original file structure that i got from the rainmteter community (hope that goes over well) and i got this thing to work mostly.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=..\Konfig.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Configures variables used by KlexMeter skins
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P
#AutoIt3Wrapper_Res_LegalCopyright=© Klexur
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Opt("GUICloseOnESC", 1)
DIM $varCfgPath = "Resources\"
DIM $varCfg0 = "UserVariables.inc"
DIM $varDesc0 = "UVarDesc.inc"
DIM $varCfg1 = "Styles.inc"
DIM $varDesc1 = "StyleDesc.inc"

DIM $varTitle = "Konfig"
DIM $varFont = "kroeger 05_55 caps"
DIM $varFontSize = "6"

DIM $Color  = "0xFFFFFF"
DIM $BgColor = "0x000000"

#Region GUI
$MainForm = GUICreate($varTitle, 345, 245)
GUISetFont($varFontSize, 400, 0, $varFont)
$VariableInput = GUICtrlCreateInput("", 5, 221, 184, 18)
$SetButton = GUICtrlCreateButton("&Set", 194, 220, 46, 20, $BS_DEFPUSHBUTTON)
$RefreshButton = GUICtrlCreateButton("&Refresh", 245, 220, 46, 20)
$ExitButton = GUICtrlCreateButton("E&xit", 295, 220, 46, 20)
$TabList = GUICtrlCreateTab(5, 5, 335, 207)
$Tab0 = GUICtrlCreateTabItem($varCfg0)
$List0 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
$Edit0 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
$Tab1 = GUICtrlCreateTabItem($varCfg1)
$List1 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
$Edit1 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))

;Color -----------------------
;This can be done in an array if desired, but it won't decrease the amount of lines of code
;You used only two colors so duplicates were removed
GUICtrlSetBkColor   ($SetButton,       $Color)
GUICtrlSetBkColor   ($RefreshButton,   $Color)
GUICtrlSetBkColor   ($ExitButton,      $Color)
GUICtrlSetColor     ($VariableInput,   $Color) 
GUICtrlSetColor     ($List0,           $Color)
GUICtrlSetColor     ($Edit0,           $Color)
GUICtrlSetColor     ($List1,           $Color)
GUICtrlSetColor     ($Edit1,           $Color)
GUICtrlSetColor     ($SetButton,       $BgColor)
GUICtrlSetColor     ($RefreshButton,   $BgColor)
GUICtrlSetColor     ($ExitButton,      $BgColor)
GUICtrlSetBkColor   ($VariableInput,   $BgColor)
GUICtrlSetBkColor   ($List0,           $BgColor)
GUICtrlSetBkColor   ($Edit0,           $BgColor)
GUICtrlSetBkColor   ($List1,           $BgColor)
GUICtrlSetBkColor   ($Edit1,           $BgColor)
;-----------------------------

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion

Global $read0v = IniReadSection($varCfgPath & $varCfg0, "Variables") ;KEYs & VALUEs
Global $read0d = IniReadSection($varCfgPath & $varDesc0, "Descriptions") ;VALUEs
Global $read1v = IniReadSection($varCfgPath & $varCfg1, "StyleLable") ;KEYs
Global $read1d = IniReadSection($varCfgPath & $varDesc1, "Descriptions") ;VALUEs

Global $ActiveList
Global $ActiveEdit
Global $ActiveVar = _GUICtrlListBox_GetSelItemsText($ActiveList)
Global $ActiveValue = $read0v[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE
Global $ActiveDesc = $read0d[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE
Global $ActiveCfg

_LoadVariables()
Func _LoadVariables() ; Load variables into list boxes
    ; Tab0> List0
    If @error Then 
        MsgBox(4096, "", "Error reading " & $varCfg0)
    Else
        For $i = 1 To $read0v[0][0]
            GUICtrlSetData($List0, $read0v[$i][0]) ;KEY
        Next
    EndIf
    ; Tab1> List1
    If @error Then 
        MsgBox(4096, "", "Error reading " & $varCfg1)
    Else
        For $i = 1 To $read1v[0][0]
            GUICtrlSetData($List1, $read1v[$i][0]) ;KEY
        Next
    EndIf
    
EndFunc

_ActiveTab()
Func _ActiveTab()
    Select
        Case _GUICtrlTab_GetCurFocus($TabList) = 0
            $ActiveList  = $List0
            $ActiveEdit = $Edit0
            $ActiveCfg = $varCfg0
        Case _GUICtrlTab_GetCurFocus($TabList) = 1
            $ActiveList  = $List1
            $ActiveEdit = $Edit1
            $ActiveCfg = $varCfg1
    EndSelect
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ExitButton
            Exit
        
        Case $ActiveList
            _ActiveTab()
            GUICtrlSetData($ActiveEdit, $ActiveDesc) ;VALUE
            GUICtrlSetData($VariableInput, $ActiveValue) ;VALUE
            
        Case $SetButton
            _ActiveTab()
            IniWrite($varCfgPath & $ActiveCfg, "Variables", $ActiveVar, GUICtrlRead($VariableInput))
            
        Case $RefreshButton
            $hwnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
            _SendMessage($hwnd, 273, 4001, 0)
        
    EndSwitch
WEnd

could anybody help me possibly shorten and clean up the code more? also i still seem to get an error for $List1 =[


Quiet but very inquisitive

Share this post


Link to post
Share on other sites

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

added

The script crashes at Line 86 for me because it can't find the *.ini file that it's supposed to be reading. The first thing the script should do when it runs is check to see if the *.ini file exists. If it doesn't then the script should exit with a warning message.

well it works fine for me, but that might be because i actually have the files it needs to read. also i thought the IF statements in the _LoadVariables() functions would be ok as a file existence check? if not where do u suggest i code it in?

sorry for all the questions =/


Quiet but very inquisitive

Share this post


Link to post
Share on other sites

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=Konfig-IniWriter.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Configures variables used by KlexMeter skins
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P
#AutoIt3Wrapper_Res_LegalCopyright=© Klexur
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Opt("GUICloseOnESC", 1)
DIM $varCfgPath = "Resources\"
DIM $varCfg0 = "UserVariables.inc"
DIM $varDesc0 = "UVarDesc.inc"
DIM $varCfg1 = "Styles.inc"
DIM $varDesc1 = "StyleDesc.inc"

DIM $varTitle = "Konfig - IniWriter"
DIM $varFont = "kroeger 05_55 caps"
DIM $varFontSize = "6"

DIM $Color  = "0xFFFFFF"
DIM $BgColor = "0x000000"

If Not FileExists($varCfgPath & $varCfg0) Then 
    MsgBox(16, "Error", $varCfgPath & $varCfg0 & " not found")
ElseIf Not FileExists($varCfgPath & $varCfg1) Then
    MsgBox(16, "Error", $varCfgPath & $varCfg1 & " not found")
    Exit
EndIf

#Region GUI
$MainForm = GUICreate($varTitle, 345, 245)
GUISetFont($varFontSize, 400, 0, $varFont)
$VariableInput = GUICtrlCreateInput("", 5, 221, 184, 18)
$SetButton = GUICtrlCreateButton("&Set", 194, 220, 46, 20, $BS_DEFPUSHBUTTON)
$RefreshButton = GUICtrlCreateButton("&Refresh", 245, 220, 46, 20)
$ExitButton = GUICtrlCreateButton("E&xit", 295, 220, 46, 20)
$TabList = GUICtrlCreateTab(5, 5, 335, 207)
$Tab0 = GUICtrlCreateTabItem($varCfg0)
$List0 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
$Edit0 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
$Tab1 = GUICtrlCreateTabItem($varCfg1)
$List1 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
$Edit1 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))

;Color -----------------------
;This can be done in an array if desired, but it won't decrease the amount of lines of code
;You used only two colors so duplicates were removed
GUICtrlSetBkColor   ($SetButton,       $Color)
GUICtrlSetBkColor   ($RefreshButton,   $Color)
GUICtrlSetBkColor   ($ExitButton,      $Color)
GUICtrlSetColor     ($VariableInput,   $Color) 
GUICtrlSetColor     ($List0,           $Color)
GUICtrlSetColor     ($Edit0,           $Color)
GUICtrlSetColor     ($List1,           $Color)
GUICtrlSetColor     ($Edit1,           $Color)
GUICtrlSetColor     ($SetButton,       $BgColor)
GUICtrlSetColor     ($RefreshButton,   $BgColor)
GUICtrlSetColor     ($ExitButton,      $BgColor)
GUICtrlSetBkColor   ($VariableInput,   $BgColor)
GUICtrlSetBkColor   ($List0,           $BgColor)
GUICtrlSetBkColor   ($Edit0,           $BgColor)
GUICtrlSetBkColor   ($List1,           $BgColor)
GUICtrlSetBkColor   ($Edit1,           $BgColor)
;-----------------------------

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion

Global $read0v = IniReadSection($varCfgPath & $varCfg0, "Variables") ;KEYs & VALUEs
Global $read0d = IniReadSection($varCfgPath & $varDesc0, "Descriptions") ;VALUEs
Global $read1v = IniReadSection($varCfgPath & $varCfg1, "StyleLable") ;KEYs
Global $read1d = IniReadSection($varCfgPath & $varDesc1, "Descriptions") ;VALUEs

Global $ActiveList
Global $ActiveEdit
Global $ActiveVar = _GUICtrlListBox_GetSelItemsText($ActiveList)
Global $ActiveValue = $read0v[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE
Global $ActiveDesc = $read0d[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE
Global $ActiveCfg

_LoadVariables()
Func _LoadVariables() ; Load variables into list boxes
    ; Tab0> List0
    If @error Then 
        MsgBox(4096, "", "Error reading " & $varCfg0)
    Else
        For $i = 1 To $read0v[0][0]
            GUICtrlSetData($List0, $read0v[$i][0]) ;KEY
        Next
    EndIf
    ; Tab1> List1
    If @error Then 
        MsgBox(4096, "", "Error reading " & $varCfg1)
    Else
        For $i = 1 To $read1v[0][0]
            GUICtrlSetData($List1, $read1v[$i][0]) ;KEY
        Next
    EndIf
    
EndFunc

_ActiveTab()
Func _ActiveTab()
    Select
        Case _GUICtrlTab_GetCurFocus($TabList) = 0
            $ActiveList  = $List0
            $ActiveEdit = $Edit0
            $ActiveCfg = $varCfg0
        Case _GUICtrlTab_GetCurFocus($TabList) = 1
            $ActiveList  = $List1
            $ActiveEdit = $Edit1
            $ActiveCfg = $varCfg1
    EndSelect
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ExitButton
            Exit
        
        Case $ActiveList
            _ActiveTab()
            GUICtrlSetData($ActiveEdit, $ActiveDesc) ;VALUE
            GUICtrlSetData($VariableInput, $ActiveValue) ;VALUE
            
        Case $SetButton
            _ActiveTab()
            IniWrite($varCfgPath & $ActiveCfg, "Variables", $ActiveVar, GUICtrlRead($VariableInput))
            
        Case $RefreshButton
            $hwnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
            _SendMessage($hwnd, 273, 4001, 0)
        
    EndSwitch
WEnd

ok, file check added, now it still wont recognize $read1v as an array. it keeps throwing an error on line 112


Quiet but very inquisitive

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

ok, well im not entirely sure but i fixed the problem that kept arising saying there was an error on line 112. all i did was change the ini file that was referenced. right now im trying to determine how to detect when the focused tab changes so that the variables update, but i can prob figure this out on my own.

as for installing rainmeter, if u dont mind my asking, but why not? i hope u didnt have a bad experience =/ but thanks for all the help =D

Edited by Klexur

Quiet but very inquisitive

Share this post


Link to post
Share on other sites

The last time I used Rainmeter, it had a serious memory leak and Rainy was not planning on developing the program any further.

well it is now back in active development and tons of new features have been added, but it's okay =] to each their own.

also i think i have come to a stable version:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_outfile=Konfig-IniWriter.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Configures settings for the KlexMeter skins.
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P
#AutoIt3Wrapper_Res_LegalCopyright=© Klexur
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Opt("GUICloseOnESC", 1)
DIM $varCfgPath = "Resources\"
DIM $varCfg0 = "UserVariables.inc"
DIM $varDesc0 = "UVarDesc.inc"
DIM $varCfg1 = "Skins\Azure.inc"
DIM $varDesc1 = "UVarDesc.inc"

DIM $varTitle = "Konfig - IniWriter"
DIM $varFont = "kroeger 05_55 caps"
DIM $varFontSize = "6"

DIM $Color  = "0xFFFFFF"
DIM $BgColor = "0x000000"

If Not FileExists($varCfgPath & $varCfg0) Then 
    MsgBox(16, "Error", $varCfgPath & $varCfg0 & " not found")
ElseIf Not FileExists($varCfgPath & $varCfg1) Then
    MsgBox(16, "Error", $varCfgPath & $varCfg1 & " not found")
    Exit
EndIf

#Region GUI
$MainForm = GUICreate($varTitle, 345, 245)
GUISetFont($varFontSize, 400, 0, $varFont)
$VariableInput = GUICtrlCreateInput("", 5, 221, 184, 18)
$SetButton = GUICtrlCreateButton("&Set", 194, 220, 46, 20, $BS_DEFPUSHBUTTON)
$RefreshButton = GUICtrlCreateButton("&Refresh", 245, 220, 46, 20)
$ExitButton = GUICtrlCreateButton("E&xit", 295, 220, 46, 20)
$TabList = GUICtrlCreateTab(5, 5, 335, 207)
$Tab0 = GUICtrlCreateTabItem($varCfg0)
$List0 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
$Edit0 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))
$Tab1 = GUICtrlCreateTabItem($varCfg1)
$List1 = GUICtrlCreateList("", 9, 30, 160, 176, BitOR($WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetFont(-1, $varFontSize, 400, 0, $varFont)
$Edit1 = GUICtrlCreateEdit("", 174, 30, 160, 176, BitOR($ES_READONLY,$ES_MULTILINE,$ES_AUTOVSCROLL))

;Color -----------------------
;This can be done in an array if desired, but it won't decrease the amount of lines of code
;You used only two colors so duplicates were removed
GUICtrlSetBkColor   ($SetButton,       $Color)
GUICtrlSetBkColor   ($RefreshButton,   $Color)
GUICtrlSetBkColor   ($ExitButton,      $Color)
GUICtrlSetColor     ($VariableInput,   $Color) 
GUICtrlSetColor     ($List0,           $Color)
GUICtrlSetColor     ($Edit0,           $Color)
GUICtrlSetColor     ($List1,           $Color)
GUICtrlSetColor     ($Edit1,           $Color)
GUICtrlSetColor     ($SetButton,       $BgColor)
GUICtrlSetColor     ($RefreshButton,   $BgColor)
GUICtrlSetColor     ($ExitButton,      $BgColor)
GUICtrlSetBkColor   ($VariableInput,   $BgColor)
GUICtrlSetBkColor   ($List0,           $BgColor)
GUICtrlSetBkColor   ($Edit0,           $BgColor)
GUICtrlSetBkColor   ($List1,           $BgColor)
GUICtrlSetBkColor   ($Edit1,           $BgColor)
;-----------------------------

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion

Global $read0v = IniReadSection($varCfgPath & $varCfg0, "Variables") ;KEYs & VALUEs
Global $read0d = IniReadSection($varCfgPath & $varDesc0, "Descriptions") ;VALUEs
Global $read1v = IniReadSection($varCfgPath & $varCfg1, "Variables") ;KEYs
Global $read1d = IniReadSection($varCfgPath & $varDesc1, "Descriptions2") ;VALUEs

Global $ActiveList
Global $ActiveEdit
Global $ActiveVar = _GUICtrlListBox_GetSelItemsText($ActiveList)
Global $ActiveValue
Global $ActiveDesc
Global $ActiveCfg

_LoadVariables()
Func _LoadVariables() ; Load variables into list boxes
    ; Tab0> List0
    If @error Then 
        MsgBox(4096, "", "Error reading " & $varCfg0)
    Else
        For $i = 1 To $read0v[0][0]
            GUICtrlSetData($List0, $read0v[$i][0]) ;KEY
        Next
    EndIf
    ; Tab1> List1
    If @error Then 
        MsgBox(4096, "", "Error reading " & $varCfg1)
    Else
        For $i = 1 To $read1v[0][0]
            GUICtrlSetData($List1, $read1v[$i][0]) ;KEY
        Next
    EndIf
    
EndFunc

_ActiveTab()
Func _ActiveTab()
    Select
        Case _GUICtrlTab_GetCurSel($TabList) = 0
            $ActiveList  = $List0
            $ActiveEdit = $Edit0
            $ActiveCfg = $varCfg0
            $ActiveValue = $read0v[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE
            $ActiveDesc = $read0d[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE
        Case _GUICtrlTab_GetCurSel($TabList) = 1
            $ActiveList  = $List1
            $ActiveEdit = $Edit1
            $ActiveCfg = $varCfg1
            $ActiveValue = $read1v[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE
            $ActiveDesc = $read1d[_GUICtrlListBox_GetCurSel($ActiveList) + 1][1] ;VALUE         
    EndSelect
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ExitButton
            Exit
        
        Case $TabList
            _ActiveTab()
        
        Case $ActiveList
            _ActiveTab()
            GUICtrlSetData($ActiveEdit, $ActiveDesc) ;VALUE
            GUICtrlSetData($VariableInput, $ActiveValue) ;VALUE
            
        Case $SetButton
            _ActiveTab()
            IniWrite($varCfgPath & $ActiveCfg, "Variables", $ActiveVar, GUICtrlRead($VariableInput))
            
        Case $RefreshButton
            $hwnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
            _SendMessage($hwnd, 273, 4001, 0)
        
    EndSwitch
WEnd

Quiet but very inquisitive

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