Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual 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 ASP Free Forums Sponsor:
  #1  
Old October 7th, 2009, 08:17 AM
mien mien is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 9 mien User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 6 m 7 sec
Reputation Power: 0
Read and write to file using VB6

im trying to read array text from text file and write it to new file.but my code it not working..

Code:
    outfiledir = mstroutfil
    myfile2 = FreeFile
    If outfiledir = "" Then
    MsgBox "Please Select File ", Process File Error"
    GoTo 1
    End If

Open inpfiledir For Input As #myfile
    Do While Not EOF(myfile)
    Input #myfile, x, y, z
    
    xc = x
    yc = y
    zc = Round(-z, 2)
    Loop
Close #myfile
    
    
Open outfiledir For Output As #myfile2
    Do While Not EOF(myfile2)
    Write #myfile2, xc, yc, zc
    Loop
    Close #myfile2
1
End Sub

thanks...

Reply With Quote
  #2  
Old October 7th, 2009, 11:17 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,461 sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Day 16 h 50 m 26 sec
Reputation Power: 1806
Hi,

What happens wehen you run it, does it give you an error or does it just not run as expected. It would help us to understand what is going on if we could see a sample of your data.

If your file contains something like this:
1,1,1
2,2,2
3,3,3
4,4,4
5,5,5

you could try something like this:
Code:
Open inpfiledir For Input As #1
Dim oneline, arr1(), arr2(), arr3(), temp() As String
Dim tempCounter As Integer
tempCounter = 1
ReDim arr1(1)
ReDim arr2(1)
ReDim arr3(1)

'Read in data one line at a time, split the input into an array and write data to three arrays
While Not EOF(1)
    Line Input #1, oneline
    If InStr(oneline, ",") > 0 Then
        temp = Split(oneline, ",")
        If tempCounter > 2 Then
            ReDim Preserve arr1(UBound(arr1) + 1)
            ReDim Preserve arr2(UBound(arr2) + 1)
            ReDim Preserve arr3(UBound(arr3) + 1)
        End If
        
        arr1(tempCounter - 1) = temp(0)
        arr2(tempCounter - 1) = temp(1)
        arr3(tempCounter - 1) = temp(2)
        
        tempCounter = tempCounter + 1
    End If
Wend
Close #1

'Now write data out to new file
Open outfiledir For Output As #1

'loop through arrays writing data to new file
For tempCounter = 0 To UBound(arr1)
    Print #1, arr1(tempCounter) & "," & arr2(tempCounter) & "," & arr3(tempCounter)
Next
Close #1


'Or write it out backwards
Open outfiledir For Output As #1

For tempCounter = UBound(arr1) To 0 Step -1
    Print #1, arr1(tempCounter) & "," & arr2(tempCounter) & "," & arr3(tempCounter)
Next
Close #1

Hopefully this will give you an idea but if you need anything else you will have to give us a full description of teh problem and your data.
Comments on this post
mien agrees!

Reply With Quote
  #3  
Old October 9th, 2009, 01:50 AM
mien mien is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 9 mien User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 6 m 7 sec
Reputation Power: 0
thank u...it just what i need..thank you vary much

Reply With Quote
  #4  
Old October 9th, 2009, 03:59 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,461 sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Day 16 h 50 m 26 sec
Reputation Power: 1806
Quote:
Originally Posted by mien
thank u...it just what i need..thank you vary much
You're welcome, glad it helped!!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Read and write to file using VB6


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





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek