Greetings Vbscript Guru's,
I am a complete Novice so bare with with me.
This is my project I am working on.
I need to place the value entered(for e.g 1.1.1.1) in the inputbox into
a file where it is going to replace a variable called "ipaddress".
When the value is pasted there a new file will be created.
I am having trouble to use the popup box entered value I call it
"input" in my scenario.

See code below.
Thanks in advance for anyone who can help me out here.

AQUILA


-------------begin----------

Const ForReading = 1
Const ForWriting = 2
Dim Input


Set objFSO = CreateObject("Scripting.FileSystemObject")
Input = InputBox("Enter your IP address")
MsgBox ("You entered: " & Input)
Set objFile = objFSO.OpenTextFile("C:\scripts\test.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
strLine = Replace(strLine, "ipaddress", & Input)
strNewText = strNewText & strLine & vbCrLF
Loop

objFile.Close

Set objFile = objFSO.CreateTextFile("C:\scripts\test1.txt", ForWriting)
objFile.WriteLine strNewText

objFile.Close
--------------------------end------------

Re: Inputbox value must be written in a specified file by Al

Al
Mon Jun 20 23:18:28 CDT 2005


"aquila" <adil.aquil@gmail.com> wrote in message
news:1119322723.204670.60640@g43g2000cwa.googlegroups.com...
> Greetings Vbscript Guru's,
> I am a complete Novice so bare with with me.
> This is my project I am working on.
> I need to place the value entered(for e.g 1.1.1.1) in the inputbox into
> a file where it is going to replace a variable called "ipaddress".
> When the value is pasted there a new file will be created.
> I am having trouble to use the popup box entered value I call it
> "input" in my scenario.

That part looks ok - when you say you are having trouble using it, what is
actually happening?

>
> See code below.
> Thanks in advance for anyone who can help me out here.
>
> AQUILA
>
>
> -------------begin----------
>
> Const ForReading = 1
> Const ForWriting = 2
> Dim Input
>
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Input = InputBox("Enter your IP address")
> MsgBox ("You entered: " & Input)

the above line should be either:

call MsgBox ("You entered: " & Input)

or:

MsgBox "You entered: " & Input

> Set objFile = objFSO.OpenTextFile("C:\scripts\test.txt", ForReading)
> Do Until objFile.AtEndOfStream
> strLine = objFile.ReadLine
> strLine = Replace(strLine, "ipaddress", & Input)

The "&" above is syntactically in error.

> strNewText = strNewText & strLine & vbCrLF
> Loop

Might be simpler to replace the entire loop with this:

strNewText = replace( objfile.readall, "ipaddress", input)

or even:

strNewText = replace( objfile.readall, "ipaddress", input, 1, -1,
vbtextcompare)

if there is a chance that "ipaddress" will appear in other than lowercase
only.

> objFile.Close
>
> Set objFile = objFSO.CreateTextFile("C:\scripts\test1.txt", ForWriting)
> objFile.WriteLine strNewText

Since your loop has already inserted the expected newline characters, it
might be less ambiguous to use ".write" instead of ".writeline".

/Al


> objFile.Close
> --------------------------end------------
>



Re: Inputbox value must be written in a specified file by aquila

aquila
Tue Jun 21 11:10:12 CDT 2005

thanks AL, I will try this and let you know.


Re: Inputbox value must be written in a specified file by James

James
Tue Jun 21 20:18:06 CDT 2005

aquila wrote:
> Greetings Vbscript Guru's,
> I am a complete Novice so bare with with me.
> This is my project I am working on.
> I need to place the value entered(for e.g 1.1.1.1) in the inputbox into
> a file where it is going to replace a variable called "ipaddress".
> When the value is pasted there a new file will be created.
> I am having trouble to use the popup box entered value I call it
> "input" in my scenario.
>
> See code below.
> Thanks in advance for anyone who can help me out here.
>
> AQUILA
>
>
> -------------begin----------
>
> Const ForReading = 1
> Const ForWriting = 2
> Dim Input
>
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Input = InputBox("Enter your IP address")
> MsgBox ("You entered: " & Input)
> Set objFile = objFSO.OpenTextFile("C:\scripts\test.txt", ForReading)
> Do Until objFile.AtEndOfStream
> strLine = objFile.ReadLine
> strLine = Replace(strLine, "ipaddress", & Input)
> strNewText = strNewText & strLine & vbCrLF
> Loop
>
> objFile.Close
>
> Set objFile = objFSO.CreateTextFile("C:\scripts\test1.txt", ForWriting)
> objFile.WriteLine strNewText
>
> objFile.Close
> --------------------------end------------
>

The only problem I see with your code is the ampersand you have on
the 2nd line inside your loop. Change the line to read:

strLine = Replace(strLine, "ipaddress", Input)