Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Select Case Problem

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Select Case Problem
  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 >>
 Select Case Problem - 9/4/2007 8:59:40 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
hi,

i'm currently writing a login script, which maps network printer based on active directory groups.

the scripts looks like that:


      


the Problem ist the Select Case function.

If i use Case "Finance", it runs.

if i use Case "Finance_Dept", it doesn't run.

The Problem is the _


How can i get the Select Case running with the underscore??

thanks for help!
 
 
Post #: 1
 
 RE: Select Case Problem - 9/4/2007 9:32:18 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
hi

that was not the error, its another one :D

code looks like that:

Make Select Case
run Script
Conintue with new Select Case.


1. select case's map network drives.

then, all network printers should be deleted with the following code:
For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2
If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True
End If

After that, i start again with Select Case

But it the delete network printer code runs in an error.

(in reply to repa)
 
 
Post #: 2
 
 RE: Select Case Problem - 9/4/2007 10:15:55 PM   
  Parabellum


Posts: 222
Score: 0
Joined: 11/12/2006
From: UK
Status: offline
not sure exactly what your asking... can you post the example code and the error your getting.

(in reply to repa)
 
 
Post #: 3
 
 RE: Select Case Problem - 9/4/2007 10:27:37 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
hi

this is the code:


      

The Problem is the Section "Delete eNetwork Printer"

(in reply to Parabellum)
 
 
Post #: 4
 
 RE: Select Case Problem - 9/4/2007 11:00:22 PM   
  Parabellum


Posts: 222
Score: 0
Joined: 11/12/2006
From: UK
Status: offline
not sure why that's not working.... i dont have a network printer i can tets with at the moment....
you could try using WMI though..??

quote:

 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
   ("Select * from Win32_Printer Where Network = TRUE")
For Each objPrinter in colInstalledPrinters
   objPrinter.Delete_
Next

(in reply to repa)
 
 
Post #: 5
 
 RE: Select Case Problem - 9/4/2007 11:06:44 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
If I am understanding you correctly, the issue is when the code loops again, your printer connection that you just made is deleted.  if that is the case, you could just add a variable that you set the first go round.


      

If you do not want to do the above, you could remove all your deletes from the For-Next and have it run before the for-Next

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to repa)
 
 
Post #: 6
 
 RE: Select Case Problem - 9/5/2007 12:13:49 AM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
Hi,

the problem si the following (i'm new in vb :) )

the Network drives are mapped. The printers are deleted, then a error message appers "command Next expected". If i remove the Deleted Network Printers code, it runs ?

the problem is the code with network printers deletion.

(in reply to mbouchard)
 
 
Post #: 7
 
 RE: Select Case Problem - 9/5/2007 12:17:55 AM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
ok, now i understood your code.

'There appears to be a Next missing.

this is my problem :) how can i solve this?

(in reply to repa)
 
 
Post #: 8
 
 RE: Select Case Problem - 9/5/2007 2:26:42 PM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
quick examples:

If statement Then
  Code
Else
  Code
End if
--------------------------
Do Until...
    Code
Loop
--------------------------
For each item...
    Code
Next


so for this line that mbouchard caught
'There appears to be a Next missing.
replace this whole line with Next to complete the For loop

(in reply to repa)
 
 
Post #: 9
 
 RE: Select Case Problem - 9/5/2007 5:04:17 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
hi

i've added a next.

