Solved

printersettings conversion to vb.net

Posted on 2004-04-30
6
745 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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