|
-
Nov 26th, 2000, 03:17 PM
#1
Thread Starter
Addicted Member
How do you write an array to a file?
-
Nov 26th, 2000, 03:38 PM
#2
Fanatic Member
Here is the easiest way to do it.....
Code:
Private Sub Form_Load()
Dim sArray(1 To 10) As String
Dim iCt As Integer
'Fill Array with random characters
For iCt = 1 To 10
sArray(iCt) = Chr(Rnd * 255)
Next iCt
'Open File to be written to
Open "C:\Array.txt" For Output As #1
For iCt = 1 To 10
' Write current array element to file
Write #1, sArray(iCt)
Next iCt
'Close File
Close #1
End Sub
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Nov 26th, 2000, 03:57 PM
#3
Monday Morning Lunatic
It might be a good idea to write the length of the array before it.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 26th, 2000, 04:26 PM
#4
Thread Starter
Addicted Member
Here's my Code.
Thank's YoungBuck for the idea of how to do it.
Public Key As Variant
Public ZipedText As String
Private Sub mnuOpen_Click()
Dim lenKey As Integer
FileName = ShowFileDialog(Me.hWnd)
Open FileName For Input As 1
Input #1, lenKey
ReDim Key(lenKey)
Do
r = r + 1
DoEvents
Input #1, Key(r)
If Key(r) = "End Array" Then
Exit Do
Else
End If
Loop
Do While Not EOF(1)
Input #1, zipedtxt
ZipedText = ZipedText + zipedtxt
Loop
Text1.text = unZip(ZipedText, Key)
Close
End Sub
Private Sub mnuSave_Click()
Key = Zip(Text1.text, ZipedText)
FileName = ShowFileDialog(Me.hWnd)
FileName = FileName & ".txt"
Open FileName For Output As 1
Write #1, UBound(Key)
For i = 1 To UBound(Key)
r = r + 1
If Key(r) = "" Then
Write #1, "End Array"
Exit For
End If
Write #1, Key(r)
Next
Write #1, ZipedText
Close
End Sub
-
Nov 26th, 2000, 07:26 PM
#5
transcendental analytic
arrays with fixed length data types are best stored binary, because it's fast and easy:
Code:
Dim IntegerArray(10) as integer
Dim DynamicLong() as long,length as byte'or use integer for room for larger arrays
Dim UDTarray(20) as UDTname
length=50
redim Dynamiclong(length-1)
'to write
open file for binary as 1
put #1,,IntegerArray
put #1,,length
put #1,,DynamicLong
put #1,,UDTarray
'to read
get #1,1,IntegerArray 'reset to start position
get #1,,length
redim Dynamiclong(length-1)
get #1,,Dynamiclong
get #1,,UDTarray
close 1
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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
|
Click Here to Expand Forum to Full Width
|