Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,458 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,870 people online right now. Registration is fast and FREE... Join Now!




Load text file into ListBox

 
Reply to this topicStart new topic

Load text file into ListBox, VB Project

Arny101
30 Jul, 2008 - 08:05 AM
Post #1

New D.I.C Head
*

Joined: 14 Mar, 2008
Posts: 6

Hi my names Arny,

ok i have been doing this project for the last 3 months and i am stil so lost.... its due tomorrow.
ive read the text book so many times and it still wont help
i need some help badly!!!
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Load Text File Into ListBox
30 Jul, 2008 - 08:11 AM
Post #2

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
You shouldn't have waited until the last minute to get help. Honestly if you were given three whole months to complete this project, then it's likely that you will not have it finished by tomorrow. Still, we'll help if we can.

You did not mention at all what your project is and what exactly you couldn't figure out. Please post again, but this time with the details of your project, the source code you're currently using, and explain what you need help with.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Load Text File Into ListBox
30 Jul, 2008 - 08:11 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

Arny101
RE: Load Text File Into ListBox
30 Jul, 2008 - 08:27 AM
Post #4

New D.I.C Head
*

Joined: 14 Mar, 2008
Posts: 6

Wow thanks, you guys are really fast lol.
um i have two forms. the second form is the information where you write it down and then it saves to a text file.
the first form is the one that im having problems with.
1) i have a lstbox that i want to upload the data saved on the text file, but it just wont work.
CODE

'load the contents of listitems.txt into lstItems
        Call LoadListFromFile(Application.Path & "\Stock.txt", lstProducts)

        On Error GoTo ErrEvt
        Dim TextLine As String, FN As Integer
        Dim ProductList As String
        Dim SourceFile As String
        ProductList = lstProducts.Text
        SourceFile = "Stock.Text"

        FN = FreeFile()
Open SourceFile For Input As #FN ' Open file.
        Do While Not EOF(FN) ' Loop until end of file.
   Line Input #FN, TextLine ' Read line into variable.
            If TextLine <> LineToRem Then
                ProductList.AddItem(TextLine)
            End If
        Loop
        Close(FN) ' Close file.

        Exit Sub 'this error handler will skip the nasty problem
        'if your text file isnt conformed with an extra linebreak at the end
        'to avoid saying INPUT PAST EOF
ErrEvt:
        Select Case Err.Number
            Case 51
                Err.Clear() ' just bail out from this
            Case Else ' do nothing
        End Select
        Resume Next


im completely lost
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Load Text File Into ListBox
30 Jul, 2008 - 08:35 AM
Post #5

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
I have some questions before I start trying to give corrections. What does the "LoadListFromFile" sub do? Isn't that what you're doing just below it? Can you show me the contents of that sub?

Where did you declare LineToRem, and what value does it hold?

CODE
If TextLine <> LineToRem Then
    ProductList.AddItem(TextLine)
End If


User is offlineProfile CardPM
+Quote Post

Arny101
RE: Load Text File Into ListBox
30 Jul, 2008 - 08:41 AM
Post #6

New D.I.C Head
*

Joined: 14 Mar, 2008
Posts: 6

Hey Zhalix, Im Arny Thanks for your help.

um well to tell you the truth i dont know what i am doing, ive looked at the text box and tried to pull things out of it that would help me get the function i needed. but i think i just failed at it.

CODE

Private Sub lstproducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstProducts.SelectedIndexChanged
        'load the contents of listitems.txt into lstItems
        Call LoadListFromFile(Application.Path & "\Stock.txt", lstProducts)

        On Error GoTo ErrEvt
        Dim TextLine As String, FN As Integer
        Dim ProductList As String
        Dim SourceFile As String
        ProductList = lstProducts.Text
        SourceFile = "Stock.Text"

        FN = FreeFile()
Open SourceFile For Input As #FN ' Open file.
        Do While Not EOF(FN) ' Loop until end of file.
   Line Input #FN, TextLine ' Read line into variable.
            If TextLine <> LineToRem Then
                ProductList.AddItem(TextLine)
            End If
        Loop
        Close(FN) ' Close file.

        Exit Sub 'this error handler will skip the nasty problem
        'if your text file isnt conformed with an extra linebreak at the end
        'to avoid saying INPUT PAST EOF
ErrEvt:
        Select Case Err.Number
            Case 51
                Err.Clear() ' just bail out from this
            Case Else ' do nothing
        End Select
        Resume Next
    End Sub


i think i might just delete it all and try and see if i can understand and get it... but i am failing hard.
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Load Text File Into ListBox
30 Jul, 2008 - 08:45 AM
Post #7

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
Seems like you're using VB.Net. I don't know VB.Net at all so I probably can't help any. Though it looks like you're using a lot of VB 6 syntax that I wouldn't think would be in place in .Net. Maybe that's part of your problem. Anyway, I hope you get the help you need.
User is offlineProfile CardPM
+Quote Post

Arny101
RE: Load Text File Into ListBox
30 Jul, 2008 - 08:47 AM
Post #8

New D.I.C Head
*

Joined: 14 Mar, 2008
Posts: 6

oh ok my bad, sorry,
well thanks for the help again mate
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Load Text File Into ListBox
30 Jul, 2008 - 09:35 AM
Post #9

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,941



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Topic renamed to be more descriptive.
User is offlineProfile CardPM
+Quote Post

Arny101
RE: Load Text File Into ListBox
30 Jul, 2008 - 09:39 AM
Post #10

New D.I.C Head
*

Joined: 14 Mar, 2008
Posts: 6

Cool Thanks.

im still so lost about what i am doing on here
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:45PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month