shell command with variable

User avatar
sal21
PlatinumLounger
Posts: 4396
Joined: 26 Apr 2010, 17:36

shell command with variable

Post by sal21 »

i use this line:

shell("@for /f "delims=:" %%i in ('findstr /nc:"AAAA" "C:\MYDIR\file1.txt"') do >"c:\testdir\result.txt" echo %%i & exit /b")

Iis possible, instead to use a fixed param :"AAAA" and "C:\MYDIR\file1.txt", substituite with a var?

similar:
...
dim myvar as string, myvar2 as string

myvar1="AAAA"
myvar2="C:\MYDIR\file1.txt"

shell("@for /f "delims=:" %%i in ('findstr /nc:"myvar1" "myvar2"') do >"c:\testdir\result.txt" echo %%i & exit /b")
...

i'm working with VB6.

User avatar
HansV
Administrator
Posts: 78768
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: shell command with variable

Post by HansV »

Like this?

Code: Select all

    Dim myvar As String, myvar2 As String

    myvar1 = "AAAA"
    myvar2 = "C:\MYDIR\file1.txt"
    Shell "@for /f ""delims=:"" %%i in ('findstr /nc:""" & myvar1 & """ """ & _
        myvar2 & """') do >""c:\testdir\result.txt"" echo %%i & exit /b"
Note the use of "" within the string.
Best wishes,
Hans