Solved

Save combobox entries to textfile

Posted on 2014-10-22
1
104 Views
Last Modified: 2014-10-23
I have a combobox that i want to save to a textfile when clicking a button, it should append all entries to a new line UNLESS it already exists. I have the below code, but it doesnt save, it doesnt do anything, but no errors.

   Dim content(TextBox1.Items.Count - 1) As String
        TextBox1.Items.CopyTo(content, 0)
        IO.File.WriteAllLines("C:\SWDEPOT\test.txt", content)

Open in new window


If a prepopulate the textfile with entries i am able to load it completely fine with the below code:

Dim load() As String = IO.File.ReadAllLines("C:\SWDEPOT\test.txt")
        Array.Reverse(load)
        TextBox1.Items.AddRange(load)

Open in new window

0
Comment
Question by:derek7467
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 40399767
Something like this should work:

    Const filePath As String = "C:\SWDEPOT\test.txt"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Adds new text
        If TextBox1.SelectedIndex = -1 AndAlso TextBox1.Text <> "" Then
            IO.File.AppendAllText(filePath, TextBox1.Text & vbNewLine)
        End If

        ' Clear previous information
        TextBox1.Items.Clear()

        ' Load the information from the text file
        Dim load() As String = IO.File.ReadAllLines(filePath)
        Array.Reverse(load)
        TextBox1.Items.AddRange(load)

    End Sub

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 11 hours left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question