|
-
Sep 7th, 2007, 07:31 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Listboxes & Txt Files
Alright, I have a listbox,and I was wondering how to get it to load a txt document when a certain item is clicked, and display the text in a textbox, is that possible?
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 07:43 PM
#2
Re: Listboxes & Txt Files
..of course its possible.
A little more information would be helpful. What are the listbox items? 1 click or 2? How much experience do you have with VB?
The below will load a file into a textBox based on the filename in the listbox.
vb Code:
Private Sub ListBox_DblClick()
Open ListBox.List(ListBox.Index) For Input As #1
textBox.Text = Input(LOF(1), 1)
Close #1
End Sub
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 07:46 PM
#3
Thread Starter
Hyperactive Member
Re: Listboxes & Txt Files
Well, I have some good experience with vb6, but, I very, very rarely use listboxes, so... 2 click is what I need I think, but then how do I add the index for the list items?
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 07:47 PM
#4
Re: Listboxes & Txt Files
 Originally Posted by Bobalandi
Alright, I have a listbox,and I was wondering how to get it to load a txt document when a certain item is clicked,
What item?
To load a text file into a ListBox you need to use the Line Input Statement when reading the file and add that to the ListBox with AddItem.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Sep 7th, 2007, 07:51 PM
#5
Thread Starter
Hyperactive Member
Re: Listboxes & Txt Files
Sorry, I want the textbox to load a txt document when a certain listitem is clicked... sorry...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:12 PM
#6
Re: Listboxes & Txt Files
The code I gave you does that. It assumes that the list item is the direct path to the file.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 08:19 PM
#7
Thread Starter
Hyperactive Member
Re: Listboxes & Txt Files
but how do I edit it for each different item clicked?
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:35 PM
#8
Re: Listboxes & Txt Files
It already does that. The code I gave you loads in the file thats selected in the listbox.. no matter which one it is.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 08:37 PM
#9
Thread Starter
Hyperactive Member
Re: Listboxes & Txt Files
Wait, so I specify the file in the list box with the additem?
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:39 PM
#10
Re: Listboxes & Txt Files
Yes. As I said.. the code assumes the text in the listbox item, is a direct path to the file. For Example:
Code:
ListBox.AddItem "C:\file.txt"
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 08:41 PM
#11
Thread Starter
Hyperactive Member
Re: Listboxes & Txt Files
Ok, thank you very much, but can you just tell me one more thing, is there a way to show it as something like "Main" and the file url?
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:43 PM
#12
Re: Listboxes & Txt Files
Expand on that a bit more.. what do you want exactly? The listbox item to read "Main - C:\file.txt" ?
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 08:44 PM
#13
Thread Starter
Hyperactive Member
Re: Listboxes & Txt Files
No, I want it to read main, but the file be C:\file.txt
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 08:59 PM
#14
Re: Listboxes & Txt Files
You can either have a separate invisible listbox for the proper filenames, or use a string array. For example:
Code:
ListBox1.AddItem "C:\file.txt"
ListBox2.AddItem "Main"
Private Sub ListBox2_DblClick()
Open ListBox1.List(ListBox2.Index) For Input As #1
textBox.Text = Input(LOF(1), 1)
Close #1
End Sub
So, you click the visible listbox, but it loads the file thats in the invisible one.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 09:01 PM
#15
Thread Starter
Hyperactive Member
Re: Listboxes & Txt Files
Ok, thank you... I appreciate it...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 09:06 PM
#16
Thread Starter
Hyperactive Member
Re: [RESOLVED] Listboxes & Txt Files
Whoops, I just got an error, it says the object is not in an array... 
Code:
Open lstfiles.List(lsttopics.Index) For Input As #1
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Sep 7th, 2007, 10:20 PM
#17
Re: [RESOLVED] Listboxes & Txt Files
Do you have any items in your listbox when it reaches that code?
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 8th, 2007, 12:38 PM
#18
Thread Starter
Hyperactive Member
Re: [RESOLVED] Listboxes & Txt Files
Yup, I have 1 at the time...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|