Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [HELP] VB.net with batch commandy  (Read 3976 times)

0 Members and 1 Guest are viewing this topic.

sailo

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 7
    [HELP] VB.net with batch commandy
    « 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..

    Salmon Trout

    • Guest
    Re: [HELP] VB.net with batch commandy
    « Reply #1 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")

    sailo

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Windows 7
      Re: [HELP] VB.net with batch command
      « Reply #2 on: July 27, 2013, 10:34:25 PM »
      it works.... thank you so much Salmon Trout