1.

Solve : [HELP] VB.net with batch commandy?

Answer»

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



Discussion

No Comment Found