hey everybody! :D
I am a major noob at programming and I am using VB '08 Express and want to use a text file to set variables on seperate forms of one program. What I would like to know is if i should use seperate files for each form and how to structure the text file and load it into seperate variables.

Example:
(text file)
User1 Info1, User1 Info2, User1 Info3, User1 Info4, etc.
User2 Info1, User2 Info2, User2 Info3, User2 Info4, etc.

(form code)
User1 Info1 = value1
User2 Info1 = value2
etc.


Is this even possible in VB? I have been reading posts for two days and it looks like its possible but not easy.

Any help is MUCH appreciated..
Blackknight

P.S. everything else is working good... just want this so i can edit the login without recoding.

Dani AI

Generated

Good start, — reading the file is the first step. For , the simplest, maintainable pattern is: treat each comma line as a record, parse it into a small data object, keep a single loader routine that returns a collection of records, and let each form pick the record(s) it needs. That way you can edit the text file without touching form code.

A minimal VB pattern (illustrative) — define a record type, load lines, split into fields, and return a List(Of T):

Public Class UserRecord
    Public Property Name As String
    Public Property Info1 As String
    Public Property Info2 As String
End Class

Public Function LoadUsers(path As String) As List(Of UserRecord)
    Dim lines = System.IO.File.ReadAllLines(path)
    Dim list As New List(Of UserRecord)
    For Each line In lines
        If String.IsNullOrWhiteSpace(line) Then Continue For
        Dim f = line.Split(","c).Select(Function(s) s.Trim()).ToArray()
        list.Add(New UserRecord With {.Name = f(0), .Info1 = If(f.Length>1,"",f(1)), .Info2 = If(f.Length>2,"",f(2))})
    Next
    Return list
End Function

Practical tips: store the file in a known location (Application.StartupPath or AppData) and handle IO exceptions. If fields can contain commas, use TextFieldParser for robust CSV parsing. Never keep real passwords in plain text — use app settings or proper hashing if authentication is required.

References for follow-up: File.ReadAllLines for simple file reading (docs) and TextFieldParser for CSV with quotes (docs). For per-user or per-app settings consider the Visual Basic application settings guidance ().

Recommended Answers

All 2 Replies

I think it's possible to take values from file.TXT
btw, i'm using VB 2005, i don't know it is work for vb 2008 or not.

I take value per line from file.txt using an arraylist.

dim array as new arraylist

'open file.txt n allow file.txt to be read
dim file as new filestream ("[your file address], filemode.open, fileaccess.read")

'reading file.txt
dim sr as streamreader(file)

'inserting file.txt value to an array
while (sr.peek > -1)
      array.add (sr.readline)       'read value per line 
end while

'don't forget close the file.txt 
sr.close
file.close

'see file.txt value 1st line
msgbox(array(0))

for example:
file.txt calling value
line 1 : info1 array(0)
line 2 : info2 array(1)


i hope this help U...

hey thanks this i what i was looking for..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.