Computing.Net > Forums > Programming > vbScript Looping problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vbScript Looping problem

Reply to Message Icon

Name: Boyle
Date: October 3, 2009 at 12:25:57 Pacific
OS: Windows 7
Subcategory: Theory
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 3, 2009 at 16:39:18 Pacific
Reply:

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.


0

Response Number 2
Name: Boyle
Date: October 4, 2009 at 07:55:25 Pacific
Reply:

Ignore this, solved it myself.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: vbScript Looping problem

Fortran Do loop problem www.computing.net/answers/programming/fortran-do-loop-problem/9488.html

DOS - For Loop Problem www.computing.net/answers/programming/dos-for-loop-problem/17488.html

For loop problem again www.computing.net/answers/programming/for-loop-problem-again/18249.html