Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Code Producing Multiple Headings 1

Status
Not open for further replies.

EMoore12

Technical User
Oct 6, 2004
30
0
0
US
I have code that loops through a directory and outputs files to a .htm page based on a search criteria that the user enters. I would like to have one heading on the page but everytime it loops through the directory it adds another header. I'm trying to determine a way for the code to detect if the header exists and if it does to stop adding the headers. Any guidance you can provide would be greatly appreciated.


Sub CheckFolder(objCurrentFolder,objLogFile,State,Yr,Evt)

Dim strSearch
Dim strStYr
Dim strYr
Dim strShip
Dim strEvent
Dim strOutput
Dim strOutput1
Dim objNewFolder
Dim objFile
Dim objStream
Dim objShell
Dim Getyr
Dim GetShip
Dim GetEvent
Dim EvtName
Dim intCount
'Dim intCount2
Dim HeaderExists

GetState = State
GetYr = Yr
GetEvent = Evt
GetShip = Ship


If evt = "N" Then
EvtName = "Natality"
ElseIf evt = "M" Then
EvtName = "Mortality"
ElseIf evt = "F" Then
EvtName = "Fetal Death"
ElseIf evt = "T" Then
EvtName = "Medical"
End If


strOutput1 = "<h3><center>Search Results for" & Chr(32) & GetState & Chr(32) & GetYr & Chr(32) & "*" & _
Chr(32) & EvtName & "</center></h3>"
objLogFile.writeline strOutput1




For Each objFile In objCurrentFolder.Files
strStYr=Mid(objFile.Name,6,4)
strEvent = Mid(objFile.Name,13,1)
strSearch = strStYr & strEvent

If strSearch=GetState & GetYr & GetEvent Then
intCount = intCount + 1


'Alternating Row Colors
If intCount Mod 2 = 0 Then
strOutput = "<table>" & "<tr bgcolor=#CAE1FF>" & "<td>" & "TSA:" & _
Chr(32) & Chr(32) & "<A href=" & _
CStr(objFile.Path) & ">" & CStr(objFile.Path) & "</A>" & Chr(32) & _
"CREATED:" & Chr(32) & CStr(objFile.datecreated) & "</td>" & "</tr>" & "</table>" & Chr(13)
objLogFile.writeline strOutput
Else
strOutput = "<table>" & "<tr bgcolor=#C1FFB1>" & "<td>" & "TSA:" & _
Chr(32) & Chr(32) & "<A href=" & _
CStr(objFile.Path) & ">" & CStr(objFile.Path) & "</A>" & Chr(32) & _
"CREATED:" & Chr(32) & CStr(objFile.datecreated) & "</td>" & "</tr>" & "</table>" & Chr(13)
objLogFile.writeline strOutput

End If


End If


Next

'Recurse Through all of the folders
For each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder, objLogFile, State, Yr, Evt

Next


End Sub
 
> I'm trying to determine a way for the code to detect if the header exists and if it does to stop adding the headers.
How about simply add a boolean argument to the sub?
[tt]
Sub CheckFolder(objCurrentFolder,objLogFile,State,Yr,Evt[blue],bHeader[/blue])
'etc etc
[blue]if bHeader then[/blue]
strOutput1 = "<h3><center>Search Results for" & Chr(32) & GetState & Chr(32) & GetYr & Chr(32) & "*" & _
Chr(32) & EvtName & "</center></h3>"
objLogFile.writeline strOutput1
[blue]end if[/blue]
'etc etc
'Recurse Through all of the folders
For each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder, objLogFile, State, Yr, Evt[blue], false[/blue]
Next
'etc etc
End Sub
[/tt]
Somewhere somehow, the CheckFolder has to be called from outside. Modify that line by adding the last argument by setting it to true.
[tt] CheckFolder ...[blue], true[/blue][/tt] 'the originating external call
 
Thanks tsuji. Your suggestion worked.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top