Solved

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

Posted on 2011-09-19
5
524 Views
Last Modified: 2012-06-27
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
Comment
Question by:webdott
[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
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36566705
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
 

Author Comment

by:webdott
ID: 36568488
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
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36570873
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
 

Author Closing Comment

by:webdott
ID: 36594164
thanks
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36594175
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

761 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