after that, an error appears, that on the last line, a next is expected. if i add a next on the last line, the same error appers again :(

(in reply to sheepz)
 
 
Post #: 10
 
 RE: Select Case Problem - 9/5/2007 11:24:18 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
any ideas ?

(in reply to repa)
 
 
Post #: 11
 
 RE: Select Case Problem - 9/6/2007 12:52:41 AM   
  Country73


Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Make sure you indent your code, makes it easier to read and find out where you have incomplete code blocks.


printerMapped = False
'Start your For here
For each strGroup in objUser.memberOf
'   All your stuff here
           
   If printerMapped = False Then
       '********************************************************************************
       'Delete Network Printer
       '********************************************************************************
       For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2
           If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
               objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True
           End If   
           ''There appears to be a Next missing.
           '********************************************************************************
           'Map Network Printer
           '********************************************************************************     

           Select Case strGroupName

               Case "PRT_server_prt22"
                   objNetwork.AddwindowsPrinterConnection "\\server06\asdf_prt101"
                       printerMapped = True   
           End Select
       NEXT      'this is the missing NEXT
   End If
Next

(in reply to repa)
 
 
Post #: 12
 
 RE: Select Case Problem - 9/6/2007 1:15:25 AM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
okay, thanks for help

the code looks now like that:


      


Now i have a strange effect.

if the printer exist and i run the script, the printer is removed, but not recreated?

if the printer is removed and i run the script, the printer is created (that is correct)


but why do the script noch recreate the printer after deletion ? i mean, the del comes before the create or?

(in reply to Country73)
 
 
Post #: 13
 
 RE: Select Case Problem - 9/6/2007 1:18:01 PM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
the problem your encountering:
quote:


if the printer exist and i run the script, the printer is removed, but not recreated?
if the printer is removed and i run the script, the printer is created (that is correct)
but why do the script noch recreate the printer after deletion ? i mean, the del comes before the create or?

is of course due to the code:

For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2
If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True
End If

'----- Map printers -----
Select Case strGroupName
       Case "PRT2"
                 objNetwork.AddwindowsPrinterConnection Printserver1 & "\prt2"
End select
Next    '<---- Problem here

so lets take a look theres two main statements/arguments being used a FOR LOOP and a SELECT Case.  the FOR LOOP is to delete all printers and your SELECT Case is to map printers two seperate things.  your SELECT Case is in the FOR LOOP which is only for deleting printers.  so first lets delete the printers ONLY:

For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2
If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
    objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True
End If
Next
 
Now AFTER deleting all the printers lets use are SELECT Case and map the correct printers to strGroupName:

   '--- Map printers ---
   Select Case strGroupName
       Case "PRT_server_prt22"
             objNetwork.AddwindowsPrinterConnection "\\server06\asdf_prt101"
  End Select


it should look like this:

       

< Message edited by sheepz -- 9/6/2007 1:23:05 PM >

(in reply to repa)
 
 
Post #: 14
 
 RE: Select Case Problem - 9/6/2007 7:57:26 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
thanks for helping me.

now the error calls: "Next not expected"

     '--- Map printers ---
     Select Case strGroupName
         Case "PRT_server_prt22"
               objNetwork.AddwindowsPrinterConnection "\\server06\asdf_prt101"
     End Select
Next

its the last NEXT

(in reply to sheepz)
 
 
Post #: 15
 
 RE: Select Case Problem - 9/6/2007 8:17:05 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
i inserted some message boxes, to find out, whats going on.

Code now looks like:

      


Following setup on the machine.

- 1 Existing Printer

Start Script:

- PrinterDEL
- PrinterADD
- Finish
- PrinterDEL
- Finish
- PrinterDEL
- Finish
-PrinterDEL
- Finish
- PrinterDEL
- Finish
- Finish


looooooooooooopiiiiiiiiiiiiiing :D

(in reply to repa)
 
 
Post #: 16
 
 RE: Select Case Problem - 9/6/2007 10:39:30 PM   
  repa

 

Posts: 19
Score: 0
Joined: 9/4/2007
Status: offline
hi and sorry for asking again.

but this script makes me creazy.... it loops arraound, maps printer, delete it, maps it, delete it, same with network drives.

where should i add a next, where not?


      

(in reply to repa)
 
 
Post #: 17
 
 RE: Select Case Problem - 9/7/2007 1:30:45 AM   
  CaffeineAddiction

 

Posts: 144
Score: 0
Joined: 2/9/2005
From:
Status: offline
http://msdn2.microsoft.com/en-us/library/tywtbxd0.aspx


      

_____________________________

Thanks for Answering my Questions ... I hope my Answer to your questions help!

(in reply to repa)
 
 
Post #: 18
 
 RE: Select Case Problem - 9/7/2007 2:44:47 AM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
quote:


hi and sorry for asking again.
but this script makes me creazy.... it loops arraound, maps printer, delete it, maps it, delete it, same with network drives.


are we having issues with the Delete/Map printers?  OR  Delete/Map drives?  i thought we only had issues with the printer section?
here is your code with ONLY the printer section, the drive mapping has been deleted to isolate the problem.  one of the very first things i leared from the admins here was "take away the On Error Resume Next"  if you have that ON, the code will not generate errors, so lets go ahead and take that out and see what errors you get with this reduce version of your code:

      

< Message edited by sheepz -- 9/7/2007 3:13:06 AM >

(in reply to CaffeineAddiction)
 
 
Post #: 19
 
 RE: Select