SunQuest
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old November 7th, 2003, 09:52 AM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
Write to a file in a certain format

Visual Basic 5.0

I write to a file and its output is as follow

"Some Text","A Date:",#2003-11-06#,"A number:",100

-----------------------------------------------

I would like to have a file output as below. The file below has
no double quotes around the data, and they are not separated
by a comma. Also, how do I write a blank line with a TAB on it ?

Code:
Some Text            <-- the data,  then a new line
     A Date:            <-- a TAB then the data,  then a new line
     2003-11-06      <-- a TAB then the data, then a new line
     A number:        <-- a TAB then the data, then a new line
     100                  <-- a TAB then the data,  then a new line

=================================
Code:
Private Sub Command1_Click()
    Dim strFile As String
    Dim Program_Name As String
    
    strFile = "C:\test5.txt"
    
    Call dhWriteAndInput(strFile)
End Sub


Private Sub dhWriteAndInput(strFile As String)
On Error GoTo ErrorHandler

    Dim hFile As Long
    ReDim varData(1 To 5) As Variant
    Dim i As Integer
    
    'Open a file for output, write to it and close it
    hFile = FreeFile
    
    Open strFile For Output Access Write As hFile
    Write #hFile, "Some Text", "A Date:", Date, "A number:", 100
    Close hFile
    
    'Now open it back up for reading
    hFile = FreeFile
    Open strFile For Input Access Read As hFile
    Input #hFile, varData(1), varData(2), varData(3), varData(4), varData(5)
    Close hFile

ErrorHandler:
    Select Case Err.Number  ' Evaluate error number.
        Case 53 ' "File NetManage.ini does not exist on C:\"
            MsgBox "File NetManage.ini does not exist on C:\"
        Case 55 ' "File already open" error.
            Close #1    ' Close open file.
        Case Else
            ' Handle other situations here...
    End Select

Resume Next
End Sub

Reply With Quote
  #2  
Old November 7th, 2003, 10:07 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
It is useful that some const strings represent TAB string and Enter string In Vb:VBTAB represents TAB,VBCRLF represents ENTER.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Write to a file in a certain format


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway