Solved

printersettings conversion to vb.net

Posted on 2004-04-30
6
729 Views
Last Modified: 2008-08-13
I found this code which is what I need for my program.  I tried to convert it myself, but I get an error on
fi.SetValue(PD.PrinterSettings, outname)
It says object reference not set to an instance of an object.

Here is the original code:
System.Type type = typeof(PrinterSettings);
this.PrinterSettings.PrintToFile = true;
FieldInfo outputPort = type.GetField("outputPort",
BindingFlags.NonPublic | BindingFlags.Instance);
outputPort.SetValue(this.PrinterSettings,"FILE:");

Here is what I converted it to:
Dim PD As New Printing.PrintDocument
       
Dim fi As System.Reflection.FieldInfo
Dim outname As New Object

PD.PrinterSettings.PrintToFile = True
fi = PD.PrinterSettings.GetType().GetField("outputport", Reflection.BindingFlags.Instance)

outname = "C:\jimc.ps"
fi.SetValue(PD.PrinterSettings, outname)  "I get the error on this line"

PD.Print()

Can someone help me with this conversion?
0
Comment
Question by:brettawv
6 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10966262
Possibly this happens because first GetField argument in C# code is "outputPort", and in VB code "outputport". Last parameter in VB code is missing NonPublic flag.
0
 

Author Comment

by:brettawv
ID: 10967757
I'm not sure how to add that to the VB code.  VB doesn't like the | sign.  Any ideas on how to rewrite that line in VB?
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 10967887
use or ... it will become a binary or ...

BindingFlags.NonPublic  or Reflection.BindingFlags.Instance

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:brettawv
ID: 10969810
I added and I still get the same error. Seems like I'm missing creating an instance of one of the objects, but I'm not sure what.  I could be totally wrong to.  If you have any other ideas, I would appreciate the help.
0
 

Author Comment

by:brettawv
ID: 11009185
I ended up using itextsharp to convert images directly to pdf which was the whole reason for asking this question.  I was trying to send my picture to a postscript file and then convert it to pdf using ghostscript.

Thanks for trying to help.  I'll try to work this out later, but I'm set for now.

I'm giving the points to gregoryyoung for at least helping me through part of the problem.
0
 

Expert Comment

by:fesit
ID: 23036971
I appreciate the awarding of points for someone trying to help, but it is also misleading - it leads people to believe that the answer being rewarded solves the problem...which it does not.

I tried this and couldn't figure out why it was not working for me until I scrolled down and saw that the problem was not actually answered....
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question