Results 1 to 14 of 14

Threaded View

  1. #1
    Bombsaway707's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Gym
    Posts
    8,799
    Reputation
    791
    Thanks
    4,004
    My Mood
    Amused

    [Tutorial]Saving/Loading a Listbox Contents

    Ok guys so heres a short simple tutorial on how to Save/Load a listbox and its contents.
    1. Add a listbox to a form(obviously)
    2. Now under public class form 1 add this:
    Code:
    Inherits System.Windows.Forms.Form
    Dim w As IO.StreamWriter
        Dim r As IO.StreamReader
    3. Now to save a listbox contents use this code:
    Code:
    Dim i As Integer
            w = New IO.StreamWriter(Save Location Here. Save as .txt file)
            For i = 0 To ListBox1.Items.Count - 1
                w.WriteLine(ListBox1.Items.Item(i))
            Next
            w.Close()
    4. Now to load a listbox contents.
    Code:
    r = New IO.StreamReader("Load location here. must load from .txt file)
            While (r.Peek() > -1)
                ListBox1.Items.Add(r.ReadLine)
            End While
            r.Close()
    Its as simple as that.
    Now for a side note: You must save a listbox contents to a .txt file before you can load them. Also the save location should be as same as the save location.
    Now the entire code put together:
    Code:
    Public Class Form1
        Inherits System.Windows.Forms.Form
     Dim w As IO.StreamWriter
        Dim r As IO.StreamReader
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim i As Integer
            w = New IO.StreamWriter("c:\test.txt")
            For i = 0 To ListBox1.Items.Count - 1
                w.WriteLine(ListBox1.Items.Item(i))
            Next
            w.Close()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            r = New IO.StreamReader("c:\test.txt")
            While (r.Peek() > -1)
                ListBox1.Items.Add(r.ReadLine)
            End While
            r.Close()
        End Sub
    End Class
    Last edited by Bombsaway707; 02-23-2010 at 09:43 PM.

  2. The Following 6 Users Say Thank You to Bombsaway707 For This Useful Post:

    Blubb1337 (02-24-2010),hopefordope (02-25-2010),Lyoto Machida (02-16-2011),Tunguestenio (03-27-2011),XGelite (02-24-2010),___x][GooD. (01-20-2011)

Similar Threads

  1. Simple Save/Load
    By kotentopf in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 8
    Last Post: 10-07-2010, 02:10 PM
  2. [Injector] Pornject ++ Internet Stream ++ Save\Load [v3]
    By XxDragonSharKxX in forum CrossFire Spammers, Injectors and Multi Tools
    Replies: 6
    Last Post: 07-02-2010, 10:16 AM
  3. [Help] VB.NET 2008 - Saving ListBox Items in Settings
    By Samueldo in forum Visual Basic Programming
    Replies: 12
    Last Post: 03-17-2010, 09:14 PM
  4. [Tutorial]Saving Checkbox True/False Statement
    By Blubb1337 in forum Visual Basic Programming
    Replies: 11
    Last Post: 02-05-2010, 08:36 PM
  5. [Tutorial] New Way to make CA load faster
    By Andyklk2009 in forum Combat Arms Hacks & Cheats
    Replies: 13
    Last Post: 10-08-2008, 04:24 PM