VBScript - Subtract one text file value from another

Associate
Joined
9 Sep 2008
Posts
40
Location
Moira, East Midlands
Only me!

I've just moved the bed in as I can see this being my second home now! ;)

I have 2 text files with one numerical value each (i.e. 54338). I would like to get another script to take one value and subtract it from the other, and have this resultant value written to a new (3rd) text file.

what I have is:

Const ForReading = 1

strComputer = "."

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("..\freespacebefore.txt", ForReading)
objFile1.Close

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile2 = objFSO.OpenTextFile("..\freespaceafter.txt", ForReading)
objFile2.Close

Set objFile3 = objFSO.CreateTextFile("..\savedspace.txt")
objFile3.WriteLine "savedspace=" & (objFile2-objFile1)
objFile3.Close


The error message I am getting is 'Object doesn't support this property or method' - refering to the highlighted text.
Help me Obi Wan......
 
Well you can't really 'subtract' text from text, you'll need to right a function to find the similarities and then have it remove that text. I think that's what you want?

For example.

Search for text(object1)
If object1 is found in object2
remove len(object1) from left(object2, <start position>)
end if

Obviously it's not exact but my brain isn't working at the minute and it's been a while since I've done VB.
 
I think he wants to do the subtraction on the number itself, not the text representation of the number ;)

Jim - You need to do a readline on each of the text files to get the figures into variables, do the calculation and then save the third file. At present you're attempting a maths function on file objects which is why you're getting problems.

Here's the rough idea:

Code:
Const ForReading = 1

strComputer = "."

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("..\freespacebefore.txt", ForReading)
iFile1Value = objFile1.Readline()
objFile1.Close

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile2 = objFSO.OpenTextFile("..\freespaceafter.txt", ForReading)
iFile2Value = objFile2.Readline()
objFile2.Close

iSavedSpace = iFile1Value - iFile2Value

Set objFile3 = objFSO.CreateTextFile("..\savedspace.txt")
objFile3.WriteLine "savedspace=" & (iSavedSpace )
objFile3.Close
 
Last edited:
That makes sense, a newbie error! :rolleyes:

I'm getting: Type mismatch: 'iFile1Value' error though.

i checked on M$ website and they detailed an issue with using adNumeric functions - but I tried the CDbl and CInt functions - nada, nyet & zilch!

:confused:
 
My text files had 'savedspace=' set as initial content in each one, so that Flash could use this as the variable it needed.

Trying to delete text (and not numericals) from one another was causing the issue. I just created another text file from the original, appending the 'savedspace=' into it and voila!
 
Back
Top Bottom