Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2011, 08:54 AM
Registered User
 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Expected: 'then'

I am not sure what is happening. the code seems write and error states that it expects 'then' and it is already there @ line 29

Code:
Option Explicit 
 
On Error Resume Next 
 
Dim objNetwork, objWMIService, objPrinter 
Dim colInstalledPrinters 
Dim strPrinterServer, strPrinterShare, strComputerName 
Dim Return, LocalDefault, PrinterIsInstalled 
 

 
strPrinterServer = "\\printserver" 
strPrinterShare = "PRINTQUEUE" 
 
 
PrinterIsInstalled = False 
    
strComputerName = "."    ' This Computer 
 
Set objWMIService = GetObject( _ 
    "winmgmts:" & "{impersonationLevel=impersonate}!\\" _ 
    & strComputerName & "\root\cimv2") 
 
Set colInstalledPrinters =  objWMIService.ExecQuery _ 
    ("Select * from Win32_Printer") 
 
For Each objPrinter in colInstalledPrinters 

    If objPrinter.Default = "True" Then

    If objPrinter.ServerName = Null And_ 
     objPrinter.Name <> "Microsoft Office Document Image Writer" Then 
        LocalDefault = True 
    Else 
        LocalDefault = False 
    End If 
    End If 
 

    If objPrinter.ServerName = strPrinterServer And _ 
        objPrinter.ShareName = strPrinterShare Then 
    PrinterIsInstalled = True 
    End If
 
Next 
 
If Not PrinterIsInstalled Then 
    Set objNetwork = CreateObject("WScript.Network")  
    objNetwork.AddWindowsPrinterConnection strPrinterServer & "\" & strPrinterShare 
    If err.Number <> 0 Then 
        WScript.Echo "Could not map " & strPrinterServer & "\" _ 
    & strPrinterShare & " [" & err.Number & "]"  
        Err.Clear 
    Else 
        If Not LocalDefault Then 
            objNetwork.SetDefaultPrinter strPrinterServer & "\" & strPrinterShare 
        End If 
    End If 
Else 
End If 

Set objWMIService = Nothing 
Set objNetwork = Nothing 
 
WScript.Quit
 
Old March 18th, 2011, 09:26 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

there should be a space between and and _
change
Code:
 If objPrinter.ServerName = Null And _
To
Code:
 If objPrinter.ServerName = Null And _ 
     objPrinter.Name <> "Microsoft Office Document Image Writer" Then 
        LocalDefault = True 
    Else 
        LocalDefault = False 
    End If
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
 
Old March 18th, 2011, 09:38 AM
Registered User
 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Cool Just a Thanks

you are the best...

Thanks!


...something so simple





Similar Threads
Thread Thread Starter Forum Replies Last Post
expected Then Adam H-W Classic ASP Basics 6 April 17th, 2008 05:41 AM
expected ';' RoniR Javascript 3 February 1st, 2007 05:28 AM
Object Expected!! Apocolypse2005 Javascript 0 July 3rd, 2006 12:23 PM
Expected 'Then' Adam H-W Classic ASP Basics 5 July 26th, 2004 02:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.