Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Sub Within A Sub

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,31855
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Sub Within A Sub
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Sub Within A Sub - 3/4/2006 2:07:04 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi guys.

I have this script that i am trying to get working.

Basically it first checks to see what AD site you are in , Then it checks to see what Make and Model machine you have which in turn will then run a set of commands , but i am having some issues with the script and i am sure its because i have a sub within a sub and i am not sure how fix it.

Any help would as always be fantastic



      




 
 
Post #: 1
 
 RE: Sub Within A Sub - 3/4/2006 3:03:17 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
you cant have a sub within a sub, if you want to do something like that its better to use a class instead

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to cjwallace)
 
 
Post #: 2
 
 RE: Sub Within A Sub - 3/5/2006 2:21:27 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Ahhhhhhhhhhhhhhhhhhh

Ok. Well from what i am trying to do , do you have any code or examples that i could look at.

What iam tring to do is a 3 step process.

First Check what AD site the Machine is in

Second then Check what type of Machine you have

Third depending on what machine you have will run run some code.

Any ideas \ suggestions on the best way to achive this?

Many thanks to anyone who can help

(in reply to kirrilian)
 
 
Post #: 3
 
 RE: Sub Within A Sub - 3/5/2006 9:34:24 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I don't know that I would bother with a class for this. Just move the DC7600c sub so that it is not in the London sub. More importantly however, I think your logic needs to be looked at. You are calling every one of your location subs then checking within the sub to see if the location is correct or not. Instead, I would use a Select-Case statement to only call the location sub that really needs to be executed.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cjwallace)
 
 
Post #: 4
 
 RE: Sub Within A Sub - 3/5/2006 1:34:33 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
I kind of agree with EBGreen, I would pull the DC7600c Sub out of the London sub but I would look at the possibility of converting the Subs into Functions and taking the return from each previous Function and using it as logical input for the subsequent Function.
It really all depends on what you are doing.  Can you post the rest of the code so we can try and come up with something? Also it only sounds like you have two logical determining factors going on here, not three.  An action(s) based on physical location and an action(s) based on machine type (which may or may not differ depending on location).

Would any of the machine specific configuration settings differ on lets say a "DC7600c" from one location to the next or would only the action under the location part differ?


Not knowing the answers to the previous questions...

      


Ok, you know this stuff already so I am not going to speculate any further. 


Cybex




_____________________________

Common sense is not so common.

(in reply to cjwallace)
 
 
Post #: 5
 
 RE: Sub Within A Sub - 3/5/2006 8:29:45 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi guys.

all the code i have is in the above post.

Each machine will run different code depending on where it is.

For example , if the machine is to be deployed in London it will copy London .ini files and reg Keys and say its in Milan it will copy Milan .ini files and reg Keys.

Thanks for your help on this one mate

(in reply to Cybex)
 
 
Post #: 6
 
 RE: Sub Within A Sub - 3/6/2006 1:30:16 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Ok, so here's the thing. The whole purpose of the Call instruction is to discard anything that is returned by a function. So if you are calling a function using the call instruction, then there is no reason for it to be a function in the first place. Having said that, I agree that you probably want to make a GetLocation and GetMachine function. You should however be using the values that they return so you should call them thusly:

strLocation = GetLocation()
strMachine = GetMachine()

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cjwallace)
 
 
Post #: 7
 
 RE: Sub Within A Sub - 3/6/2006 12:15:35 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
Your right, I missed that lastnight when I posted.


Cybex

_____________________________

Common sense is not so common.

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: Sub Within A Sub - 3/6/2006 12:17:12 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
So CJWallace, Did you get what you needed or are you still having issues?


Cybex

_____________________________

Common sense is not so common.

(in reply to cjwallace)
 
 
Post #: 9
 
 RE: Sub Within A Sub - 3/6/2006 10:39:23 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi mate. Sorry i have only just had a chance to pick this up. Had major DNS \ AD issues yesterday

Was not a nice day i can tell you.


Anyway yes i am still having a few issues trying to get my head around the code that was posted.


Where is it getting the information London from?

Where is it getting the wmi information from?

Am i just missing something?

Am i just going round the bend tee hee

Thanks for your help


(in reply to Cybex)
 
 
Post #: 10
 
 RE: Sub Within A Sub - 3/7/2006 6:33:56 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
In the example that Cybex posted, you would have to create the functions to get that information.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cjwallace)
 
 
Post #: 11
 
 RE: Sub Within A Sub - 3/7/2006 8:40:33 AM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
Correct, what I posted was more pusdo code than anything.  Just an idea...

I will try and throw something together tonight if I can get a free moment.


Cybex

_____________________________

Common sense is not so common.

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: Sub Within A Sub - 3/7/2006 8:57:45 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Thanks Cybex

God i love this site and everyone who helps out.

(in reply to Cybex)
 
 
Post #: 13
 
 RE: Sub Within A Sub - 3/7/2006 12:19:18 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
I am at home right now and no way to test this.  Can you run these when you get a chance and tell me what they return on one of your systems.  I want to make sure we have the right pieces for the logic work correctly.


      

Cybex

_____________________________

Common sense is not so common.

(in reply to cjwallace)
 
 
Post #: 14
 
 RE: Sub Within A Sub - 3/7/2006 8:28:30 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi Cybex..

Just to let you know that your code is telling me what AD Site i am in and Also the make and model of my machine.

I guess the next step is to get it to run code based on them two factors?

Thanks for all your help so far mate

< Message edited by cjwallace -- 3/8/2006 6:42:00 PM >

(in reply to Cybex)
 
 
Post #: 15
 
 RE: Sub Within A Sub - 3/8/2006 6:43:36 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi Cybex.

I was just wondering if you have had a chance to look at the next part of this script \ issue.

I have been playing around but i just keep coming back to the way i had my script last time.


Thanks very much for your help on this mate

(in reply to cjwallace)
 
 
Post #: 16
 
 RE: Sub Within A Sub - 3/9/2006 1:19:17 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I think this may be a good time for a quick sitrep. Could you post the code that you are currently running, what it is not doing that you want it to do, and any errors?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cjwallace)
 
 
Post #: 17
 
 RE: Sub Within A Sub - 3/20/2006 10:31:08 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi guys.

Sorry its taken me so long to get back on this. been so so busy.

Just starting to pick my scripting up again. had some major AD issues this week.

Anyway the code that cybex posted above work in that it tells me what AD site i am attached to but also the model of my machine which is great.

I now need to work out a way for running code based on them to values

eg if in London and you have machine type 1 then run this

if in Milan and have machine type 2 then run this

etc etc

Any ideas?

(in reply to ebgreen)
 
 
Post #: 18
 
 RE: Sub Within A Sub - 3/20/2006 11:43:48 PM   
  ginolard


Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
Check out the wonders of Select/Case True for this.  Let's assume we have a variable called varCity and another called varMachine, our code would look something like this

Select Case True
   Case varCity="London" And varMachine="1"
       Do stuff
   Case varCity="Milan" And varMachine="2"
       Do more stuff
   Case Else
       Do even more stuff
End Select

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to cjwallace)
 
 
Post #: 19
 
 RE: Sub Within A Sub - 3/21/2006 12:11:22 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello mate.

Ok i have put this together but i am sure this is wrong


      

(in reply to ginolard)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Sub Within A Sub Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts