Issue Converting VBA Print Macro to VB.Net (No error but won't print)

Hi gurus,

I have been creating internal macros for our company in VBA for a few years. I have recently begun exploring VB.Net and thought a good trial would be to convert one of the existing VBA macros to a VB.Net standalone format.

I created the form and added/modified all the code for the buttons to work with VB.Net. I did not get any errors, only an issue at line 257 saying the function would not return a value on all code paths (might be the problem but I don't see how). So running the macro brings up the form and the form controls all work. But when I use the "Print Currently Active Drawing" button, it will walk through the entire macro without any issues, but when it gets to the print command it acts like it did not see the command. Won't print, won't even act like it sent anything to the printer.

I know the code functions since it works in VBA, so I am hoping it is an issue of being unfamiliar with VB.Net and I overlooked turning something on or setting up a reference that was needed. I am hoping some of you can take a look at it and give me some feedback on how to get it to print (or just some VB.Net feedback on better ways to do things).

Finally, to get the default print folder to function, there is a text file I included in the zip file called "Printer Default Location.txt" that needs to go in a folder on C ("C:\\SolidWorks Files"). It's for saving text for the Form (going to try to learn how to save settings once I can get it to print).

I appreciate you taking time to look at this for me.

SolidworksApi macros
Answers 5
IK
IK 2017-08-24 Best Answer

please try this

JS
JS 2017-08-24

Hi Ivana,

The code you suggested resolved quite a few issues and definitely cleaned it up. That being said, it still will not print. I would say it is something network based except it does not even show it is a pending print. It acts like it does not know what the command is and just glosses over it.

Also, if the Oce TDS400 printer is selected it stops and shows this error message:

     "An unhandled exception of type 'System.AccessViolationException' occurred in Cloeren - Print Wizard.exe

     Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Any thoughts?

Thanks

IK
IK 2017-08-24

this line should not be moved to local scope: Dim ReadOnly Opt(9) As Object

JS
JS 2017-08-25

Sorry Ivana, still does not want to print and continues to throw the error.

JS
JS 2017-09-14

For anyone interested, after treading Harvey's waters for two weeks I finally got an oppurtunity to look at this macro again, and I finally figured it out with the help of a print macro published by AngelSix.

The issue was in the PrintOut2 command. The original page array variable I was using was listed as long and would not work so I switched it to a zero and the macro began printing:

        swModel.Extension.PrintOut2(0, NumberCopies, False, PriorPlot, "")

The PrintOut2 command requires an Integer variable there.

Hope this helps someone else, thanks.