Newbie to .net with a problem

G

Gareth Howe

I could do this is VB6 but can't figure out .net yet.

I need to be able to access a data file that has a list of printers, with
their corrisponding share name and computer that they are sat on (Which I
have already generated as a CSV file).

In VB6 I would use the data control to load this in to an array but can't
find the corrisponding function in .net

What I would then do would be to have an array of buttons that would be
created with the names of the printers.

When a button was clicked, it would then execute the following

\\<servername>\netlogon\con2prt /cd \\<printerserver>\<printershare>


I'm not asking anyone to generate me the solution to this, but a few good
pointers would be really appreciated.

Many thanks,
Gareth
 
S

SStory

Gareth,

File operations can be performed on a text (CSV) file as follows:

'read and process CSV file one line at a time
Public Sub ReadFromCSV(ByVal strCSVFilePath As String)
Dim strmInfile As New System.IO.StreamReader(strCSVFilePath)
dim strLine as string
dim strElements() as string

Me.Cursor.Current = Cursors.WaitCursor

'read line
strLine = strmInfile.ReadLine

While Not strLine Is Nothing
Try
'split comma separated line into elements of string array
strElements=strLine.Split(",")

'you write this function/sub
DoSomethingWithThem(strElements)

'get next line
strLine = strmInfile.ReadLine
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "ERROR Reading
file")
Me.Cursor.Current = Cursors.Default
exit Sub
Finally
strmInfile.close
End Try
End While

strmInfile.Close()
Me.Cursor.Current = Cursors.Default
End Sub

IN DOTNET THERE ARE NO CONTROL ARRAYS but one Click event handler can be
told to handle all button click events,

or using AddHandler you can accomplish the same thing when you create the
buttons.

Inside this handler--either way--you can decide based on the button tag or
name or whatever, what to do--maybe store this printer info in the tag of
the button.

MSDN IN VB.NET 2003 SAYS:
Visual Basic Concepts


Printers Collection Changes in Visual Basic .NET
See Also
Printing Changes in Visual Basic .NET | Windows Forms Print Support |
Introduction to the Windows Forms PrintDialog Component | PrinterSettings
Class

In Visual Basic 6.0, the Printers collection was used to return information
about available printers on a system. In Visual Basic .NET, the PrintDialog
control returns information about available printers; properties for a given
printer can be retrieved using the PrinterSettings class.

The Printers collection had two properties: Item and Count. These were
standard collection properties; the PrintDialog control has no equivalent
properties.

See Also
Hope this helps you some,

Shane Story
 
H

Herfried K. Wagner [MVP]

* "Gareth Howe said:
I need to be able to access a data file that has a list of printers, with
their corrisponding share name and computer that they are sat on (Which I
have already generated as a CSV file).

In VB6 I would use the data control to load this in to an array but can't
find the corrisponding function in .net

What I would then do would be to have an array of buttons that would be
created with the names of the printers.

When a button was clicked, it would then execute the following

\\<servername>\netlogon\con2prt /cd \\<printerserver>\<printershare>

Is that a command shell command? Have a look at this project, maybe it
will help you to solve your problem:

<http://www.mvps.org/dotnet/dotnet/samples/miscsamples/downloads/RedirectConsole.zip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top