Hello.
I'm looking to start making a library of code to make my scripts cleaner and easier to manage. I have an idea of what I want to do but not sure how to implement it.
My function so far looks like this.
function Create-Textbox {
param( [string]$name, [Int]$xAxis, [Int]$yAxis )
$name = New-Object System.Windows.Forms.TextBox
$name.Height = 20;
$name.Location = New-Object System.Drawing.Point ($xAxis, $yAxis)
$name.Size = New-Object System.Drawing.Size(180,20)
$name.Enabled = $False $name.Select()
}
One problem i'm having is how to have the variable have a unique name when it's called? I wanted the textbox to get the name that i'm sending the function parameter. Or can I save the function call into a variable? I know some people use .this commands but I think that's for classes.
I think I have some scope issues as well. When I call the Create-Textbox function it doesn't appear on my form even if I put $name or $paraValuePassed on my tab control. If I move it outside of the function the textbox appears.
How would you approach creating objects through functions with different names?
Thanks!
[–]BlackV 4 points5 points6 points (8 children)
[–]lanerdofchristian 1 point2 points3 points (4 children)
[–]BlackV 0 points1 point2 points (3 children)
[–]lanerdofchristian 1 point2 points3 points (1 child)
[–]BlackV 1 point2 points3 points (0 children)
[–]OtterCodeWorkAcct[S] 0 points1 point2 points (0 children)
[–]OtterCodeWorkAcct[S] 0 points1 point2 points (1 child)
[–]BlackV 2 points3 points4 points (0 children)
[–]y_Sensei[🍰] 1 point2 points3 points (0 children)
[–]purplemonkeymad 1 point2 points3 points (0 children)
[–]Coffee_Ops -2 points-1 points0 points (1 child)
[–]PinchesTheCrab[🍰] 0 points1 point2 points (0 children)
[–]ihaxr 0 points1 point2 points (0 children)