[Solved] [VB.net] CopyCount error

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
AquaTerra
Posts: 5
Joined: Sat Nov 17, 2012 6:39 pm

[Solved] [VB.net] CopyCount error

Post by AquaTerra »

Hello,
Sorry if I am posting this in wrong forum.
I am writing vb.net program that open .ott file, replace some text and then print it on selected printer. Problem is that "CopyCount" argument is not working (when I want to print multiple copies). When I debug my program i get this: "com.sun.star.lang.IllegalArgumentException:"

I would really appreciate if someone could help me with this. I know that I didn't tell you lot of details but this exception is all I got.

Thank you in advance!
OpenOffice 3.3 on Windows 7
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: [VB.net] CopyCount error

Post by B Marcelly »

Hi,
Nobody can help you without a look at your code.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
AquaTerra
Posts: 5
Joined: Sat Nov 17, 2012 6:39 pm

Re: [VB.net] CopyCount error

Post by AquaTerra »

Code: Select all

--------------there are code before this part, but it is not important for this problem so I didn't include it for better readability 
               oSM = CreateObject("com.sun.star.ServiceManager")
              oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
                oDoC = oDesk.loadComponentFromURL("file:///C:\potvrda.ott", "_blank", 0, New unoidl.com.sun.star.beans.PropertyValue(0) {})
                oRD = oDoC.createReplaceDescriptor
                oRD.searchRegularExpression = True
                oRD.setSearchString("<OPU>")
                oRD.setReplaceString(OPU_broj.Text)
                oDoC.replaceall(oRD)
              
                Dim args As System.Array
                Dim objDummy As Object = New Object
                args = System.Array.CreateInstance(objDummy.GetType, 0)
                objDummy = Nothing 

                Dim oArgs(1) As Object
                Dim dArgs(2) As Object

                If printerOmot.Length > 2 Then
                    oArgs(0) = MakePropertyValue(oSM, "Name", printerOmot)
                Else
                    oArgs(0) = MakePropertyValue(oSM, "Name", printerDefault)
                End If

                oDoC.setPrinter(oArgs)
                dArgs(0) = MakePropertyValue(oSM, "CopyCount", 2)
                dArgs(1) = MakePropertyValue(oSM, "Wait", True)
                oDoC.print(dArgs)
                oDoC.Close(True)

if I don't include this line

Code: Select all

 dArgs(0) = MakePropertyValue(oSM, "CopyCount", 2)
everything works OK, but if I include it then i get exception error as described in my first post
OpenOffice 3.3 on Windows 7
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: [VB.net] CopyCount error

Post by Charlie Young »

AquaTerra wrote: if I don't include this line

Code: Select all

 dArgs(0) = MakePropertyValue(oSM, "CopyCount", 2)
everything works OK, but if I include it then i get exception error as described in my first post
Just a hunch. The 2 is defaulting to 32 bits, and CopyCount should be 16. Try

Code: Select all

 dArgs(0) = MakePropertyValue(oSM, "CopyCount", CShort(2))
Apache OpenOffice 4.1.1
Windows XP
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: [VB.net] CopyCount error

Post by B Marcelly »

Maybe no influence on your problem, but I see these errors :

Your URL address is incorrect. It should be :
file:///C:/potvrda.ott
This was a simple case... Much more complex if you have national characters or spaces in the path.

The declaration of your arrays should indicate the maximum value of the index, see documentation of VB.NET.

Code: Select all

Dim oArgs(0) As Object
Dim dArgs(1) As Object
And at which instruction does the exception occur ?
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
AquaTerra
Posts: 5
Joined: Sat Nov 17, 2012 6:39 pm

Re: [VB.net] CopyCount error

Post by AquaTerra »

Charlie Young wrote:
Just a hunch. The 2 is defaulting to 32 bits, and CopyCount should be 16. Try

Code: Select all

 dArgs(0) = MakePropertyValue(oSM, "CopyCount", CShort(2))
Thank you, it seems that this fixed my problem. Will test it more later, but for now I don't receive error any more :super:

B Marcelly wrote:Maybe no influence on your problem, but I see these errors :

Your URL address is incorrect. It should be :
file:///C:/potvrda.ott
This was a simple case... Much more complex if you have national characters or spaces in the path.

The declaration of your arrays should indicate the maximum value of the index, see documentation of VB.NET.

Code: Select all

Dim oArgs(0) As Object
Dim dArgs(1) As Object
And at which instruction does the exception occur ?
Thank you, fixed that :super:
OpenOffice 3.3 on Windows 7
Post Reply