-
Formatting VB Script
Hello programmer's. I have the following VB script in VS2005, ASP.NET that writes sql data to a text file. Can someone help me understanding whether I can format the paydate and checkamt fields? Please see the two sample format problems below. I need to reformat certain values. Do I do the formatting in the Dim section or in the if not – then section or in the streamwriter section? Thank you.
Two Sample Format Problems:
1. Using the below VB script in asp.net the “paydate” is outputting to the checkfile.txt as 1/1/2010. I need to format it so it outputs as 1/1/10.
2. Using the below VB script in asp.net the “checkamt” is outputting to the checkfile.txt as 848.7000. I need to format it so it outputs as 848.70.
Hello programmer's. I have the following VB script in VS2005, ASP.NET that writes sql data to a text file. Can someone help me understanding whether I can format the paydate and checkamt fields? Currently the fields in the text file look like line one, but I want it to look like line two. Thanks.
Line 1(current look): 01/01/2010 848.7000
Line 2(wanted look): 01/01/10 848.70
Partial VB Script:
Code:
'************************START CREATING THE OUTPUT TEXT FILE***********************************
Dim flag As Boolean
Dim ds As New DataSet
Dim da As New SqlDataAdapter
objComm = New SqlCommand("select * from tbl2txt", objConn)
objComm.CommandTimeout = 500
''The flag is to let me know which authentication response to issue
flag = False
da.SelectCommand = objComm
da.Fill(ds)
intFileNum = ds.Tables(0).Rows.Count
objConn.Close()
If intFileNum > 0 Then
flag = True
'START CREATE THE OUTPUT FILE HERE
'extract all fields out 1st, then format and write using the StreamWriter
Dim sw As New System.IO.StreamWriter("c:\CheckFile.txt")
For Each dr As DataRow In ds.Tables(0).Rows
Dim Strpaydate As String = String.Empty
Dim Strcheckamt As String = String.Empty
Dim Strname As String = String.Empty
Dim Stradd1 As String = String.Empty
Dim Stradd2 As String = String.Empty
Dim Stradd3 As String = String.Empty
Dim Stradd4 As String = String.Empty
Dim Strpostcode As String = String.Empty
Dim Strinvno As String = String.Empty
Dim Strdocdate As String = String.Empty
Dim Strinvoiceamt As String = String.Empty
Dim Strvendor As String = String.Empty
Dim Strcheckno As String = String.Empty
Dim Strsname As String = String.Empty
Dim StrGrp As String = String.Empty
Dim StrGroupName As String = String.Empty
'Make sure the value coming back from the DataBase is Not Null. If it has value then write it using the StreamWriter to the text file. WriteLine makes a new line for each entry
If Not IsDBNull(dr("paydate")) Then Strpaydate = (dr("paydate"))
If Not IsDBNull(dr("checkamt")) Then Strcheckamt = Format(dr("checkamt"))
If Not IsDBNull(dr("name")) Then Strname = (dr("name"))
If Not IsDBNull(dr("add1")) Then Stradd1 = (dr("add1"))
If Not IsDBNull(dr("add2")) Then Stradd2 = (dr("add2"))
If Not IsDBNull(dr("add3")) Then Stradd3 = (dr("add3"))
If Not IsDBNull(dr("add4")) Then Stradd4 = (dr("add4"))
If Not IsDBNull(dr("postcode")) Then Strpostcode = (dr("postcode"))
If Not IsDBNull(dr("invno")) Then Strinvno = (dr("invno"))
If Not IsDBNull(dr("docdate")) Then Strinvno = (dr("docdate"))
If Not IsDBNull(dr("invoiceamt")) Then Strinvoiceamt = (dr("invoiceamt"))
If Not IsDBNull(dr("vendor")) Then Strvendor = (dr("vendor"))
If Not IsDBNull(dr("checkno")) Then Strcheckno = (dr("checkno"))
If Not IsDBNull(dr("sname")) Then Strsname = (dr("sname"))
If Not IsDBNull(dr("Grp")) Then StrGrp = (dr("Grp"))
If Not IsDBNull(dr("GroupName")) Then StrGroupName = (dr("GroupName"))
'Now write to the streamwriter, adding a space between the values
sw.WriteLine(Strpaydate + " " + " " + Strcheckamt + " " + Strname + " " + Stradd1 + " " + Stradd2 _" " + Stradd3 + " " + Stradd4 + " " + Strpostcode + " " + Strdocdate + " " + Strinvoiceamt + " " + Strvendor _" " + Strinvno + " " + " " + Strcheckno + " " + Strsname + " " + StrGrp + " " + StrGroupName)
Next
'Clean Up
sw.Flush()
sw.Close()
'Clean Up
objConn.Dispose()
ds.Dispose()
da.Dispose()
End If
Last edited by Hack; 01-14-2010 at 12:23 PM.
Reason: Added Code Tags
-
Formatting Date and Number in VB Script
For date formatting
sDate = CDate("01/01/2010")
resultDate = CStr(Month(sDate)) + "/" + CStr(Day(sDate)) + "/" + Right(CStr(Year(sDate)),2)
For number formatting
FormatNumber(848.70000,2,,,0)
Thanks,
-Uday
-
Great information thanks again.
ip
Similar Threads
-
By bubberz in forum ASP.NET
Replies: 2
Last Post: 08-23-2005, 02:19 PM
-
By Karey in forum Database
Replies: 6
Last Post: 03-03-2002, 07:12 PM
-
By Zane Thomas in forum .NET
Replies: 147
Last Post: 01-31-2001, 01:00 PM
-
By Jon Ogden in forum .NET
Replies: 84
Last Post: 01-29-2001, 01:12 PM
-
By jason in forum VB Classic
Replies: 0
Last Post: 10-12-2000, 02:56 PM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks