Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 FileSystem Object Question

Author  Topic 

edb2003
Yak Posting Veteran

66 Posts

Posted - 2003-08-14 : 14:24:28
Hi everyone,


Is there a way I can get my search page to print like it displays on the browser? Here is a snippet of code that follows the same routine throughout my search page. When I add tags to the below it simple prints out the HTML tags with the text and does not format it. I am using Filesystems object and the Windows Script Host Network Object.


tmpMessage = tmpMessage & "Title:" & " "

tmpMessage = tmpMessage & "Size:" & " "

tmpMessage = tmpMessage & "Sheets:" & " "

tmpMessage = tmpMessage & "CurrRev:" & " "

tmpMessage = tmpMessage & "Location:" & " "

tmpMessage = tmpMessage & "OOC:" & vbCrLf


tmpMessage = tmpMessage & ArrTitle(tmpindex) & " "

tmpMessage = tmpMessage & ArrSize(I) & " "

tmpMessage = tmpMessage & ArrSheets(I) & " "

tmpMessage = tmpMessage & ArrCurrRev(I) & " "

tmpMessage = tmpMessage & ArrLocation(I) & " "

tmpMessage = tmpMessage & ArrOOC(I) & vbCrLf


Appreciate your help :)
Ed

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-14 : 15:55:25
You might get a faster reply if you post your question on a VB forum.

Tara
Go to Top of Page

edb2003
Yak Posting Veteran

66 Posts

Posted - 2003-08-14 : 16:12:10
Sorry,
Here it is ....


<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<% Response.Buffer = true %>


<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<title>BRP Order Form</title>



</head>

<body>

<%
Dim strTime, ArrMasterReq
strTime=""
Dim sFullUser,iPos,sDomain,sUser,strUser,objUser

sFullUser = trim(Request.ServerVariables ("LOGON_USER"))
iPos = InStr(sFullUser, "\")
sDomain = Left(sFullUser, iPos - 1)
sUser = Mid(sFullUser, iPos + 1)

Set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)

strTime= FormatDateTime(Now, vbLongDate) & " "
strTime = strTime & FormatDateTime(Now, vbShortTime) & " " & RIGHT((FormatDateTime(Now, vbLongTime)),2)

%>
<table><tr><td>
<Font face="Arial" size="3"><B>ELECTRONIC RECORDS REPRODUCTION REQUEST</B></FONT>
</td></tr>
<tr><td><hr></td></tr>
<tr><td>Requestor:<%=sFullUser%></td></tr>
<tr><td>Extension:</td></tr>
<tr><td>Department:</td></tr>
<tr><td>Date/Time:<%=FormatDateTime(Now, vbLongDate) & " " & FormatDateTime(Now, vbShortTime) & " " & RIGHT((FormatDateTime(Now, vbLongTime)),2)%>

<%
Dim strHeader,strDivider,strMsgHeader

Dim strRequestor, strExtension, strDepartment,strInstructions,tmpInstructions

strHeader=""
strHeader = "ELECTRONIC RECORDS REPRODUCTION REQUEST" & VbCrLf

strDivider = "*************************************" & VbCrLf
strRequestor="Requestor:" & sFullUser & VbCrLf
strExtension="Extension:" & VbCrLf
strDepartment="Department:" & VbCrLf
tmpInstructions=Request.Form("instructions")
strInstructions="Special Instructions:" & tmpInstructions
strTime=strTime & VbCrLf

Dim strMessage2
strMessage2 = ""

strMsgHeader = strHeader & strTime & strDivider & strRequestor & strExtension & strDepartment & strInstructions

'SET COOKIES
Response.Cookies("Header") = strMsgHeader


%>


</td>
<tr><td><hr></td></tr>

<form name="orderform" action="brp_orderform.asp" method=post>

<tr><td>Special Instructions: <input type="text" size="50" name="instructions"></td></tr>



<%


