Jump to content

Just Curious....


Recommended Posts

Hey All -

I was just wonder if theres an easier way of writing this section below. I've thought of using a Select..case but I need it to read through all of them not just select one. This only has 2 records in it right now but when im done it will have anywhere around 50 records....(thats too much code the way im doing it for something simple....)

Thank you for any help in advance

$sRead = IniRead ($sFile , "01 Dly Prd Rpt1", "HasRun" , 0 )
$sRead2 = IniRead ($sFile , "06 Prod Rpts", "HasRun" , 0 )
If $sRead = 1 Then
    GUICtrlSetState ($DlyRpts1 , $GUI_DISABLE)
EndIf
If $sRead2 = 1 Then
    GUICtrlSetState ($ProdRpts , $GUI_DISABLE)
EndIf

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Hey All -

I was just wonder if theres an easier way of writing this section below. I've thought of using a Select..case but I need it to read through all of them not just select one. This only has 2 records in it right now but when im done it will have anywhere around 50 records....(thats too much code the way im doing it for something simple....)

Thank you for any help in advance

$sRead = IniRead ($sFile , "01 Dly Prd Rpt1", "HasRun" , 0 )
$sRead2 = IniRead ($sFile , "06 Prod Rpts", "HasRun" , 0 )
If $sRead = 1 Then
    GUICtrlSetState ($DlyRpts1 , $GUI_DISABLE)
EndIf
If $sRead2 = 1 Then
    GUICtrlSetState ($ProdRpts , $GUI_DISABLE)
EndIf
You want your list of ini sections and the associated control IDs in a 2D array (or two 1D arrays), and then just loop through it to handle each case:
Global $avReports[2][2] = [["01 Dly Prd Rpt1", $DlyRpts1], _
        ["06 Prod Rpts", $ProdRpts]]

For $n = 0 To UBound($avReports) - 1
    $sRead = IniRead($sFile , $avReports[$n][0], "HasRun" , 0 )
    If $sRead = 1 Then GUICtrlSetState($avReports[$n][1], $GUI_DISABLE)
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You want your list of ini sections and the associated control IDs in a 2D array (or two 1D arrays), and then just loop through it to handle each case:

Global $avReports[2][2] = [["01 Dly Prd Rpt1", $DlyRpts1], _
        ["06 Prod Rpts", $ProdRpts]]

For $n = 0 To UBound($avReports) - 1
    $sRead = IniRead($sFile , $avReports[$n][0], "HasRun" , 0 )
    If $sRead = 1 Then GUICtrlSetState($avReports[$n][1], $GUI_DISABLE)
Next

:)

Thanks for your reply....

bear with me for a min if u dont mind, I don't understand arrays (ill admit im a complete noob at coding, i got thrown into the position at work because i knew the basics)

If i understand it correctly for each different record i would just have to add to it the original array like:

Global $avReports[3][3] = [["01 Dly Prd Rpt1", $DlyRpts1], _
        ["06 Prod Rpts", $ProdRpts]["Example1" , $Example1]]

For $n = 0 To UBound($avReports) - 1
    $sRead = IniRead($sFile , $avReports[$n][0], "HasRun" , 0 )
    If $sRead = 1 Then GUICtrlSetState($avReports[$n][1], $GUI_DISABLE)
Next

and for each new record just incriment the size of the array? and this doesn't have limits on how big the array is?

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Thanks for your reply....

bear with me for a min if u dont mind, I don't understand arrays (ill admit im a complete noob at coding, i got thrown into the position at work because i knew the basics)

If i understand it correctly for each different record i would just have to add to it the original array like:

Global $avReports[3][3] = [["01 Dly Prd Rpt1", $DlyRpts1], _
        ["06 Prod Rpts", $ProdRpts]["Example1" , $Example1]]

For $n = 0 To UBound($avReports) - 1
    $sRead = IniRead($sFile , $avReports[$n][0], "HasRun" , 0 )
    If $sRead = 1 Then GUICtrlSetState($avReports[$n][1], $GUI_DISABLE)
Next

and for each new record just incriment the size of the array? and this doesn't have limits on how big the array is?

Close.

Think of a 1D array as a numbered list. The only thing even slightly strange about it is that the elements are numbered from zero. So a 1D array with three elements would be addressed as $avArray[0], $avArray[1], $avArray[2]. The count is 3 but the last element is 2 because they are numbered from zero.

A 2D is like a spreadsheet. By convention, most people treat the first index as the rows and and the second as columns. Both indexes are still zero based. In your code, you are adding more rows but not more columns, so the array size would be $avReports[3][2]. Also, each 'row' of data is enclosed in square brackets and there should be a comma between each set.

So your example should be:

Global $avReports[3][2] = [["01 Dly Prd Rpt1", $DlyRpts1], _
        ["06 Prod Rpts", $ProdRpts],["Example1" , $Example1]]

Another example with five 'rows' including some formatting to make it easier to read:

Global $avReports[5][2] = [["01 Dly Prd Rpt1", $DlyRpts1], _
        ["06 Prod Rpts", $ProdRpts], _
        ["Example3", $Example3], _
        ["Example4", $Example4], _
        ["Example5", $Example5]]

The AutoIt Wiki has a page with good info on arrays, but you have to search for it, as the pages links don't really get you there: AutoIt Arrays

There is a learning curve involved, but array are very much worth figuring out. They make many things much easier to do.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you! I'm atually starting to understand arrays now, and i think ive got a lot of work of cleaning up my other scripts to make them easier to read and shorter.

Again - Thank you for all your help.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
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
 Share

  • Recently Browsing   0 members

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