Solved

Write to text file with input box to change a specific value

Posted on 2014-07-23
12
839 Views
Last Modified: 2014-07-23
I need to create a batch file and write to it. The wording remain the same but the /Value=? needs to change by provding the person a input box to enter the value? The file needs to be created in c:\Program Files (x86)\test\Worktest\Test.bat



I need to write the following with the ability to change the Value=apple to what ever the user inputs.  I want to be able to change that by using the inputbox.

echo off
"C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe" /Value=apple /playnow

Please advice
0
Comment
Question by:Vicki05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 84

Expert Comment

by:oBdA
ID: 40214412
Plain batch:
@echo off
setlocal
set Value=
set /p Value=Please enter the value (or an empty value to exit): 
if "%Value%"=="" goto :eof
"%ProgramFiles(x86)%\Common Files\test\Interface\Control\hello.jack.test.exe" /Value=apple /playnow

Open in new window

0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40214434
Try this:
echo off
set /p strValue= Please enter a value.
"C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe" /Value=%strValue% /playnow 

Open in new window

0
 
LVL 84

Expert Comment

by:oBdA
ID: 40214451
Small correction for the plain batch (forgot to replace apple, too much copy and paste):
@echo off
setlocal
set Value=
set /p Value=Please enter the value (or an empty value to exit): 
if "%Value%"=="" goto :eof
"%ProgramFiles(x86)%\Common Files\test\Interface\Control\hello.jack.test.exe" /Value="%Value%"/playnow

Open in new window

And for the fun of it, a batch with an input box:
@echo off
setlocal
set Title=Title
set Prompt=Prompt
set TempFile=%Temp%\Input.vbs
>"%TempFile%" echo Wscript.Echo InputBox("%Prompt%", "%Title%")
set Value=
for /f "delims=" %%a in ('cscript.exe //nologo "%Temp%\Input.vbs"') do (set Value=%%a)
del "%TempFile%"
if "%Value%"=="" goto :eof
"%ProgramFiles(x86)%\Common Files\test\Interface\Control\hello.jack.test.exe" /Value="%Value%"/playnow

Open in new window

0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:Vicki05
ID: 40214517
Sorry, I meant to say that I need a vbscript to write a text or a batch file that will let me change the value.
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40214548
Please repost the exact text you need written to a text/batch file, put the variable text only in bold.
0
 

Author Comment

by:Vicki05
ID: 40214595
Here is the vbscript that I am working on. I need to be able to change the value using a inputbox instead of msgbox

strComputer = "."
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")


Const ForReading = 1
Const ForWriting = 2
intAnswer = _
    Msgbox("This utility gives the ability to Update the Value." & vbCrLf & "Do you want to turn Change Value?", _
        vbYesNo, "Run Program")

If intAnswer = vbYes Then

            If objFSO.FileExists("C:\Program Files (x86)\test\Worktest\Test.bat") Then
                  objFSO.DeleteFile "C:\Program Files (x86)\test\Worktest\Test.bat"
            End If


            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set outFile = objFSO.OpenTextFile("C:\Program Files (x86)\test\Worktest\Test.bat", 8, True)
      For i = 1 to 7

Next

outfile.WriteLine "@echo off"
outfile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe""/Value=apple /playnow"


      msgbox"Done"
End If
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40214620
Perhaps if I understood your goal I could advise you of a better way...

strValue = InputBox("Enter desired value.")
outfile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe""/Value=" & strValue & " /playnow"

Open in new window

0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 40214652
Do you mean something like this (what's the empty for loop for?):
strOutputFile = "C:\Program Files (x86)\test\Worktest\Test.bat"
strOutputFile = "C:\Temp\Test.bat"
strTitle = "Run Program"
strPrompt =	"This utility gives the ability to update the value." & vbCrLf & _
			"Enter the value you want to set, or an empty value to skip:" & vbCrLf

Const ForReading = 1
Const ForWriting = 2
' Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strValue = InputBox(strPrompt, strTitle)
If strValue <> "" Then
	If objFSO.FileExists(strOutputFile) Then
		objFSO.DeleteFile strOutputFile
	End If
	Set outFile = objFSO.OpenTextFile(strOutputFile, 8, True)
	For i = 1 to 7
	Next
	outfile.WriteLine "@echo off"
	outfile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe"" /Value=""" & strValue & """ /playnow"
	MsgBox "Value changed to '" & strValue & "'."
End If

Open in new window

0
 

Author Comment

by:Vicki05
ID: 40214660
Hi Macro,

I get an error on line2 character 1. Object required "outfile"
0
 

Author Closing Comment

by:Vicki05
ID: 40214681
Thanks for the solution. It worked.
0
 
LVL 84

Expert Comment

by:oBdA
ID: 40214793
Just noted that for the sake of completeness, there should be an "outFile.Close" after line 21. And for the fun of it, here's a version that fixes this and displays the current value in the input box:
strOutputFile = "C:\Program Files (x86)\test\Worktest\Test.bat"
strTitle = "Run Program"
strPrompt =	"This utility gives the ability to update the value." & vbCrLf & _
			"Enter the value you want to set, or an empty value to skip." & vbCrLf

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
' Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(strOutputFile) Then
	strSearch = "/Value="
	Set outFile = objFSO.OpenTextFile(strOutputFile, ForReading)
	Do While Not outFile.AtEndOfStream
		strLine = outFile.ReadLine()
		intPosValue = InStr(strLine, strSearch)
		If intPosValue > 0 Then
			intPosPlayNow = InStr(strLine, "/playnow")
			If (intPosPlayNow > 0) And (intPosPlayNow > intPosValue) Then
				strOldValue = Mid(strLine, intPosValue + Len(strSearch) + 1, intPosPlayNow - intPosValue - Len(strSearch) - 3)
			End If
		End If
	Loop
	strPrompt = strPrompt & vbCrLf & "The current value is '" & strOldValue & "'."
	outFile.Close
End If

strValue = InputBox(strPrompt, strTitle, strOldValue)
If (strValue <> "") And (strValue <> strOldValue) Then
	Set outFile = objFSO.OpenTextFile(strOutputFile, ForWriting, True)
	For i = 1 to 7
	Next
	outFile.WriteLine "@echo off"
	outFile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe"" /Value=""" & strValue & """ /playnow"
	outFile.Close
	MsgBox "Value changed to '" & strValue & "'."
End If

Open in new window

0
 

Author Comment

by:Vicki05
ID: 40214829
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question