s01655468 Posted March 19, 2003 Posted March 19, 2003 (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 March 19, 2003 by John Quote
bpayne111 Posted March 19, 2003 Posted March 19, 2003 .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. Quote i'm not lazy i'm just resting before i get tired.
s01655468 Posted March 19, 2003 Author Posted March 19, 2003 (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 March 20, 2003 by divil Quote
tcomputerchip Posted April 1, 2003 Posted April 1, 2003 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") Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.