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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Text File

Status
Not open for further replies.

Lambro

Programmer
Aug 22, 2001
258
US
I have a text file with two columns: Email and SSN
Below is the text file named login.txt:

Email, SSN
14342, 4323
43545, 2232
03232, 2322
23232, 0434


Below is the code for my file called sDSNFile.dsn

[ODBC]
DRIVER=Microsoft Text Driver (*.txt; *.csv)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=25
MaxBufferSize=2048
FIL=text
Extensions=None,asc,csv,tab,txt
DriverId=27
DefaultDir=C:\Inetpub\



Below is my code for displaying the text file:


<%
Dim sDSNFile
sDSNFile = "sDSNFile.dsn"

' Let's now dynamically retrieve the current directory
Dim sScriptDir
sScriptDir = Request.ServerVariables("SCRIPT_NAME")
sScriptDir = StrReverse(sScriptDir)
sScriptDir = Mid(sScriptDir, InStr(1, sScriptDir, "/"))
sScriptDir = StrReverse(sScriptDir)

' Time to construct our dynamic DSN
Dim sPath, sDSN
sPath = Server.MapPath(sScriptDir) & "\"
sDSN = "FileDSN=" & sPath & sDSNFile & _
";DefaultDir=" & sPath & _
";DBQ=" & sPath & ";"

' Building Data Connection
Dim Conn, rs
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open sDSN

' Get only the Name and Price fields
Dim sql
sql = "SELECT Email,SSN FROM login.txt"

'Implicitly create a recordset object with the
'results of this query
set rs = conn.execute(sql)


'Print out the contents of our recordset
Do WHile Not rs.EOF
Response.Write "Email: " & rs("Email")
Response.Write "<br>SSN: " & rs("SSN")
Response.Write "<HR>")

rs.MoveNext 'Move to the next record
Loop

'Close our recordset and connection
rs.close
set rs = nothing
conn.close
set conn = nothing
%>


My problem is that any of the numbers that begin with zero display with the zero missing. So if the number is 034332, it displays as 34332.
 
If you know that the length should always be 5, would this work:
Code:
strOriginal = "1234"
strNew = Pad(strOriginal, 5)
Response.Write strNew

Function Pad(strText, nLen)
	While Len(strText) < nLen
		strText = "0" & strText
	Wend
	Pad = strText
End Function 'Pad

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
So, your text file looks something like this:

Email, SSN
1234 0987
12345 9876


Where you have 4 digit and 5 digit Email numbers in the text file?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top