Hey guys,
Once again i need help and this time i have no idea how to do it. I would love it if someone could help me out here =) . Basically what i want to do is open a txt file using openfiledialog which i have set out and using seperators to assign them into listbox1 and listbox 2.

I think you may have to use regex for this but I am not sure how I can do this. I want one of the sides to show the gmail account names () and the other side to show the password which are both being grabbed from the txt file. E.g
The text file list will be like this -
:password
:password.
I want all the gmail accounts to go to list box 1 and all the passwords to goto list box 2. the ":" should act as a seperator but i donot know how to do this.

Thanks in advance. Any responses will be highly appreciated.

Dani AI

Generated

asked how to load account/credential pairs from a text file into two ListBoxes; was right that splitting each line is the simplest approach. The code below shows a robust, practical VB.NET WinForms pattern: use an OpenFileDialog, stream the file line by line, split only on the first colon (so passwords that contain a colon are preserved), trim values, and add them to ListBox1 and ListBox2 in lockstep.

' Put this on a button click handler
Dim ofd As New OpenFileDialog()
ofd.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
If ofd.ShowDialog() <> DialogResult.OK Then Return

Try
    ListBox1.Items.Clear()
    ListBox2.Items.Clear()
    For Each line As String In System.IO.File.ReadLines(ofd.FileName)
        If String.IsNullOrWhiteSpace(line) Then Continue For
        Dim parts As String() = line.Split(New Char() {":"c}, 2)
        If parts.Length < 2 Then Continue For
        ListBox1.Items.Add(parts(0).Trim())
        ListBox2.Items.Add(parts(1).Trim())
    Next
Catch ex As Exception
    MessageBox.Show("Error reading file: " & ex.Message)
End Try

Notes and troubleshooting: use File.ReadLines to avoid loading very large files into memory; Split with a count of 2 keeps anything after the first colon as the password; trim each part to remove stray spaces; skip or log malformed lines if parts.Length < 2. If the file uses a nonstandard encoding, use the overloads that accept an Encoding. Keep the two ListBoxes synchronized by always adding both items together; if you need richer UI or editing, bind a small list of objects (account/password) to a grid instead. For security, never store or transmit real passwords in plaintext in production.

Microsoft docs: OpenFileDialog and File.ReadLines are documented at the Microsoft Learn site for reference.

Recommended Answers

All 2 Replies

Open a text file, read it line by line, split each line with ":" delimiter character.

Hey man ,
Thanks for that but i cannot seem to code it. Could you please give some examples to help me out. Thank you so much

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.