• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 547
  • Last Modified:

change text in .txt file with vbscript or .bat script with a radio button

i have a .txt file that has some true/false info in it.

i was wondering if there is a vbscript or .bat that allows a popup to change them on check of
the radio button.

example:
c:\client\client-jones.txt

click on script, opens popup with radio buttons as follows:
paid march [ ] true  [ ] false
paid april  [ ] true  [ ] false
paid may  [ ] true  [ ] false

the text file is like this:
 
clent=jones, jimmy
address=
city=
state=
zip=
phone=


paid invoices
march=true
april=true
may=false

Open in new window


it would only change the true/false after each month=?

thanks
0
webdott
Asked:
webdott
  • 3
  • 2
1 Solution
 
RobSampsonCommented:
Hi, with pure vbscript, you won't have the ability to use check boxes, but you could build a HTA that would read the file and display checkboxes for each option.

I can help with that, but I have a question first....is there anything else after the "paid invoices" section?  I would write the HTA to read the file up to the "paid invoices" line, then read the rest of the options until the end of the file, and display them....

Rob.
0
 
webdottAuthor Commented:
just all the months - examples:
january=true
february=false

etc. for each month thru to december.

thanks for your help!

what is a HTA? is it a script that is edited in notepad?
0
 
RobSampsonCommented:
Hi, first, create a VBS file called LaunchHTA.vbs (or whatever you want to call it), and put this code in it (by pasting it in to Notepad):
strHTA = "C:\Temp\Scripts\TestHTA2.hta"
Set objShell = CreateObject("WScript.Shell")
If WScript.Arguments.Count = 1 Then
	objShell.Run "mshta """ & strHTA & """ """ & WScript.Arguments.Item(0) & """", 1, False
Else
	objShell.Run "mshta """ & strHTA & """", 1, False
End If

Open in new window


In that VBS code, change "C:\Temp\Scripts\TestHTA2.hta" to the path that you save the following HTA code to.  Create a file called the same name as that HTA you just referenced, and paste the below code into that file with notepad:
<html>
<head>
<title>Test</title>
<HTA:APPLICATION 
	ID = "objHTA"
	APPLICATIONNAME="Test"
	BORDER="dialog"
	SCROLL="no"
	SINGLEINSTANCE="yes"
	WINDOWSTATE="normal"
	Maximizebutton="no"
	ContextMenu="no"
>
<html>
	<head>
		<script language="vbscript">
			Dim strOptions
			Sub Window_OnLoad
				intWidth = 800
				intHeight = 600
				Me.ResizeTo intWidth, intHeight
				Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
			    If Mid(document.location, 6, 3) = "///" Then
			    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
			    Else
			    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
			    End If
				strFileName = Trim(Replace(LCase(objHTA.CommandLine), """" & LCase(strHTAPath) & """", ""))
				If strFileName <> "" Then
					If Left(strFileName, 1) = """" Then strFileName = Mid(strFileName, 2)
					If Right(strFileName, 1) = """" Then strFileName = Left(strFileName, Len(strFileName) - 1)
					txt_filepath.Value = strFileName
					GetData
				End If
			End Sub
			
			Sub GetData
				span_info.InnerHTML = ""
				span_options.InnerHTML = ""
				strOptions = ""
				Set objFSO = CreateObject("Scripting.FileSystemObject")
				Const ForReading = 1
				strFileName = Trim(txt_filepath.Value)
				If strFileName <> "" Then
					If objFSO.FileExists(strFileName) = True Then
						Set objFile = objFSO.OpenTextFile(strFileName, ForReading, False)
						blnStartOfOptions = False
						strHTML = "<table width='50%'><tr><th width='50%' align='left'>Month</th><th>Paid</th></tr>"
						While Not objFile.AtEndOfStream
							strLine = Trim(objFile.ReadLine)
							If LCase(strLine) = LCase("paid invoices") Then blnStartOfOptions = True
							If blnStartOfOptions = True Then
								If InStr(strLine, "=") > 0 Then
									strMonth = Split(strLine, "=")(0)
									strPaid = Split(strLine, "=")(1)
									If strOptions = "" Then
										strOptions = strMonth
									Else
										strOptions = strOptions & "," & strMonth
									End If
									If LCase(strPaid) = "true" Then
										strChecked = " checked"
									Else
										strChecked = ""
									End If
									strHTML = strHTML & vbCrLf & "<tr><td>" & strMonth & "</td><td align='center'><input type='checkbox' id='chk_" & strMonth & "' name= 'chk_" & strMonth & "'" & strChecked & "></td></tr>"
								End If
							Else
								span_info.InnerHTML = span_info.InnerHTML & strLine & "<BR>"
							End If
						Wend
						objFile.Close
						span_options.InnerHTML = strHTML
					Else
						MsgBox "Unable to find file. Please enter a valid file path."
					End If
				Else
					MsgBox "Please enter a file path."
				End If
			End Sub
			
			Sub SaveData
				Set objFSO = CreateObject("Scripting.FileSystemObject")
				Set objFile = objFSO.CreateTextFile(txt_filepath.Value, True)
				objFile.Write Replace(span_info.InnerHTML, "<BR>", vbCrLf)
				objFile.WriteLine "paid invoices"
				For Each strMonth In Split(strOptions, ",")
					strPaid = LCase(Eval("chk_" & strMonth & ".checked"))
					objFile.WriteLine strMonth & "=" & strPaid
				Next
				objFile.Close
				MsgBox "Data has been saved."
			End Sub
		</script>
	</head>
	<body>
		<br>
		Please type in the path to the file you want to open, and click "Get Data"
		<br>
		<input type="text" name="txt_filepath" id="txt_filepath" size="60">
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="button" id="btn_getdata" name="btn_getdata" value="Get Data" onclick="GetData">
		<br>
		<br>
		<span id="span_info"></span>
		<br>
		<span id="span_options"></span>
		<br><br>
		<input type="button" id="btn_savedata" name="btn_savedata" value="Save Data" onclick="SaveData">
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="button" id="btn_exit" name="btn_exit" value="Exit" onclick="window.close">		
	</body>
</html>

Open in new window


Then, to run it, drag a text file onto the VBS file, using Windows Explorer.

Regards,

Rob.
0
 
webdottAuthor Commented:
thanks
0
 
RobSampsonCommented:
No problem. The HTML in the HTA I wrote is very basic (it was a quick and dirty build), and doesn't look very nice, but you can add whatever HTML code you like to spruce it up a bit.  It supports CSS as well if you want to use it.

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now