VB.Net Argument

I am trying to use a variable in place of a command line argument, but the application (Visual Cut) will not run. There are no Visual Studio error messages. Please help me resolve the error.
Code that causes error:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu2 As String
        Argu2 = """Export_File:C:\test_3\People_1.pdf"""

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)""" + Argu2
        retval = Shell(ls_temp)
    End Sub

Open in new window

There are no errors when this code runs:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""
        retval = Shell(ls_temp)
    End Sub

Open in new window

Mark01Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Try Changing these two lines of code
        Argu2 = """Export_File:C:\test_3\People_1.pdf"""

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)""" + Argu2

Open in new window

To this
Argu2 = "Export_File:""C:\test_3\People_1.pdf"""

ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " &
    "-e ""C:\test_3\People_1.rpt"" Export_Format:""Adobe Acrobat (pdf)"" " + Argu2

Open in new window

Also you are doing nothing with the results with the last line in that sub.
0
Mark01Author Commented:
@Fernando Soto: The following code does not work (app will not run):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu2 As String
        Argu2 = "Export_File:""C:\test_3\People_1.pdf"""

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
        "-e ""C:\test_3\People_1.rpt"" Export_Format:""Adobe Acrobat (pdf)"" " + Argu2
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
Fernando SotoRetiredCommented:
Hi Mark01;

Try it this way to see if it works. If it does not then execute it from the command line window to see if it is working correctly, when it does post the complete command here exactly as you entered it.
Argu2 = "Export_File:""C:\test_3\People_1.pdf"""

ls_temp = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe " 
    "-e ""C:\test_3\People_1.rpt"" Export_Format:""Adobe Acrobat (pdf)"" " + Argu2

Open in new window

0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Fernando SotoRetiredCommented:
If there is an actual space in the file name as shown in your code
"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe "

Open in new window

then what I just posted will not work. Please use command line tool and post back the command you typed in.
0
Mark01Author Commented:
Yes, there is a space in the file name. I don't understand what you mean by using the command line tool. There are no errors when this code runs:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
Fernando SotoRetiredCommented:
The Command Line / Command Line Tool / Command Prompt Window is all the same, See image below. Execute your program in that window.Command Line Tool
0
Mark01Author Commented:
I am using a Visual Studio 2008 project to test the code. I don't have any experience running a project from a command line. Are you referring to the following:
https://docs.microsoft.com/en-us/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line
0
Fernando SotoRetiredCommented:
I am not asking you to run the project from the command line I am asking you to run the program C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe from the command line with all of its arguments just like you would run any bat file or exe from the command line to make sure that the arguments you are using with that program are being excepted correctly.
0
Mark01Author Commented:
I have already run the command line with all of its arguments in a batch file. All of the arguments are being accepted correctly. I have also run the following command line and  arguments are they are accepted correctly:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
Fernando SotoRetiredCommented:
I would like to verify that the command you are constructing in your project is correct and I can not do that without seeing it the way it was typed in to the command line window.
0
Mark01Author Commented:
I have already verified it. Previous EE question:
https://www.experts-exchange.com/questions/29080283/Batch-to-VB-App.html
0
Fernando SotoRetiredCommented:
So in your other post the line worked and the same input in this question does not work. Try the other post statement in this question and see if it starts working again.
0
Mark01Author Commented:
This is a different question. The other question did not use a variable.
0
Fernando SotoRetiredCommented:
So have you tried without a variable in this project as you did in the other project? If so post that code here.
0
Mark01Author Commented:
No. The other project did not use an argument variable. I posted the code in this question.
0
Fernando SotoRetiredCommented:
I know it did not use a variable. I would like you to do it in the new project without a variable to see if it works and if it works post that code here.
0
Mark01Author Commented:
I have already verified that the command line with all of its arguments are being accepted correctly. I have posted that code in this thread more than once.
0
Fernando SotoRetiredCommented:
Very good, I do not know how to proceed from here to help you. Hopefully someone else will view the question and help you out.

Good luck.
0
ktaczalaCommented:
I've never seen an executable contain a space!
visual CUT.exe is probably trying to execute CUT.exe
0
Mark01Author Commented:
@ktaczala There are no errors when this code runs (this code works):
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
ktaczalaCommented:
try displaying ls_temp in a text box and verify the correct formatting
both from the code that works and the code that fails.
0
ktaczalaCommented:
I assume then that
this is the path: C:\Program Files (x86)\Visual CUT 11\Visual
and this is the executable: CUT.exe
0
Mark01Author Commented:
The path is: C:\Program Files (x86)\Visual CUT 11
No, the executable is: Visual CUT.exe
0
Mark01Author Commented:
Here are the results of some testing:
Vers 1 (Only opens report in Visual Cut):
Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = """" & Argu1 & """" & Argu2 & """" & Argu3 & """" & Argu4

Open in new window

Vers 2 (only starts Visual Cut):
ls_temp = """" & Argu1 & """"

Open in new window