Dim strSubmit 'Form value for the Submit Button
Dim strPrinterPath 'Form value for Network Path to Printer
Dim strUsername 'Form value for Username
Dim strPassword 'Form value for Password
Dim strMessage 'Form value for Message to Print
Dim objFS 'VBScript File System Object
Dim objWSHNet 'Windows Script Host Network Object
Dim objPrinter 'Printer Object to stream text to

strSubmit = Request.Form("Submit")

If strSubmit = "" Then

'
' If we have not received the results from the form we must
' display it.
'


Response.write "<FORM action=brp_print.asp method=POST id=form name=form>"

Response.write "<table width=704 border=0 cellspacing=0 cellpadding=2 height=22 bgcolor=#FFFFFF>"
Response.write "<tr bgcolor=E2E2E2>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Document</b></font></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Title</b></font></td>"
Response.write "<td width=120 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Size</b></font></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Sheets</b></font></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Cur Rev</b></font></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Loc</b></font></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Class</b></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>OOC</b></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Unincorporated ECN's</b></td>"
Response.write "<td width=105 align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif><b>Master Req?</b></td>"
Response.write "</tr>"


'Parse out the array of documents ordered.

Dim tmpbound,strdocnames,FileArray, tempArray,tmpfilename1,strtempnames
Dim strdoctitle,strdocsize,strdocsheets,strdocCurrRev,strdocLocation,strdocClass,strdocOOC,strdocECNS,strdocMasterReq
Dim ArrTitle,ArrSize,ArrSheets,ArrCurrRev,ArrLocation,ArrClass,ArrOOC,ArrECNS,ArrMaster

'Request.Form("Checkbox")
'Response.write "Checkbox" & (Request.Form("Checkbox") & "<br>")

'#######
strdocnames=Request.form("Checkbox")
'Response.Write "strdocnames" & strdocnames & "<BR>"

'#check for the index that goes with this file

'######


strtempnames=Request.form("DocumentName")

strdoctitle=Request.form("DocumentTitle")
'Response.Write "strdocTitle" & strdoctitle & "<BR>"

strdocsize=Request.form("DocumentSize")
strdocsheets=Request.form("DocumentSheets")
strdocCurrRev=Request.form("DocumentCurRev")
strdocLocation=Request.form("DocumentLocation")
strdocClass=Request.form("DocumentClass")
strdocOOC=Request.form("DocumentOOC")
strdocECNS=Request.form("DocumentECNS")


if strdocnames <> "" then

FileArray = split(strdocnames, ",")
TempArray = split(strtempnames,",")
ArrTitle = split(strdoctitle, ",")

'DEBUG
'For I = LBound(ArrTitle) to UBound(ArrTitle)
'Response.Write "ArrTitle" & I & ":" & ArrTitle(I) & "<BR>"
'next

ArrSize = split(strdocsize, ",")
ArrSheets = split(strdocsheets, ",")
ArrCurrRev = split(strdocCurrRev, ",")
ArrLocation = split(strdocLocation, ",")
ArrClass = split(strdocClass, ",")
ArrOOC = split(strdocOOC, ",")
ArrECNS = split(strdocECNS, ",")


Dim I
I=0
Dim objRS_temp,strSQL,tmpfile, tmpMessage
Set objRS_temp = Server.CreateObject("ADODB.Recordset")
tmpMessage=""
'INITIALIZE COOKIES
Response.Cookies("Message") = tmpMessage



Dim tmpfilenext,tmpfilename2,tmpindex,X,Y,newstring
tmpfilenext = ""
tmpfilename2 = ""
tmpindex = 0
X = 0
Y = 0

For I=0 to UBound(FileArray)

mystring=FileArray(I)
mystring=RemoveIndexNum(mystring)

Response.write "<tr align=center><td align=center><input type=text size=15 name=DocumentSize readonly onfocus=blur() value=" & mystring & ">" & "</font></TD>"

'#get the index that goes with this file that I recorded with the
'checkbox info.

