|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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... |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
thank u...it just what i need..thank you vary much
|
|
#4
|
||||
|
||||
|
Quote:
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Read and write to file using VB6 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|