Solved

printersettings conversion to vb.net

Posted on 2004-04-30
6
700 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
Comment Utility
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
Comment Utility
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
Comment Utility
use or ... it will become a binary or ...

BindingFlags.NonPublic  or Reflection.BindingFlags.Instance

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:brettawv
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

10 Experts available now in Live!

Get 1:1 Help Now