Computer Hope

Software => Computer programming => Topic started by: sailo on July 27, 2013, 12:23:21 PM

Title: [HELP] VB.net with batch commandy
Post by: sailo on July 27, 2013, 12:23:21 PM
Here is my VB.Net code :

Dim NameOfFile As String = ""

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                Dim fnPeices() As String = OpenFileDialog1.FileName.Split("\")
                NameOfFile = fnPeices(fnPeices.Length - 1)
                MsgBox(NameOfFile)     'Here it display the file name correctly

                Shell("cmd.exe /c" & "echo NameOfFile & pause")     ' HERE, IT WILL EXECUTE BATCH COMMAND (echo NameOfFile & pause)

            Catch ex As Exception
                MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
End If


When it execute shell program, Instead of echoing/displaying the file name it just display the word "NameOfFile", how can i display the actual filename?
Please help and thanks in advance..
Title: Re: [HELP] VB.net with batch commandy
Post by: Salmon Trout on July 27, 2013, 01:56:53 PM
Since you want to pass to the Shell command a string containing the value held by the variable NameOfFile, and not the variable's name, you will have to do something like this:

Shell("cmd.exe /c" & "echo " & NameOfFile  & "& pause")
Title: Re: [HELP] VB.net with batch command
Post by: sailo on July 27, 2013, 10:34:25 PM
it works.... thank you so much Salmon Trout