Sign in to follow this  
Followers 0
Fran

tidying code

3 posts in this topic

Can someone help me shorten this code please? I'm going crazy with all the variables.. copy & paste and whotnotelse.

Please... ;)

$pb0 = "HC200"
$pb1 = "HC300"
$pb2 = "HCA3L"
$pb3 = "HCA4L"
$pb4 = "SB200"
$pb5 = "SB200"
$pb6 = "SB300"
$pb7 = "SBA3L"
$pb8 = "SBA4L"
$pb9 = "SBA4P"
$pb10 = "SCA4P"
$pb11 = "SCA5L"
$pb12 = "SCMIN"

GUICtrlSetData($chkPHOTOBOOKS[0], $pb0)
GUICtrlSetData($chkPHOTOBOOKS[1], $pb1)
GUICtrlSetData($chkPHOTOBOOKS[2], $pb2)
GUICtrlSetData($chkPHOTOBOOKS[3], $pb3)
GUICtrlSetData($chkPHOTOBOOKS[4], $pb4)
GUICtrlSetData($chkPHOTOBOOKS[5], $pb5)
GUICtrlSetData($chkPHOTOBOOKS[6], $pb6)
GUICtrlSetData($chkPHOTOBOOKS[7], $pb7)
GUICtrlSetData($chkPHOTOBOOKS[8], $pb8)
GUICtrlSetData($chkPHOTOBOOKS[9], $pb9)
GUICtrlSetData($chkPHOTOBOOKS[10], $pb10)
GUICtrlSetData($chkPHOTOBOOKS[11], $pb11)
GUICtrlSetData($chkPHOTOBOOKS[12], $pb12)
    If IniRead($iniFile, $SECTION, $pb0, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[0], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[0], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb1, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[1], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[1], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb2, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[2], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[2], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb3, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[3], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[3], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb4, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[4], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[4], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb5, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[5], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[5], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb6, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[6], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[6], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb7, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[7], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[7], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb8, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[8], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[8], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb9, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[9], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[9], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb10, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[10], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[10], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb11, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[11], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[11], $GUI_UNCHECKED)
    EndIf
    If IniRead($iniFile, $SECTION, $pb12, "0") = "1" Then
        GUICtrlSetState($chkPHOTOBOOKS[12], $GUI_CHECKED)
    Else
        GUICtrlSetState($chkPHOTOBOOKS[12], $GUI_UNCHECKED)
    EndIf

    If $CATEGORY = "PHOTOBOOKS" Then
        GUICtrlSetState($chkPHOTOBOOKS[0], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[1], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[2], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[3], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[4], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[5], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[6], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[7], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[8], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[9], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[10], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[11], $GUI_ENABLE)
        GUICtrlSetState($chkPHOTOBOOKS[12], $GUI_ENABLE)

1 section from my ini file:

[PHOTOBOOKS]
SAMPLE_ALBUMS=10001234, 10001235, 10001236, 10001237, 10001238, 10001239, 10001240, 10001241
IMAGE_CONTENTUPDATE=smiley1.jpg
IMAGE_WEB=
MYSQL_ID=
HCA4L=1
HCA4P=0
HCA3L=1
HC200=1
HC300=1
SCA4P=0
SCA5L=1
SCMIN=1
SBA4L=1
SBA4P=1
SBA3L=1
SB200=1
SB300=1

Share this post


Link to post
Share on other sites



Something like this:

Global $pb[13] = ["HC200", "HC300", "HCA3L", "HCA4L", "SB200", "SB200", "SB300", "SBA3L", "SBA4L", "SBA4P", "SCA4P", "SCA5L", "SCMIN"]

For $iIndex = 0 To 12
    GUICtrlSetData($chkPHOTOBOOKS[$iIndex], $pb[$iIndex])
    If IniRead($iniFile, $SECTION, $pb[$iIndex], "0") = "1" Then
    GUICtrlSetState($chkPHOTOBOOKS[$iIndex], $GUI_CHECKED)
    Else
    GUICtrlSetState($chkPHOTOBOOKS[$iIndex], $GUI_UNCHECKED)
    EndIf
Next
If $CATEGORY = "PHOTOBOOKS" Then
    For $iIndex = 0 To 12
    GUICtrlSetState($chkPHOTOBOOKS[$iIndex], $GUI_ENABLE)
    Next
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Dude... you are genius! :) Thank you sooooo much!

This is gonna help me a lot with my AutoIt projects. ;)

Have a good one ;)

F

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