Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some code that can open a file with either Notepad or Wordpad. I am attempting to be able to open the same file with a text editor of the users choice. I tried Microsoft Word as a test but cannot get it to work. Here is my code (oh: the variable "OtherPuzzleEditorPath" is defined as Public in a module):
VB
Private Sub viewBtn_Click(sender As Object, e As EventArgs) Handles viewBtn.Click
        Dim MySelectedPath As String = Nothing
        Dim MySelectedExt As String = Nothing
        Dim EditorPath As String = Nothing
        
        Select Case True

            Case RadioButton1.Checked
                MySelectedPath = PuzzlePath
                MySelectedExt = ".wsp"

            Case RadioButton2.Checked
                MySelectedPath = SolutionsPath
                MySelectedExt = ".wss"

        End Select

        EditorPath = MySelectedPath & ListBox3.SelectedItem.ToString & MySelectedExt

        Select Case True

            Case OpenWithNotepad
                Process.Start("Notepad.exe", EditorPath)

            Case OpenWithWordpad
                Process.Start("Wordpad.exe", Chr(34) & EditorPath & Chr(34)) 'DONT CHANGE THIS LINE!

            Case OpenWithOther
                Process.Start(OtherPuzzleEditorPath & Space(1) & EditorPath)

        End Select

        ListBox3.ClearSelected()
        deleteBtn.Enabled = False
        viewBtn.Enabled = False

    End Sub<pre lang="vb">


What I have tried:

Different variations of defining both strings: ie(Chr(34) & [path] & Chr(34)), changing to the directory the executable is in FIRST, then running it with the path of the file.
Posted
Updated 1-Oct-18 15:57pm

1 solution

You changed the way you passed parameters when you added your "OtherPuzzleEditor". You do not provide a space and then the parameter.

You are supposed to pass the executable to launch and its parameters as separate arguments to the Start call. Change the code from this:
VB.NET
Process.Start(OtherPuzzleEditorPath & Space(1) & EditorPath)

To this:
VB.NET
Process.Start(OtherPuzzleEditorPath, EditorPath)
 
Share this answer
 
Comments
[no name] 2-Oct-18 8:07am    
Thank you very much! I had to add quotes around the second parameter because of the spaces in the string. Works GREAT! Thanks again!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900