Jump to content
Sign in to follow this  
rehnmark

Move variables to antother function

Recommended Posts

rehnmark

Hi there!

I would really need some help, hope you can help me :D

This is my code:

antaldatorer()

func antaldatorer()
$wsid = InputBox("Ominstallation - PeDeploy", "Ange datornamn för de tre datorer som ska installeras om, ex: W65401010; W65401011; W65401012 ", "W6540", " M")
if @error  Then Exit


$ws1 = StringMid($wsid, 1, 9)
$ws2 = StringMid($wsid, 12, 9)
$ws3 = StringMid($wsid, 23, 9)
$null = StringMid($wsid, 230, 9)


if $ws2 = $NULL and $ws3 = $NULL then ominstallation1()
if $ws2 <> $NULL and $ws3 = $NULL then ominstallation2()
if $ws2 <> $NULL and $ws3 <> $NULL then ominstallation3()

EndFunc

My question is, how do i get the variables (and its values) $ws1, $ws2 and $ws3 to the functions ominstallation1(), ominstallation2() and ominstallation3()?

Thanx for your help!

Share this post


Link to post
Share on other sites
pinkfoyd

make an array and call your function with it in return element

ie :

Dim $array[4]


$table = antaldatorer()

put all you variable in the array

and put this a the end of your function : return($array)

Edited by pinkfoyd

Share this post


Link to post
Share on other sites
SmOke_N

Put them in a Global scope, that way each function can use them... Example

Global $ws1, $ws2, $ws3
antaldatorer()

func antaldatorer()
$wsid = InputBox("Ominstallation - PeDeploy", "Ange datornamn för de tre datorer som ska installeras om, ex: W65401010; W65401011; W65401012 ", "W6540", " M")
if @error  Then Exit


$ws1 = StringMid($wsid, 1, 9)
$ws2 = StringMid($wsid, 12, 9)
$ws3 = StringMid($wsid, 23, 9)
$null = StringMid($wsid, 230, 9)


if $ws2 = $NULL and $ws3 = $NULL then ominstallation1()
if $ws2 <> $NULL and $ws3 = $NULL then ominstallation2()
if $ws2 <> $NULL and $ws3 <> $NULL then ominstallation3()

EndFuncoÝ÷ Øêî±êZ­©µêìjëh×6antaldatorer()

func antaldatorer()
$wsid = InputBox("Ominstallation - PeDeploy", "Ange datornamn för de tre datorer som ska installeras om, ex: W65401010; W65401011; W65401012 ", "W6540", " M")
if @error  Then Exit


$ws1 = StringMid($wsid, 1, 9)
$ws2 = StringMid($wsid, 12, 9)
$ws3 = StringMid($wsid, 23, 9)
$null = StringMid($wsid, 230, 9)


if $ws2 = $NULL and $ws3 = $NULL then ominstallation1($ws1, $ws2, $ws3)
if $ws2 <> $NULL and $ws3 = $NULL then ominstallation2($ws1, $ws2, $ws3)
if $ws2 <> $NULL and $ws3 <> $NULL then ominstallation3($ws1, $ws2, $ws3)

EndFunc

Func ominstallation1($ws1, $ws2, $ws3)
    ;something
EndFunc
;etc...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
rehnmark

Put them in a Global scope, that way each function can use them... Example

Global $ws1, $ws2, $ws3
antaldatorer()

func antaldatorer()
$wsid = InputBox("Ominstallation - PeDeploy", "Ange datornamn för de tre datorer som ska installeras om, ex: W65401010; W65401011; W65401012 ", "W6540", " M")
if @error  Then Exit
$ws1 = StringMid($wsid, 1, 9)
$ws2 = StringMid($wsid, 12, 9)
$ws3 = StringMid($wsid, 23, 9)
$null = StringMid($wsid, 230, 9)
if $ws2 = $NULL and $ws3 = $NULL then ominstallation1()
if $ws2 <> $NULL and $ws3 = $NULL then ominstallation2()
if $ws2 <> $NULL and $ws3 <> $NULL then ominstallation3()

EndFuncoÝ÷ Øêî±êZ­©µêìjëh×6antaldatorer()

func antaldatorer()
$wsid = InputBox("Ominstallation - PeDeploy", "Ange datornamn för de tre datorer som ska installeras om, ex: W65401010; W65401011; W65401012 ", "W6540", " M")
if @error  Then Exit
$ws1 = StringMid($wsid, 1, 9)
$ws2 = StringMid($wsid, 12, 9)
$ws3 = StringMid($wsid, 23, 9)
$null = StringMid($wsid, 230, 9)
if $ws2 = $NULL and $ws3 = $NULL then ominstallation1($ws1, $ws2, $ws3)
if $ws2 <> $NULL and $ws3 = $NULL then ominstallation2($ws1, $ws2, $ws3)
if $ws2 <> $NULL and $ws3 <> $NULL then ominstallation3($ws1, $ws2, $ws3)

EndFunc

Func ominstallation1($ws1, $ws2, $ws3)
    ;something
EndFunc
;etc...
Thank you! Global worked like a sharm :D

Share this post


Link to post
Share on other sites
Uten

Using Globals, when they can be awoided, is a bad habit that will bite your tail at some point down the road. So , you would be better of passing arguments.

antaldatorer()

func antaldatorer()
$wsid = InputBox("Ominstallation - PeDeploy", "Ange datornamn för de tre datorer som ska installeras om, ex: W65401010; W65401011; W65401012 ", "W6540", " M")
if @error  Then Exit


$ws1 = StringMid($wsid, 1, 9)
$ws2 = StringMid($wsid, 12, 9)
$ws3 = StringMid($wsid, 23, 9)
$null = StringMid($wsid, 230, 9)


if $ws2 = $NULL and $ws3 = $NULL then ominstallation1($ws1, $ws2)
if $ws2 <> $NULL and $ws3 = $NULL then ominstallation2($ws1, $ws2, $ws3)
if $ws2 <> $NULL and $ws3 <> $NULL then ominstallation3($ws1, $ws2, $ws3)

EndFunc
;
; ByRef: Pass by reference. Changes done in ominstallation1 will affect calling function
; $ws3 = "W6540": Default value is W6540, You don't have to use this argument possition 
; in the calling function if you accept the default value.
Func ominstallation1(ByRef $ws1, $ws2, $ws3 = "W6540")
   ;Do job
EndFunction
Func ominstallation1(ByRef $ws1, $ws2, $ws3 = "W6540")
   ;Do job
EndFunction
Func ominstallation1(ByRef $ws1, $ws2, $ws3 = "W6540")
   ;Do job
EndFunction

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  

×