Alright. I'm attempting to complete a school assignment and cannot for the life of me figure this out. I'm trying to use powershell to pass values from one function to another making a "modular" type script. I can't seem to figure out how to move the values out of the scope of the function without using the $script:xxxxx. Is there another way to move the values in powershell as a regular argument parameter pass by reference?
Here's what I have:
function main
{
inputGrams($carbGrams, $fatGrams)
$carbGrams
$carbGrams
calcGrams
displayInfo
}
function inputGrams([ref]$carbGrams, [ref]$fatGrams)
{
$carbGrams = read-host "Enter the grams of carbs per day"
$fatGrams = read-host "Enter the grams of fat per day"
}
function calcGrams
{
$carbCal = $carbGrams * 4
$fatCal = $fatGrams * 9
}
function displayInfo
{
write-host "The total amount of carb calories is $carbCal"
write-host "The total amount of fat calories is $fatCal"
}
main
The two values right after the inputGrams function should change each time the script is run but they don't because of scope issues and passing the values. Anyone know how to properly pass those values back to the main function?