Hi,

Can you help me how to call two lines from VB Script and give the same in .bat file as input.

Here is my VB SCript code..
---------------------------------------------------------------------------------------

Set oShell = CreateObject( "WScript.Shell" )
Set ObjFSO= CreateObject("Scripting.FileSystemObject")
Str1="Version=3.1016.0.0"
Str2="Version=3.1017.0.0"

Getxml1 = "D:\BuildShare\CMS_Maternity\lorenzo tranche2\maternity\webclient\wizard\lorappmaternityslui.web\moduleconfig\modulecatalog.xml"
Set objFile = objFSO.OpenTextFile(Getxml1, 1)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText,Str1,Str2)
Set objFile = objFSO.OpenTextFile(Getxml1, 2)
objFile.WriteLine strNewText
objFile.Close

Getxml2 = "D:\BuildShare\CMS_Maternity\lorenzo tranche2\maternity\webclient\wizard\lorappmaternityslui.web\navigation\navigation.xml"
Set objFile = objFSO.OpenTextFile(Getxml2, 1)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText,Str1,Str2)
Set objFile = objFSO.OpenTextFile(Getxml2, 2)
objFile.WriteLine strNewText
objFile.Close

----------------------------------------------------------------------------------

From the above code, this is used for incrementing a version. So, how can I give inputs which is BOLD in text to bat file (The same inputs should change in Vb Script)?
--------------------------------------------------------------------------------------

Thanks in advance!

I don't follow. Can you please restate the problem without referring to vbScript or bat? As this is the vb.NET forum I presume you are looking for a vb.NET solution. It appears from your description, however, that you want to write a bat file ("how can I give inputs which is BOLD in text to bat file"). Also, I don't see any "BOLD in text". If English is not your first language than that might be the cause of the confusion. I would be happy to offer suggestions once I understand the problem.

I don't follow. Can you please restate the problem without referring to vbScript or bat? As this is the vb.NET forum I presume you are looking for a vb.NET solution. It appears from your description, however, that you want to write a bat file ("how can I give inputs which is BOLD in text to bat file"). Also, I don't see any "BOLD in text". If English is not your first language than that might be the cause of the confusion. I would be happy to offer suggestions once I understand the problem.

Hi,

Thanks for your reply!

Actually I wrote an VB Script. it works fine without calling this vbs from bat file. So what my question is, we need to change two inputs i.e Str1 & Str2 and then we need to trigger .vbs file.Instead of changing the two inputs every-time by opening .vbs file, can I give two inputs in bat file which should change in .vbs file? If it is possible, can you guide me how to solve this problem..

Hope it clears!

If rdLoan.HasRows = True Then
Do While rdLoan.Read

Dim ls As New ListViewItem(rdLoan.Item("Borrowname").ToString())
ls.SubItems.Add(rdLoan("accno"))
ls.SubItems.Add(rdLoan("Title"))
ls.SubItems.Add(rdLoan("author"))
ls.SubItems.Add(rdLoan("issue_date"))
ListView1.Items.Add(ls)

Loop
this code retrieve only one record
pls help

So the question (if I understand it) is to pass str1 and str2 as parameters to the vbScript so that you don't have to hard code the version numbers. In that case you can do

set arg = Wscript.Arguments

if arg.Count <> 2 then
	wscript.Echo "UpdateVersion oldversion newversion"
	wscript.Quit 1
end if

str1 = arg(0)
str2 = arg(1)

If you know where in the xml file the version number is stored it might be more appropriate to have a script that takes just one parameter to identify which field of the version number you want to increment. For example

IncrementVersionNumber 3

would take "Version=3.1016.0.0" and change it to "Version=3.1016.1.0". It should be a simple change and if you want to post a sample xml file I would be happy to slap it together.

This version should do what I suggested. Save it as IncrementVersion.vbs

In the regular expression, "\d+" matches one or more consecutive digits and "\."
matches a period.

set fso  = CreateObject("Scripting.FileSystemObject")
set args = Wscript.Arguments

if args.Count <> 2 then
	wscript.Echo "IncrementVersion file field"
	wscript.Echo ""
	wscript.Echo "  Increment a field (1-4) of a version number string in a text file."
	wscript.Echo "  Version string is formatted as ""Version=#.#.#.#"" where # can be"
	wscript.Echo "  any sequence of digits."
	wscript.Quit 1
end if

file  = args(0)
field = args(1)

'you should verify here that
'1) the file exists
'2) field is a digit from 1-4

'The following regular expression will match a string of the form
'"Version=#.#.#.#" where # is any sequence of digits
'The search is case-sensitive and will find only the first
'occurrence of the string (because Global=False)

set rex = New RegExp
rex.Pattern = "Version=\d+\.\d+\.\d+\.\d+"
rex.Global  = False

'read the entire text file

text = fso.OpenTextFile(file).ReadAll

'search and replace

for each match in rex.Execute(text)
	'wscript.echo Match.FirstIndex,match.Value
	newver = UpdateVersion(match.Value,field)
	text = Replace(text,match.Value,newver)
next

'rewrite the xml file

set tso = fso.OpenTextFile(file,2)
tso.Write text
tso.Close()

'this function takes a version string in the form "Version=3.103.1.8"
'and increments the given field (one-relative)

Function UpdateVersion (oldver, field)

	dim tokens
	dim fields
	
	tokens = Split(oldver,"=")
	fields = Split(tokens(1),".")
	fields(field-1) = cint(fields(field-1)) + 1
	
	UpdateVersion = tokens(0) & "=" & Join(fields,".")
	
End Function

Some feedback would be nice. Is the above what you were looking for?

Some feedback would be nice. Is the above what you were looking for?

Hi Jim,

The one which you sent me before works. Finally I came up with idea in solving the above problem. Thank you for spening some time for replying valuable thoughts.

Appreciate with your help!

Fer sher. Glad to help. Us retirees like to feel semi-useful from time to time ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.