Vers 3 (Only opens report in Visual Cut):
ls_temp = """" & Argu1 & """" & Argu2 & """" & Argu3 & """" & Argu4 & """"

Open in new window

Vers 4 (Error: Exception. System.IO.FileNotFoundException was unhandled
  Message="File not found."):
ls_temp = "" & Argu1 & "" & Argu2 & "" & Argu3 & "" & Argu4 & ""

Open in new window

0
ktaczalaCommented:
I put your code in vb and displayed the results, obviously I don't have visual cut to actually run it.

here's how you ls_temp is coming out:
"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"C:\test_3\People_1.rpt"Export_Format:Adobe Acrobat (pdf)"Export_File:C:\test_3\People_1.pdf
"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"C:\test_3\People_1.rpt"Export_Format:Adobe Acrobat (pdf)"Export_File:C:\test_3\People_1.pdf"
C:\Program Files (x86)\Visual CUT 11\Visual CUT.exeC:\test_3\People_1.rptExport_Format:Adobe Acrobat (pdf)Export_File:C:\test_3\People_1.pdf

Notice the lack of spaces, that may be your issue.

** these are all one liners no crlf at the end of test_3, this comment box is wraping text automatically.
0
Mark01Author Commented:
@ktaczala: You are missing spaces. Here is a summary.

The following sub results in exporting the People_1.rpt report to PDF (it works; no errors):
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String

        ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""
        retval = Shell(ls_temp)
    End Sub

Open in new window

The following sub results in only starting Visual Cut (the People_1.rpt report is not exported):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = """" & Argu1 & """" & Argu2 & """" & Argu3 & """" & Argu4 & """"
        retval = Shell(ls_temp)
    End Sub

Open in new window

The following sub results in only starting Visual Cut (the People_1.rpt report is not exported):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = """" & Argu1 & """"
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
Mark01Author Commented:
I just noticed that Argu1 in  42537380 and 42537768 is missing the -e. The following sub results in an "System.IO.FileNotFoundException was unhandled. Message="File not found."" error.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe -e"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = """" & Argu1 & """"
        retval = Shell(ls_temp)

Open in new window

"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe -e" is not equal to """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e
0
ktaczalaCommented:
Here's the contents of ls_temp according to your code:
example 1:
ls_temp = """C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " &
"-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""
this one you said works, notice the space between the quotes.
"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe" -e "C:\test_3\People_1.rpt" "Export_Format:Adobe Acrobat (pdf)" "Export_File:C:\test_3\People_1.pdf"

example 2:
ls_temp4 = """" & Argu1 & """" & Argu2 & """" & Argu3 & """" & Argu4 & """"
this one you said fails, notice no space between the quotes.
"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe -e"C:\test_3\People_1.rpt"Export_Format:Adobe Acrobat (pdf)"Export_File:C:\test_3\People_1.pdf"
0
Mark01Author Commented:
There is space between the quotes. I think the error is caused by the following:
Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe -e"

Open in new window

not being equivalent to:
"""C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"" " & _
"-e

Open in new window

0
ktaczalaCommented:
See attachment
code.jpg
0
Mark01Author Commented:
@ktaczala: Thank you for going to the trouble of marking up an image of the code. As I look at the following sub in Visual Studio with the code from 42538687, I don't see any missing spaces. Here is the full sub:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe -e"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = """" & Argu1 & """"
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
ktaczalaCommented:
When you concatenate Argu1, Argu2, Argu3, and Argu4, that's when you see the missing spaces.
0
Mark01Author Commented:
I understand your point. I'm concentrating on 42538687 and 42539032. Do you see any missing spaces in the following: Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe -e"? If there is a missing space in 42539032, then I cannot find it.
0
Mark01Author Commented:
I'm making some progress. No errors for the following sub although Visual Cut will not run:
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = Argu1 + " -e"
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
Mark01Author Commented:
No VS errors, but report will not export. Full sub code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = Argu1 + " -e" & " """ & Argu2 & " """ & Argu3 & " """ & Argu4 & """"
        retval = Shell(ls_temp)

Open in new window

0
ktaczalaCommented:
Link to Visual Cut 11 Manual: Visual Cut Manual

Look at Page 63 also look at page 70
Looks like the -e should be outside the quotes
0
ktaczalaCommented:
C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe -e "C:\test_3\People_1.rpt "Export_Format:Adobe Acrobat (pdf) "Export_File:C:\test_3\People_1.pdf"

Missing quote before C: and after .exe and after .rpt and after (pdf)
0
Mark01Author Commented:
I'm stuck. I get End of statement expected and Name 'retval' is not declared errors.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval close membersAs String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = """" & Argu1 & """" + " -e" & " """ & Argu2 & """" " """ & Argu3 & " """ & Argu4 & """"
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
ktaczalaCommented:
Try this easier to read:
ls_temp = Chr(34) & Argu1 & Chr(34) & " -e " & Chr(34) & Argu2 & Chr(34) & " " & Chr(34) & Argu3 & Chr(34) & " " & Chr(34) & Argu4 & Chr(34)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark01Author Commented:
I get the same End of statement expected and Name 'retval' is not declared errors.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval close membersAs String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = Chr(34) & Argu1 & Chr(34) & " -e " & Chr(34) & Argu2 & Chr(34) & " " & Chr(34) & Argu3 & Chr(34) & " " & Chr(34) & Argu4 & Chr(34)
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
ktaczalaCommented:
Dim retval close membersAs String

is the issue
I assume it should be: Dim retval as string
0
Mark01Author Commented:
Yes, that was causing the errors. Visual Cut functions normally and exports the report. Your code does not contain any errors.
0
Mark01Author Commented:
Summary. Here is the solution.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim retval As String
        Dim ls_temp As String
        Dim Argu1 As String = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        Dim Argu2 As String = "C:\test_3\People_1.rpt"
        Dim Argu3 As String = "Export_Format:Adobe Acrobat (pdf)"
        Dim Argu4 As String
        Argu4 = "Export_File:C:\test_3\People_1.pdf"

        ls_temp = Chr(34) & Argu1 & Chr(34) & " -e " & Chr(34) & Argu2 & Chr(34) & " " & Chr(34) & Argu3 & Chr(34) & " " & Chr(34) & Argu4 & Chr(34)
        retval = Shell(ls_temp)
    End Sub

Open in new window

0
Mark01Author Commented:
Thank you, Fernando Soto and ktaczala.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.