Jump to content
pintas

[SOLVED]Change control value from array

Recommended Posts

pintas

Hi,

The code below creates buttons from an INI file 'Teste.ini'.

I'm trying to change the color for specific buttons when Value0 of a section name is equal to B (for example).

The SectionNames are buttons. And i need to somehow identify those buttons in the array so i can change their color, but i'm very confused...

Can you guys help me out please?

The INI file:

[Button1]
Value0=B
Value1=1
Value2=1

[Button2]
Value0=F
Value1=1
Value2=1

[Button3]
Value0=E
Value1=1
Value2=1

[Button4]
Value0=B
Value1=1
Value2=1

The code:

#include <GUIConstantsEx.au3>
$optbar = IniReadSectionNames(@ScriptDir&"\teste.ini")
local $ButtonBank
$varStartHeight=0
$varStartHeight += 5
Dim $Button[4]
GUICreate("Test")
For $x = 1 To UBound($optbar) - 1
$Button[$x] = GUICtrlCreateButton($optbar[$x], $varStartHeight, 30, 55, 27)
$varStartHeight += 60
Next
GUISetState()
While 1
    $msg=GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

 

Edited by pintas

Share this post


Link to post
Share on other sites
Danyfirex

Hello. You could do this:

#include <Array.au3>
#include <GUIConstantsEx.au3>
$optbar = IniReadSectionNames(@ScriptDir&"\teste.ini")
;~ _ArrayDisplay($optbar)
local $ButtonBank
$varStartHeight=0
$varStartHeight += 5
Dim $Button[4]
GUICreate("Test")
Local $sColor=""
For $x = 1 To UBound($optbar) - 1
$Button[$x-1] = GUICtrlCreateButton($optbar[$x], $varStartHeight, 30, 55, 27)
$sColor=IniRead(@ScriptDir&"\teste.ini",$optbar[$x],"Value0","")
ConsoleWrite($sColor & @CRLF)
If $sColor="B" Then
GUICtrlSetBkColor($Button[$x-1],0x235464)
EndIf
If $sColor="F" Then
GUICtrlSetBkColor($Button[$x-1],0xf53663)
EndIf

If $sColor="E" Then
GUICtrlSetBkColor($Button[$x-1],0x473f6f)
EndIf

$varStartHeight += 60
Next
GUISetState()
While 1
    $msg=GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Saludos

Share this post


Link to post
Share on other sites
pintas

Oh, thank you so much!

Solved!

 

 

Edited by pintas

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

×