Computer Hope
Software => Computer programming => Topic started 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..
-
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")
-
it works.... thank you so much Salmon Trout