Click to See Complete Forum and Search --> : textfile position


chicken.king
03-31-2005, 11:05 PM
Hello
I created a web which is use for data entry.
I am also create a textfile. Is it posible that the textfile contains is exactly same as the web page. I mean the position or alignment of the text.

phpnovice
03-31-2005, 11:37 PM
For what purpose?

chicken.king
04-01-2005, 12:08 AM
It is because some user might want to save the data to a document file and print it in the future.

I would like to make to textfile data look exactly same as the web page

phpnovice
04-01-2005, 08:09 AM
You mean have the text file look like a rendered HTML page? No. You can certainly create the text file with the same HTML content as the web page. However, that would be in source format -- not rendered. Otherwise, if you mean to have the text file have the same text content as the main area of the web page... Yes, you can do that -- though it won't be exactly the same because the browser renders text a little differently than plain text.

chicken.king
04-01-2005, 08:06 PM
thank you for your reply
sorry to bother you so much.I hope you won't mind

HOw can I keep the data into the textfile with a constant alignment. i can't arrange the position of the data so the data are become very messy in the text files.

Here Is my code :-

name= request.QueryString("name")
address = Request.QueryString("address")
age = Request.QueryString("age")
status= Request.QueryString("status")

Set filesys = server.CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\EPS.doc", true)
path = filesys.GetAbsolutePathName("c:\EPS.doc")
getname = filesys.GetFileName(path)

filetxt.WriteLine("Name :"& name & vbtab & "Address :"& address)
filetxt.WriteLine("Age :"& age & vbtab & "Marital Status :"& status)
filetxt.Close
end function

phpnovice
04-02-2005, 10:40 AM
Perhaps you could use functions like these:

Function FormatColumns(aryData, aryColumns, aryDelim)
Dim a, c
FormatColumns = ""
For a = LBound(aryData) To UBound(aryData)
c = Mid(aryColumns(a), 2) * 1
Select Case Left(aryColumns(a), 1)
Case "L"
FormatColumns = FormatColumns & (JLeft(aryData(a), c) & aryDelim(a))
Case "C"
FormatColumns = FormatColumns & (Center(aryData(a), c) & aryDelim(a))
Case "R"
FormatColumns = FormatColumns & (JRight(aryData(a), c) & aryDelim(a))
End Select
Next
End Function

Function JLeft(StringData, FinishedLength)
JLeft = Left(StringData & String(FinishedLength, " "), FinishedLength)
End Function

Function Center(StringData, FinishedLength)
If Len(StringData) >= FinishedLength Then
Center = Left(StringData, FinishedLength)
Else
Center = Left(String(Fix((FinishedLength - Len(StringData)) / 2), " ") & _
StringData & String(FinishedLength, " "), FinishedLength)
End If
End Function

Function JRight(StringData, FinishedLength)
If Len(StringData) >= FinishedLength Then
JRight = Left(StringData, FinishedLength)
Else
JRight = String(FinishedLength - Len(StringData), " ") & StringData
End If
End Function

and call then something like this:

cols = Array("L6", "C30", "R14", "C30")
dels = Array(": ", " ", ": ", "")
'
ary1 = Array("Name", name, "Address", address)
filetxt.WriteLine FormatColumns(ary1, cols, dels)
ary1 = Array("Age", age, "Marital Status", status)
filetxt.WriteLine FormatColumns(ary1, cols, dels)

chicken.king
04-03-2005, 09:02 PM
thanks for your help I will try it now

chicken.king
04-04-2005, 02:33 AM
Thank you very much.The code works. But the for loop that you code contain error. So, I use a stupit way to test the code.

phpnovice
04-04-2005, 08:45 AM
What error? I tested the code before I gave it to you. It worked perfectly -- even for the example I gave. I would guess that any error caused would be the result of passing inconsistent arguments to the function. In other words, all three array arguments must have the same number of elements in each array.

chicken.king
04-05-2005, 09:19 PM
The error is :-
"expected end of statement"
next a

I still trying to understand the code
One question that I would like to ask.

cols = Array("L6", "C30", "R14", "C30")

why you put in number in L6, C30, R14 and c30
what is all the number means

phpnovice
04-05-2005, 10:37 PM
To fix that error, just remove the letter "a". I converted these from some Visual Basic code I had. Sorry for the oversight. As for the column specifications... The letter is the formatting for the column data -- "L"eft, "C"enter, and "R"ight justified. The number is the maximum width for the column data. These must be sandwiched together as shown in the example.

chicken.king
04-06-2005, 01:25 AM
Thank you so much :)
One last question. What does it mean ?

1. FormatColumns = FormatColumns & (JLeft(aryData(a), c) & aryDelim(a))
2. JLeft = Left(StringData & String(FinishedLength, " "), FinishedLength)

phpnovice
04-06-2005, 08:13 AM
1. "FormatColumns" is the name of the function. In VBScript, to return a value from a function, you return that value by assigning it to the function name. This, in this case, the return value may be concatenated with additional values.

2. The String() function creates a string of a specified length using a specified character. In this case, we want to create a column that is of a particular width. Thus, when left justification is desired, we can add a column-width number of spaces to the original data in order to create such a column. The Left() function truncates the resulting string to the exact column width.

chicken.king
04-06-2005, 09:05 PM
OK thank you so much

phpnovice
04-06-2005, 10:51 PM
Cheers.

chicken.king
04-07-2005, 08:44 PM
phpnovice
Can this concept that you are given can be apply to the visual basic 6.0
I mean the alignment of the listbox ?

phpnovice
04-07-2005, 11:19 PM
Yes, I converted two of these functions (FormatColumns and Center) from two VB6 functions I already had. I added the other two functions (JLeft and JRight) -- just for you -- in order to make a complete set. I used them with the VB6 Listbox control and specified a fixed-spacing font (Courier New) so that the columns would line up.

chicken.king
04-08-2005, 01:07 AM
thanks again
I am thinking for so long to solve this listbox problem

phpnovice
04-08-2005, 07:56 AM
Cheers.

chicken.king
04-17-2005, 09:12 PM
After I create the textfile and write the data in it. Is it posible that I get back the value from the textfile.

phpnovice
04-17-2005, 11:23 PM
Here is an example of reading from a text file:
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objFSO, objFile, objOpenFile, txt
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(Server.MapPath("/folder/textfile.txt"))
Set objOpenFile = objFile.OpenAsTextStream(ForReading)
txt = objOpenFile.ReadAll
objOpenFile.Close
Set objOpenFile = Nothing
Set objFile = Nothing
Set objFSO = Nothing
'
Response.Write "<p>" & txt & "</p>" & vbCrLf
%>

chicken.king
04-18-2005, 06:26 AM
Thank a lot it works

phpnovice
04-18-2005, 07:15 AM
Cheers.