Dim charnum,mystring,tmpvar
Dim str1, tempchar_position, tempstr,tempstr_length
str1 = "#"
mystring=""

tempchar_position = InStr(FileArray(I),str1)
tempstr = FileArray(I)
tempstr_length = Len(tempstr)

tempstr = Right(tempstr,(tempstr_length - tempchar_position))

'convert text data type to integer

tmpindex=CSng(tempstr)

if ArrTitle(tmpindex)= "" then
tmpvar="N/A"
else
tmpvar=ArrTitle(tmpindex)
'Response.write "tmpindex" & tmpindex & "<BR>"
'Response.write "ArrTitle(tmpindex)" & ArrTitle(tmpindex)& "<BR>"
'Response.write "tmpvar" & tmpvar & "<BR>"
end if

Response.write "<td><font face=arial size=2>" & ArrTitle(tmpindex) & "</font></td>"

Response.write "<td><font face=arial size=2>" & ArrSize(tmpindex) & "</font></td>"

Response.write "<td><font face=arial size=2>" & ArrSheets(tmpindex) & "</font></td>"

Response.write "<td><font face=arial size=2>" & ArrCurrRev(tmpindex) & "</font></td>"

Response.write "<td><font face=arial size=2>" & ArrLocation(tmpindex) & "</font></td>"

Response.write "<td><font face=arial size=2>" & ArrClass(tmpindex) & "</font></td>"

Response.write "<td><font face=arial size=2>" & ArrOOC(tmpindex) & "</font></td>"

Response.write "<td><font face=arial size=2>" & ArrECNS(tmpindex) & "</font></td>"

tmpfile = FileArray(I)
Response.write "<td><input type=checkbox name=MasterReq value=" & tmpfile & ">" & "</TD>"


tmpMessage = tmpMessage & "Master Required?:" & FileArray(I) & vbCrLf
Response.write "<td> </td>"

Response.Write "</tr>"

'SET LAYOUT FOR PRINTER

tmpMessage = vbCrLf & tmpMessage & "********************************************" & VbCrLf & "Document:" & FileArray(I) & vbCrLf


Response.write "<td><font face=arial size=2>" & tmpMessage = tmpMessage & "Title:" & "</font></td>"

tmpMessage = tmpMessage & "Size:" & " "

tmpMessage = tmpMessage & "Sheets:" & " "

tmpMessage = tmpMessage & "CurrRev:" & " "

tmpMessage = tmpMessage & "Location:" & " "

tmpMessage = tmpMessage & "OOC:" & vbCrLf


tmpMessage = tmpMessage & ArrTitle(tmpindex) & " "

tmpMessage = tmpMessage & ArrSize(I) & " "

tmpMessage = tmpMessage & ArrSheets(I) & " "

tmpMessage = tmpMessage & ArrCurrRev(I) & " "

tmpMessage = tmpMessage & ArrLocation(I) & " "

tmpMessage = tmpMessage & ArrOOC(I) & vbCrLf



'SET COOKIES
Response.Cookies("Message") = tmpMessage

next

end if


GetUserName
else



SendToPrinter
end if

%>



<%

SUB GetUserName
Response.Write "<hr><TABLE WIDTH=200 BORDER=0 CELLSPACING=1 CELLPADDING=1><TR>"
Response.Write "<hr><TD ALIGN=right NOWRAP>Login ID:</TD>"
Response.Write "<TD ALIGN=left NOWRAP><INPUT type=text id=username name=username value=" & strUsername & "></TD>"
Response.Write "</TR><TR><TD ALIGN=right NOWRAP>Password:</TD><TD ALIGN=left NOWRAP>"
Response.Write "<INPUT type=password id=password name=password></TD></TR></Table>"

Response.Write "<tr><td><hr></td></tr>"
Response.Write "<tr><td><INPUT type=submit value=Submit id=submit name=submit></td></tr>"
Response.Write "<tr><td><hr></td></tr>"
Response.Write "</table></form>"

End Sub


SUB SendToPrinter


' Get information from our form
strPrinterPath="\\SYLFS003\Canon$omega"
'Response.write strPrinterPath
strUsername = Request.Form("username")
strUsername = "ocean\" & strUsername
strPassword = Request.Form("password")
'Response.write strpassword

strdocMasterReq=Request.form("masterreq")
ArrMasterReq = split(strdocMasterReq, ",")

Dim N, tmpMaster,strMessage3
N=0
tmpMaster=""
strMessage3=""

For N=0 to UBound(ArrMasterReq)
strMessage3=strMessage3 & ArrMasterReq(N) & VbCrLf
next


strMessage2 = "Master Document is Required for the following items:" & VbCrLf


strMessage = Request.Cookies("Header") & Request.Cookies("Message") 'GET COOKIES
'Get Which Master's are required
strMessage = strMessage & "**********************" & VbCrLf & tmpMessage & VbCrLf & "**********************" & strMessage2 & VbCrLf & strMessage3

'Dim ErrMsg

'If strUserName = "" then
'ErrMsg="You did not enter a user name"
'end if

'if strPassword = "" then
'ErrMsg="You did not enter a password"
'end if


' Create FileSystem Object and Windows Script Host Network Object

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objWSHNet = CreateObject("WScript.Network")

' Connect to Network Printer from Windows Script Host

objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, strusername, strpassword

' Open Print device as a file using the File System Object

Set objPrinter = objFS.CreateTextFile("LPT1", True)

' Send text to print device using the File System Object

objPrinter.Write(strMessage)

' Close the print device object and trap for errors

On Error Resume Next
objPrinter.Close

' If an error has occurred while closing the printer connection,
' output what went wrong.
'
If Err Then
Response.Write ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err.Clear
Else

' The operation succeeded. Output a confirmation (DEBUG)

Response.Write "<CENTER>"
Response.Write "<TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1>"
'Response.Write "<TR><TD ALIGN=RIGHT><B>Message Sent:</B></TD>"
'Response.Write "<TD ALIGN=LEFT>" & strMessage & "</TD></TR>"
'Response.Write "<TR><TD ALIGN=RIGHT><B>Path to Network Printer:</B></TD>"
'Response.Write "<TD ALIGN=LEFT>" & strPrinterPath & "</TD></TR>"
'Response.Write "<TR><TD ALIGN=RIGHT><B>Login ID:</B></TD>"
'Response.Write "<TD ALIGN=LEFT>" & strUsername & "</TD></TR>"
Response.Write "<BR><BR><B><Font face=Verdana size=2 color=red>Your request has been submitted, Thank you.</B></font>"
Response.Write "</TABLE>"
Response.Write "</CENTER>"

'Response.write tmpMessage & "<BR>"

' Remove the printer connection

objWSHNet.RemovePrinterConnection "LPT1:"
Set objWSHNet = Nothing
Set objFS = Nothing
Set objPrinter = Nothing

end if

END SUB

FUNCTION RemoveIndexNum(mystring)
Dim this_string,newstring
Dim strchar, strchar_position,str_length, str_remove

strchar="#" 'The delimiting character that it searches for in the string
strchar_position = InStr(mystring,strchar)

str_length = Len(mystring)
str_remove=str_length - 2
'Response.Write "str_remove" & str_remove & "<BR>"

mystring= Left(mystring,str_remove)
RemoveIndexNum = mystring
'Response.Write "mystring" & mystring & "<BR>"

END FUNCTION
%>


</body>
</html>
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-14 : 16:51:55
No, what I was saying is that SQLTeam is for SQL Server related questions. You have posted a VBScript question. You might want to post your question on another site that deals with VBScript. Someone here might answer your question, but typically only SQL Server questions are answered here.

Tara
Go to Top of Page
   

- Advertisement -