Solved

printersettings conversion to vb.net

Posted on 2004-04-30
6
719 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with LINQ and XML 10 35
Exit the loop 4 42
VB 2005 how to get a new line of data each time I try to write to a file. 10 24
start a process from a service 3 21
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now