Microsoft KB Archive/193262

= PRB: Quotes Added When Using Write# to Write Numbers to File =

Article ID: 193262

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q193262



SYMPTOMS
When writing numerical data obtained from a database recordset to a text file using the Write# command, Visual Basic erroneously places quotes around the numbers.



RESOLUTION
See the workaround as described in the MORE INFORMATION section below.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic. Form1 is created by default. Select References from the Project menu and check Microsoft DAO 3.5 Object Library or Microsoft DAO 3.51 Object Library.  Paste the following code into the declarations section of Form1:` Private Sub Form_Load Dim wrkJet As Workspace Dim dbsNorthwind As Database Dim rsInvoices As Recordset 'Create Microsoft Jet Workspace object. Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet) 'Open Database object from saved Microsoft Jet database for 'exclusive use. MsgBox "Opening Northwind..." Set dbsNorthwind = wrkJet.OpenDatabase("Nwind.mdb", True) Set rsInvoices = dbsNorthwind.OpenRecordset("select _        [Salesperson],[OrderID],[OrderDate],[ProductID] from [Invoices]") Open "test.tmp" For Output As #1 Write #1, rsInvoices.Fields("productid").Properties("Value").Value Write #1, rsInvoices!ProductID Close #1 rsInvoices.Close dbsNorthwind.Close wrkJet.Close

Dim a As Long, b As Long Open "test.tmp" For Input As #1 Input #1, a, b        Msgbox "a=" & a         Msgbox "b=" & b         Close #1 End Sub   Press the F5 key to run the project. The message boxes "a=24" and "b=0" are displayed.

NOTE: The file test.tmp that is created in the project or default Visual Basic directory has the following contents which demonstrates that Visual Basic has placed quotes around the number:         24 "24"                       

Workaround
A workaround to this problem is to change the code that writes to the text file from: Write #1, rsInvoices!ProductID to: Write #1, rsInvoices!ProductID.value

Additional query words: kbdss kbDSupport kbVBp kbVBp500 kbVBp600 kbNoKeyWord

Keywords: kbprb KB193262

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.