vbScript Looping problem

October 3, 2009 at 12:25:57
Specs: Windows 7
Const ForReading = 1

Set objFSO = 
CreateObject("Scripting.FileSystemObject")
Set objTextFile2 = 
objFSO.OpenTextFile("%PATH%dates.txt", 
ForReading)

Set FSO = 
CreateObject("Scripting.FileSystemObject") 
Set inFile = FSO.OpenTextFile( 
"%PATH%dates.txt" ) 
lines = Split( inFile.ReadAll, vbLF ) 
lineCount = UBound(lines) ' assumes last line 
ends with line break

For i1 = 1 to linecount

strLine1= objTextFile2.ReadLine

Set objFSO = 
CreateObject("Scripting.FileSystemObject")
Set objTextFile = 
objFSO.OpenTextFile("%PATH%Notes1.txt", 
ForReading)

Set FSO = 
CreateObject("Scripting.FileSystemObject") 
Set inFile = FSO.OpenTextFile( 
"%PATH%Notes1.txt" ) 
lines = Split( inFile.ReadAll, vbLF ) 
lineCount = UBound(lines) ' assumes last line 
ends with line break

For i = 1 to linecount

	strLine = objTextFile.ReadLine 
	
	strFinalout = vbCrLf & DateDiff("d", 
Now(), strLine1) & " days until " &  strLine
	
 Final	
	
Next
Next


Sub Final

Dim objFSO, objFolder, objShell, objTextFile, 
objFile
Dim strDirectory, strFile, Appname

Appname = "Notes"

strDirectory = "%PATH%"
strFile = "\Notes.txt"

' Create the File System Object
Set objFSO = 
CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = 
objFSO.GetFolder(strDirectory)
Else
   Set objFolder = 
objFSO.CreateFolder(strDirectory)
   WScript.Echo "Just created " & strDirectory
End If

If objFSO.FileExists(strDirectory & strFile) 
Then
   Set objFolder = 
objFSO.GetFolder(strDirectory)
Else
   Set objFile = 
objFSO.CreateTextFile(strDirectory & strFile)
   Wscript.Echo "Just created " & strDirectory 
& strFile
End If 

set objFile = nothing
set objFolder = nothing

' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting 
= 2
Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)
' Writes strText every time you run this 
VBScript

objTextFile.WriteLine(strFinalOut)
objTextFile.Close
End Sub

WScript.Quit

I have another script that gets user input and
saves the date entered into dates.txt and the user input into notes1.txt, the
purpose of this script is to get the dates, find
the datediff between them and now then add
text(notes1.txt) onto the end. Everything said previously
has been managed ok but I can't figure out
how to solve an output problem. It should
output :

X days until .....
Y days until......
Z days until.....
ect....

But instead due to the way the loop's
structured it outputs:

Z days until.....
Z days until.....
Z days until.....
ect....

or the other way I tried it outputs:

X days until.....
Y days until.....
X days until.....
X days until.....
Y days until.....
Ydays until.....
ect....

Also %path% isn't used, it's just to shorten
the code on here save posting the direct path
to the directory.

Any help / suggestions would be appreciated.


See More: vbScript Looping problem

Report •


#1
October 3, 2009 at 16:39:18
Do you know what I want to know?

I want to know what browser everyone seems to be using that send hard line returns on its word wrap.


Report •

#2
October 4, 2009 at 07:55:25
Ignore this, solved it myself.

Report •

Related Solutions


Ask Question