I'm trying to simplify a Windows interface script that my colleague did in which he used a lot of if-loops which I think can be further shortened using for-loops.
Basically we have a couple sets of computers that ranged from 4 - 12 per set & we provide each admin an interface to revert their respective snapshots.
I'm looking to replace the number in each variable with the $i value from the for-loop.
I've tried using arrays & hashtables but based on what I've gathered, they're much more suitable in storing values & not formulas that included other variables.
if($ComputerNumber -eq 4) {
$checkBoxComputer1LocX = $leftMargin
$checkBoxComputer1LocY = [int]$labelSubHeaderLocY + [int]$buttonHeight + [int]$padding
$checkBoxComputer2LocX = $leftMargin
$checkBoxComputer2LocY = [int]$labelSubHeaderLocY + [int]$buttonHeight + [int]$padding + (1 * ([int]$checkBoxHeight + [int]$padding))
$checkBoxComputer3LocX = $leftMargin
$checkBoxComputer3LocY = [int]$labelSubHeaderLocY + [int]$buttonHeight + [int]$padding + (2 * ([int]$checkBoxHeight + [int]$padding))
$checkBoxComputer4LocX = $leftMargin
$checkBoxComputer4LocY = [int]$labelSubHeaderLocY + [int]$buttonHeight + [int]$padding + (3 * ([int]$checkBoxHeight + [int]$padding))
}
This is what I'm trying to achieve:
for($i=1; $i -le $ComputerNumber; i++) {
$checkBoxComputer$iLocX = $leftMargin
$checkBOxComputer$iLocY = [int]$labelSubHeaderLocY + [int]$buttonHeight + [int]$padding + (($i - 0) * ([int]$checkBoxHeight + [int]padding))
}