Combobox adding value to module HELP!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Combobox adding value to module HELP!

  1. #1
    Join Date
    Apr 2009
    Posts
    1

    Question Combobox adding value to module HELP!

    Hello everybody,

    I have been trying to work this out for some time now but without any luck, this is my final hope.

    I have a script in Visual Studio which adds a network printer to a computer, I used to use VBS but I need to be able to add a GUI to it. This is the script in the module.

    Module Module1
    Sub add_printer()
    Dim objNetwork, strUNCPrinter
    strUNCPrinter = "\\peel-black\PDM-PTR-028"
    objNetwork = CreateObject("WScript.Network")
    objNetwork.AddWindowsPrinterConnection(strUNCPrinter)
    End Sub
    End Module

    The bit which says "\\peel-black" is the server and "\PDM-PTR-028" is the printer.

    Is there a way to put all the names of the printers into a combobox and then when the value is selected on the combobox the value replaces the exsisting printer. PDM-PTR-028 would be a value in the combobox.

    I hope that somebody will be able to help me.

    Many Thanks In Advance

    Richard!

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Welcome to DevX

    You will need to add your own error trapping.
    Code:
    Imports System.Drawing.Printing
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
            Dim strInstalledPrinters As String
            
            For Each strInstalledPrinters In _
                PrinterSettings.InstalledPrinters
                ComboBox1.Items.Add(strInstalledPrinters)
            Next 
    
            ' Set the combo to the first printer in the list - optional
            ComboBox1.SelectedIndex = 0
    End Sub
    
    
    Public Sub add_printer(ByVal pstrPrinter As String)
    Dim objNetwork As ??????   'I do not know what you are doing here - in VB.NET 
                                         'this will generate an error.   You MUST 
                                         'stipulate a variable type
    Dim strUNCPrinter As String
    strUNCPrinter = "\\peel-black\" & pstrPrinter
    objNetwork = CreateObject("WScript.Network")
    objNetwork.AddWindowsPrinterConnection(strUNCPrinter)
    End Sub
    
    Private Sub btnAddPrinter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddPrinter.Click
    add_printer(ComboxBox1.Text)
    End Sub
    Last edited by Hack; 04-06-2009 at 01:10 PM.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 3
    Last Post: 09-27-2007, 07:27 AM
  2. Adding ComboBox to a bound DataGridView
    By camrontucker in forum .NET
    Replies: 2
    Last Post: 03-10-2007, 12:02 PM
  3. adding a module to a project
    By harish13 in forum VB Classic
    Replies: 1
    Last Post: 07-27-2006, 02:44 AM
  4. Adding on to a ComboBox list
    By miss_jess in forum VB Classic
    Replies: 12
    Last Post: 05-31-2005, 09:33 AM
  5. Adding item to combobox
    By Eray Sazan in forum Web
    Replies: 0
    Last Post: 03-22-2001, 07:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center