2

All;

I have a bit of code I've written that opens a design blueprint when I scan a bar code. It works well enough, but I'd like to open a new instance of the design software (Solidworks) and have the print display in the new instance. Right now, no matter how many Solidworks instances I have open, the print will only open in the first instance started.

The line commented out below is the line that works, just not in the right instance. The line below that is what I'd expect to work, but it returns a 'file not found' even though the path to solidworks and the print path are both correct.

Any explanation as to why this isn't working would be much appreciated as I'm obviously very new at this...and have no idea what I'm doing.

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
    Try
        Dim barcode As String = tb_barcode.Text
        Dim filename As String = tb_barcode.Text
        'Add File Extension to end of path
        Dim ext As String = ".SLDDRW"
        'Split job number from detail number in barcode textbox
        barcode = Split(tb_barcode.Text, ".")(0)
        filename = Split(tb_barcode.Text, ".")(1)
        '- This works, just in primary instance
        'System.Diagnostics.Process.Start("G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext)
        '- This does not work
        System.Diagnostics.Process.Start("'C:\Program files\Solidworks Corp\Solidwork\SLDWORKS.exe' 'G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")

    Catch
        MessageBox.Show("File Not Found")
    End Try
End Sub
DisplayName
  • 13,283
  • 2
  • 11
  • 19

2 Answers2

1

Sorry for naive approach but shouldn't there be a comma in Process.Start between 2 arguments?

Start(String, String) 

Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component. docs

Nick
  • 83
  • 7
  • No need to be sorry! I've already tried the comma and that didn't seem to work either: System.Diagnostics.Process.Start("C:\Program files\Solidworks Corp\Solidwork\SLDWORKS.exe", "G:\Fixtures\ """ & barcode & "\Details\" & barcode & " DET " & filename & ext) – mystic_muffin Nov 26 '18 at 19:21
  • you need both comma and quotation marks inside the string for space characters : https://askubuntu.com/questions/530578/how-to-write-the-path-of-a-folder-with-space-in-its-name Or else it tries to open 'C:\Program' which doesn't exist. – Vlad Nov 26 '18 at 21:09
1

Why don't you use the Application.ExecutablePath.That returns the Application's path with its full name. Then your code should be

   System.Diagnostics.Process.Start(Application.Executablepath, "G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")

Also make sure that the second string argument is a valid path.

preciousbetine
  • 2,959
  • 3
  • 13
  • 29