|
-
Aug 21st, 2004, 10:41 AM
#1
Thread Starter
Junior Member
Display Listbox item's description in a Textbox [Resolved]
Hi all, I'm new to VB and this is my question:
I have a list box where the user select an item from the list box, and the description of the item will be display in a text box.
Different item will display different description in the same text box. How can I do this?
I've been trying by using this code:
VB Code:
Private Sub List1_Click()
Select Case List1.ListIndex
Case 0:
Text1.Text = "A Description"
Case 1:
Text1.Text = "B Description"
Case 2:
Text1.Text = "C Description"
End Select
End Sub
But the description is very long (more than hundreds words), I tried to store it in an access database, but failed because text size too large. Is it possible to save the description in a .txt file and load the description from that .txt file into the text box?
Thanks in advance!
Last edited by hbin; Aug 25th, 2004 at 10:59 AM.
-
Aug 21st, 2004, 10:57 AM
#2
What did you define the field in Access? Text? If you define it as Memo then you should not have any problem with the text size.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 22nd, 2004, 03:50 AM
#3
Thread Starter
Junior Member
Yeah, I previously defined the field as Text, now the text size problem solved after I defined it as Memo, thanks
I'm still having the problem to display the description of an item from a Listbox in the same Textbox. Since I stored the description in an access database, how do I let the user to randomly access to certain record (description) by selecting from the Listbox?
Thanks in advance! I hope I didn't confuse anyone over here :P
-
Aug 22nd, 2004, 04:20 AM
#4
You could always use a text file if you wanted. All you would have to do is seperate each "description" by a special character...
VB Code:
Dim desc() As String
Private Sub Form_Load()
Dim FF As Long
Dim myStr As String
FF = FreeFile()
Open "C:\test.txt" For Input As #FF
myStr = Input(LOF(FF), FF)
desc = Split(myStr, "{")
Close #FF
End Sub
Private Sub List1_Click()
Text1.Text = Replace(desc(List1.ListIndex), vbNewLine, "")
End Sub
Code:
//The TextFile
This is the description of the very first item in the list (ListIndex 0).
{
This is the second description of the second item (ListIndex 1).
{
blah blah blah..
{
Phreak
Last edited by «°°phReAk°°»; Aug 22nd, 2004 at 04:24 AM.
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Aug 22nd, 2004, 06:28 AM
#5
Thread Starter
Junior Member
Display Listbox item's description in a Textbox
Thanks Phreak, it works~! But the text shown up all in one paragraph even though it's originally divided in paragraphs in the text file. How can I make the text separated into paragraphs?
By the way, I changed the code
VB Code:
Open "C:\test.txt" For Input As #FF
to
VB Code:
Open "test.txt" For Input As #FF
in order the program to locate the file in the same folder as the project, and it works. Will this code still works when I converted my project into .exe file?
-
Aug 22nd, 2004, 07:00 AM
#6
AH, whoops, lol. This part:
VB Code:
Text1.Text = Replace(desc(List1.ListIndex), vbNewLine, "")
..removes the new lines. Which in turn, makes it all 1 line.
You can remove the "Replace" and just make it this:
VB Code:
Text1.Text = desc(List1.ListIndex)
I had the "Replace" because I didn't set the MutliLine property to true, and it showed squares for the Newline characters..
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Aug 22nd, 2004, 09:44 AM
#7
Thread Starter
Junior Member
Yup, it now can separate into paragraphs. 
BTW, I don't know why before this code can works but now it couldn't works
VB Code:
Open "test.txt" For Input As #FF
How should I write the code to make the program to locate the file in the same folder as the project, even when converted to .exe file?
PS: Can a .txt file store a large amount of text?
-
Aug 22nd, 2004, 09:53 AM
#8
PowerPoster
Suggest you do some reading on handling "sequential files"
FF is a supposed to be a file number. As I recall it is defined as an integer, and/or long. FF is a hex value so MOST likely if you want to use hex, you need to convert it to an integer or long
before using it as a file number. NEVER TRIED HEX AS A FILE NUMBER SO BEST GUESS RESPONSE.
---------------
How should I write the code to make the program to locate the file in the same folder as the project, even when converted to .exe file?
----------------
Put the folder/directory in front of your file name ----> "test.txt"
-----------
PS: Can a .txt file store a large amount of text?
-----------
Up to the size of the space available on your hard disk or
as I recall 4GB, whichever is smaller.
-
Aug 22nd, 2004, 10:24 AM
#9
Thread Starter
Junior Member
Put the folder/directory in front of your file name ----> "test.txt"
Yup, I did that before, eg: , but I wanted to make the program automatically locate this text file as long as it's in the same folder as the project; so the user can place the project & file in any folder or directory.
BTW, I was trying to let the user to print the description in the text box and it seems like can't print the text correctly and completly.
Here is what I wrote:
VB Code:
Private Sub cmdPrint_Click()
'Print the Description
Printer.Font.Name = "Times New Roman"
Printer.Font.Size = 11
Printer.Print Text1.Text
Printer.EndDoc
End Sub
-
Aug 22nd, 2004, 11:02 AM
#10
if you want to find the path your project is in then use
VB Code:
Open App.Path & "\test.txt" For Input As #1
is this what you are talking about ?
casey.
-
Aug 22nd, 2004, 11:13 AM
#11
Thread Starter
Junior Member
is this what you are talking about ?
VB Code:
Open App.Path & "\test.txt" For Input As #1
casey.
Yup, exactly Thanks.
-
Aug 22nd, 2004, 11:58 AM
#12
Thread Starter
Junior Member
Printting description of the Textbox
VB Code:
Private Sub cmdPrint_Click()
'Print the Description
Printer.Font.Name = "Times New Roman"
Printer.Font.Size = 11
Printer.Print Text1.Text
Printer.EndDoc
End Sub
I wrote these code to print the description in the text box and the output is like it can't print the text as what it shown in the text box or text file. Certain lines in a paragraph were skipped until a suppose to be long document (description) printed as short/uncompleted. Well, I'm not sure if it really "skipped" the lines in a paragraph or it can't wrap the lines to fit the page.
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
|