Array to a file (text) help needed please

s01655468

New member
Joined
Mar 19, 2003
Messages
3
Can anyone help me to convert this into vb.net, mine cant convert. Thank!
Or can someone know how to save the array to a file (text, ...what ever) and when the app start, read the file back into an array, and validate user inputs (example: login password)

Thank again in advance.
Code:
Option Explicit

Used for demonstration purposes only
Const sPassword As String = "pass1,pass2,pass3,pass4,pass5"

You password array
Private sPassArray() As String

Private Sub Form_Load()
   Populate the password array for demonstartion
   purposes only
   sPassArray = Split(sPassword, "," )
End Sub

Save the password list
Private Sub Command1_Click()
Dim lfn As Long
Dim sBuffer As String

   Join the array into a string buffer
   sBuffer = Join(sPassArray, "," )
   
   Get a free file number
   lfn = FreeFile()
   Open the file
   Open "c:\password.txt" For Binary Access Read Write Lock Read Write As lfn
   Write the string buffer to the file
   Put lfn, , sBuffer
   Close the file
   Close lfn
   
End Sub

Get the password list
Private Sub Command2_Click()
Dim lfn As Long
Dim sBuffer As String

   Get a free file number
   lfn = FreeFile()
   Open the file
   Open "c:\password.txt" For Binary Access Read Write Lock Read Write As lfn
      
   Initialise the string buffer
   sBuffer = String$(LOF(lfn), 0)
   
   Get the string buffer from the file
   Get lfn, , sBuffer
   Close the file
   Close lfn

   Split the sting buffer into the array
   sPassArray = Split(sBuffer, "," )

End Sub
[edit]added VB tags to make the code easier to read[/edit]
 
Last edited by a moderator:
.NET uses Streams now for reading and writing data to a file
I know this isnt what you are looking for but the concepts make what you are trying to do very easy and i beleive microsoft is trying to phase out the old sequential file access.
take some time and check it out i think you will be happy with the results

you may wish to do some research on Serialization. Serialization lets you write an object to a file. When you serialize an object it will take your object convert it to some jibberish put it in a file you choose and then you may retrieve that object by Deserializing it.
 
I try, but cant.
It does not read and compare the value in the TextBox1 and 2 to the text file at E:\text.txt.
Can help
==============================================
Code:
Dim sPassArray() As String
        Dim pass = TextBox1.Text
        Dim user = TextBox2.Text
        Dim eii As String
        Dim i As Integer
        Dim ei As String

        Dim sreader As IO.StreamReader
        sreader = IO.File.OpenText("E:\text.txt")
        ei = sreader.ReadToEnd
        sreader.Close()

        sPassArray = Split(eii, ",")

        For i = 0 To UBound(sPassArray) Step 2
            If sPassArray(i) = pass Then
                If sPassArray(i + 1) = user Then
                End If
            End If
        Next
 
Last edited by a moderator:
You have a type-o in your code.


ei = Io.File.OpenText("E:\text.txt")


I think it should be:

eii = Io.File.OpenText("E:\text.txt")
 
Back
Top