VB 2008; How to add text from text file to combobox menu

Shout-Out

User Tag List

Results 1 to 10 of 10
  1. #1
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    VB 2008; How to add text from text file to combobox

    Hello everyone. I was wondering how i can have a saved log (for bookmarks for a web browser) in the form of a txt file be added to a combo box. Aka, i have a txt file that stores the saved bookmarks, and i want them to be uploaded to a combo box when the form loads. Here is the code so far;

    CType(tabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("Google.com")
    Dim sFileName As String = "C:\Stealth Browser\bookmarks.txt"
    Dim myFileStream As New System.IO.FileStream(sFileName, _
    FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
    Dim myReader As New System.IO.StreamReader(myFileStream)
    Dim sFileContents As String = myReader.ReadToEnd()
    ComboBox1.Text = sFileContents
    myReader.Close()
    myFileStream.Close()

    What this does wrong, is it only uploads the last line of the txt file. How do i add every line as a separate item in the collections of the combo box? Thanks in advanced.

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

    VB 2008; How to add text from text file to combobox
  2. #2
    maclone's Avatar / Authenticator enabled
    Reputation
    2420
    Join Date
    Nov 2007
    Posts
    8,726
    Thanks G/R
    0/1029
    Trade Feedback
    0 (0%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Going the hard way...
    Code:
            If File.Exists("C:\Stealth Browser\bookmarks.txt") Then
                Dim fileSR As New StreamReader("C:\Stealth Browser\bookmarks.txt")
                Do Until fileSR.EndOfStream
                    ComboBox1.Items.Add(fileSR.ReadLine())
                Loop
                fileSR.Close()
            Else
                MessageBox.Show("The file doesn't exist.")
            End If
    Last edited by maclone; 07-13-2009 at 08:20 PM.
    Zomfg. And no, don't ask. - Dombo did it.

  3. #3
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright. now im having trouble adding things to this txt file.

    I have a listbox, a textbox, and two buttons. button 1 is the add button. it adds the textbox1.text to the listbox. Then the other button saves the selected item in the listbox to the txt file. How do you think i could do this effectively? Heres my code for the save button;

    Dim sFileName As String = "C:\Stealth Browser\bookmarks.txt"
    Dim myFileStream As New System.IO.FileStream(sFileName, _
    FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)

    Dim myWriter As New System.IO.StreamWriter(myFileStream)

    myWriter.WriteLine(ListBox1.Text)

    myWriter.Flush()

    myWriter.Close()
    myFileStream.Close()
    Form1.ComboBox1.Items.Add(ListBox1.Text)

    Thanks in advanced.

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

  4. #4
    maclone's Avatar / Authenticator enabled
    Reputation
    2420
    Join Date
    Nov 2007
    Posts
    8,726
    Thanks G/R
    0/1029
    Trade Feedback
    0 (0%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Dim fileWR As New StreamWriter("C:\Stealth Browser\bookmarks.txt", True)
    fileWR.WriteLine(ListBox1.SelectedItem)
    fileWR.Close()
    Last edited by maclone; 07-13-2009 at 08:36 PM.
    Zomfg. And no, don't ask. - Dombo did it.

  5. #5
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet. Works fine. Thanks. Also, is it possible to remove a line of a txt file?

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

  6. #6
    maclone's Avatar / Authenticator enabled
    Reputation
    2420
    Join Date
    Nov 2007
    Posts
    8,726
    Thanks G/R
    0/1029
    Trade Feedback
    0 (0%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Dim fileSR As New StreamReader("D:\bookmarks.txt")
    Dim tempText As String = fileSR.ReadToEnd
    fileSR.Close()
    Dim fileWR As New StreamWriter("D:\bookmarks.txt")
    fileWR.Write(tempText.Replace(vbCrLf & ListBox1.SelectedItem, Nothing))
    fileWR.Close()
    It works, but if you got 2 items like:
    123abclol
    123abc
    and you want to remove '123abc', the other item will be edited to 'lol'.

    And to fix that you'll need to find your own way, so I didn't code everything you need for your browser.
    Last edited by maclone; 07-13-2009 at 10:17 PM.
    Zomfg. And no, don't ask. - Dombo did it.

  7. #7
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your time. Im deciding to just kill the file then recreate it then put the combobox items into the file.

    Trust me, you are not even close to writing the whole web browser. :] just the part i was unfamiliar with.

    Now time to be Hippocratic. Do you know how i would go about checking if a directory exists, then if it doesnt, create the folder and the file.

    Thanks again for your time. I really appreciate it.

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

  8. #8
    The Maffyx's Avatar Contributor

    Reputation
    249
    Join Date
    Feb 2007
    Posts
    1,186
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this make sure to put this in the imports if it isnt there already:

    imports System.IO

    then put this where you need it:

    Code:
    If Not Directory.Exists(Path) then
      Directory.CreateDirectory(Path)
    End If


  9. #9
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. i forgot to say that i figured this thing out but thanks anyway :]

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

  10. #10
    The Maffyx's Avatar Contributor

    Reputation
    249
    Join Date
    Feb 2007
    Posts
    1,186
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Np, and that's good to hear ^_^


Similar Threads

  1. Replies: 5
    Last Post: 02-02-2009, 11:14 AM
  2. How to add a weapon from wow-v [ASCENT]
    By brandonrulz1 in forum WoW EMU Guides & Tutorials
    Replies: 2
    Last Post: 11-28-2008, 05:00 PM
  3. how to import a text file?
    By lethalllama in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 08-23-2008, 03:44 AM
  4. how to change a text file for a itmem to a sql file
    By lolzz in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 06-12-2008, 01:18 AM
  5. how to change text color?
    By L'Lawliet in forum World of Warcraft General
    Replies: 12
    Last Post: 11-04-2007, 02:44 PM
All times are GMT -5. The time now is 06:09 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search