Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Can anyone help me to convert this into vb.net, mine can't 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.

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]

Edited by John
Posted

.NET uses Streams now for reading and writing data to a file

I know this isn't 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'm not lazy i'm just resting before i get tired.
Posted (edited)

I try, but can't.

It does not read and compare the value in the TextBox1 and 2 to the text file at E:\text.txt.

Can help

==============================================

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

Edited by divil
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...