PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Showing text in listbox and more...-VBForums
Page 1 of 2 12 LastLast
Results 1 to 40 of 46

Thread: [RESOLVED] Showing text in listbox and more...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Resolved [RESOLVED] Showing text in listbox and more...

    I have a .txt file that looks like this:

    nvm_:_nevermind
    np_:_no problem
    brb_:_be right back

    and so on...Anyways, I have a listbox that I want everything to the left of "_:_" to show up in, so the listbox would have data like this:

    nvm
    np
    brb

    And I have two textboxes. When you click on "np" in this case, I want text1.text to have np, and text2.text to show whats beside "_:_". So in text2.text it would have the text: no problem. If I edit the text in either text box, and click a command button (command1) I need it to save the changes in the .txt file that it gets the data from, so if I edited text1.text to "np1" and text2.text to "noproblem1", the text file would look like this:

    nvm_:_nevermind
    np1_:_noproblem1
    brb_:_be right back

    Anyways, how can I do this?
    Did you find a post in this thread useful? Please click Rate This Post.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    Post the code that is loading the listbox. It depends how you are storing it.
    You might have a problem, if you click on np and decide to make it brb, though
    You might want to have an add button, and a change button. (maybe even a delete button)
    Write the file when you hit the exit button.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    what do you mean?
    Did you find a post in this thread useful? Please click Rate This Post.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Oh, and I already have an add button, I just need to have a change and delete.
    Did you find a post in this thread useful? Please click Rate This Post.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Ok, I think I know what you mean. I'm using this code:

    VB Code:
    1. Dim Temp As String
    2. Open "C:\Definitions.txt" For Input As #1
    3. Do Until EOF(1)
    4. Line Input #1, Temp
    5. List1.AddItem Temp
    6. Loop
    7. Close #1

    To get the text from the .txt file into the listbox, but it shows everything, not just whats on the left side of the "_:_". How can I seperate it?
    Did you find a post in this thread useful? Please click Rate This Post.

  6. #6
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Showing text in listbox and more...

    VB Code:
    1. Option Explicit
    2. Dim SpltLine() As String, SpltEnter() As String
    3. Dim i As Integer, x As Integer
    4.  
    5. Private Sub Form_Load()
    6. Dim MyStr As String
    7.     Open App.Path & "\txtfile.txt" For Input As #1
    8.         MyStr = Input(LOF(1), 1)
    9.     Close #1
    10.     SpltEnter() = Split(MyStr, vbCrLf)
    11.         For i = 0 To UBound(SpltEnter)
    12.             SpltLine() = Split(SpltEnter(i), "_:_")
    13.                 List.AddItem SpltLine(0)
    14.         Next i
    15. End Sub
    16.  
    17. Private Sub List_Click()
    18. SpltLine() = Split(SpltEnter(List.ListIndex), "_:_")
    19. Text1.Text = SpltLine(0)
    20. text2.Text = SpltLine(1)
    21. End Sub

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    I would save the values to another array, say X.
    VB Code:
    1. DIM X() as string ' make this global to the form
    2. ' -------------
    3. Dim Temp As String
    4. dim str() as string
    5. Open "C:\Definitions.txt" For Input As #1
    6.   cnt=0
    7.   Do Until EOF(1)
    8.     redim preserve x(cnt,1) as string
    9.     Line Input #1, Temp
    10.     str() = split(Temp,"_:_")
    11.     List1.AddItem str(0)
    12.     X(cnt,0)=str(0)
    13.     X(cnt,1)=str(1)
    14.     cnt=cnt+1
    15.   Loop
    16. Close #1
    Last edited by dglienna; Aug 22nd, 2005 at 10:50 PM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Ok, so how do I make it so that when I click on "n2m" in the listbox, it puts n2m in text1.text, and nothing too much in text2.text?
    Did you find a post in this thread useful? Please click Rate This Post.

  9. #9
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Showing text in listbox and more...

    using the code i posted..

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    I forgot the second dimension.. I'll go back and correct the last post.

    in listbox1_click()
    VB Code:
    1. sub listbox1_click()
    2.   text1.text = X(List1.ListIndex,0)
    3.   text2.text = X(List1.ListIndex,1)
    4. end sub

  11. #11
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Showing text in listbox and more...

    I just dont get why no one is looking at mine..it works 100%

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Ok, I'm using this code:

    VB Code:
    1. Private Sub Form_Load()
    2. Dim X() As String ' make this global to the form
    3. ' -------------
    4. Dim Temp As String
    5. Dim str() As String
    6. Open "C:\Definitions.txt" For Input As #1
    7.   cnt = 0
    8.   Do Until EOF(1)
    9.     ReDim Preserve X(cnt, 1) As String
    10.     Line Input #1, Temp
    11.     str() = Split(Temp, "_:_")
    12.     List1.AddItem str(0)
    13.     X(cnt, 0) = str(0)
    14.     X(cnt, 1) = str(1)
    15.     cnt = cnt + 1
    16.   Loop
    17. Close #1
    18. End Sub
    19.  
    20. Private Sub List1_click()
    21.   Text1.Text = X(List1.ListIndex, 0)
    22.   Text2.Text = X(List1.ListIndex, 1)
    23. End Sub

    And, I get the error:

    Subscript out of range

    And it highglihts this code:

    VB Code:
    1. ReDim Preserve X(cnt, 1) As String

    Oh, and |2eM!x, I tried you're code, no errors, but when I clicked it, it didn't show in the textboxes for some reason.
    Did you find a post in this thread useful? Please click Rate This Post.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Nevermind |2eM!x, you're code worked great, I just missed one of the "List" text, I had to change them to List1, but I guess I didn't see one. Thanks, now, how would I be able to modify a text file, when the text in the textboxes are modified? I'm using |2eM!x's code, and also, how can I delete lines in the .txt file that I click?
    Did you find a post in this thread useful? Please click Rate This Post.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    I am getting an error, do you think that somone could show me what's wrong? I have the code in a timer, so that it always stays updated.

    EDIT: Project Files, and some text removed.
    Last edited by JBD2; Aug 24th, 2005 at 10:14 AM.
    Did you find a post in this thread useful? Please click Rate This Post.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    I really need help!
    Did you find a post in this thread useful? Please click Rate This Post.

  16. #16
    Addicted Member messup000's Avatar
    Join Date
    Jun 2005
    Posts
    181

    Re: Showing text in listbox and more...

    need some more info for the program to run. Like a definitions text file to help

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Obviously...Did anyone try it with the .txt file? I made it so of course I have the .txt file on my computer, but it's not hard to make one, anyways I've attatched the text file, hopefully someone can help with my problem. (Put the .txt file in C:\ Drive)
    Attached Files Attached Files
    Did you find a post in this thread useful? Please click Rate This Post.

  18. #18
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    Re: Showing text in listbox and more...

    change this
    Private Sub Timer1_Timer()
    VB Code:
    1. Dim MyStr As String
    2.     Open "C:\Definitions.txt" For Input As #1
    3.         MyStr = Input(LOF(1), 1)
    4.     Close #1
    5.     SpltEnter() = Split(MyStr, vbCrLf)
    6.         For i = 0 To UBound(SpltEnter)
    7.             SpltLine() = Split(SpltEnter(i), "_:_")
    8.                 List1.AddItem SpltLine(0)
    9.         Next i
    10. End Sub
    to this
    VB Code:
    1. Private Sub Timer1_Timer()
    2. Dim MyStr As String
    3.     Open "C:\Definitions.txt" For Input As #1
    4.         MyStr = Input(LOF(1), 1)
    5.     Close #1
    6.     SpltEnter() = Split(MyStr, vbCrLf)
    7.         For i = 0 To UBound(SpltEnter)-1 ' or check for spltenter(i)=""
    8.             SpltLine() = Split(SpltEnter(i), "_:_")
    9.                 List1.AddItem SpltLine(0)
    10.         Next i
    11. End Sub
    Last edited by JohnVB6; Aug 23rd, 2005 at 08:33 PM.
    Sometimes what you're looking for is exactly where you left it.

  19. #19
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    Re: Showing text in listbox and more...

    Another thing, running that code in a timer just keeps adding the same text
    to the list over and over...
    Sometimes what you're looking for is exactly where you left it.

  20. #20
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    Re: Showing text in listbox and more...

    Ok just after a quick check I modified this
    VB Code:
    1. Private Sub Image5_Click()
    2. Dim FF As Integer
    3.  
    4. FF = FreeFile
    5.  
    6. If Text1.Text = "" Or Text2.Text = "" Then 'change #1
    7.     MsgBox "No slang and/or replacement text typed.", vbExclamation, "EasyType Pro Alert"
    8. Else:
    9. Open "C:\Definitions.txt" For Append As #FF
    10.  Print #FF, Text1.Text & "_:_" & Text2.Text 'change #2
    11. Close #FF
    12. End If
    13.  
    14. Text1.Text = ""
    15. Text2.Text = ""
    16. End Sub

    The append statement automatically adds the text to the end of the file, so
    you don't need vbCrLf it was putting blank lines in your text file,
    which caused errors when splitting them.

    Instead of using the timer to load the text, load at start up and after
    additions, deletions or alterations, ie. when the user clicks those buttons, also
    you need to clear the text fields when the user clicks those buttons.

    By the way, I really like the look of your form nice job, perhaps you could give
    the user feedback though, when the image is clicked it should change a little
    so the user knows it was clicked.
    Last edited by JohnVB6; Aug 23rd, 2005 at 08:34 PM.
    Sometimes what you're looking for is exactly where you left it.

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Yeah, I was thinking of having so when you highlight the button, it lights up or something. Then when you hold the mouse down, it goes back to normal. Thanks for the help.
    Did you find a post in this thread useful? Please click Rate This Post.

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Ok, it works, but when I click on the new definition in the list after I add something, I get this error:

    Sub-script out of range

    And it highlights this line:

    VB Code:
    1. SpltLine() = Split(SpltEnter(List1.ListIndex), "_:_")

    In this code:

    VB Code:
    1. Private Sub List1_Click()
    2. SpltLine() = Split(SpltEnter(List1.ListIndex), "_:_")
    3. Text3.Text = SpltLine(0)
    4. Text4.Text = SpltLine(1)
    5. End Sub

    Also, how can I delete something by clicking the list, and then it deletes that line?
    Did you find a post in this thread useful? Please click Rate This Post.

  23. #23
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    Re: Showing text in listbox and more...

    you're probably trying to split a blank line, check the text file
    Sometimes what you're looking for is exactly where you left it.

  24. #24
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    Re: Showing text in listbox and more...

    SpltLine() = Split(SpltEnter(List1.ListIndex), "_:_")

    I just tried it with your code and I can add a new def. and then click the
    list and everything is fine. Did you make a change with the way you fill the
    list since the last time you uploaded the file?

    You're probably adding the new def. to the list before adding it
    to the text file, so when you search the text file with the new index
    it doesn't exist.
    Last edited by JohnVB6; Aug 23rd, 2005 at 11:04 PM.
    Sometimes what you're looking for is exactly where you left it.

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    I'm kind of confused on what you mean.
    Last edited by JBD2; Aug 26th, 2005 at 09:28 AM.
    Did you find a post in this thread useful? Please click Rate This Post.

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Anybody?
    Did you find a post in this thread useful? Please click Rate This Post.

  27. #27
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    I've made two changes:
    First thing is that you weren't clearing out the list each time you loaded it.
    Also, instead of specifying where the definition file was, I just used app.path in all three places. Also, if you use Option Explicit, you would have seen that Xfrm needed to be declared AS FORM.

    VB Code:
    1. 'Reload the list
    2. List1.Clear
    3. Dim MyStr As String
    4.     Open App.Path & "\Definitions.txt" For Input As #1

    To delete, as long as you have them all in memory, you can write out the file in order, but skip the one that you want to delete, and then read it in again.
    When you modify something, you still have to re-write the whole array of items.
    Instead of using APPEND, to erase the old one, use OUTPUT.

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Thanks dglienna. I'll try and work on the delete thing, but If I need help I'll let you know.
    Did you find a post in this thread useful? Please click Rate This Post.

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    To delete, as long as you have them all in memory, you can write out the file in order, but skip the one that you want to delete, and then read it in again.
    When you modify something, you still have to re-write the whole array of items.
    Instead of using APPEND, to erase the old one, use OUTPUT.
    Do you think you could give me a code example to start? I'll try and work from there.
    Did you find a post in this thread useful? Please click Rate This Post.

  30. #30

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    I think all I need help with is just skipping the clicked line...I'm pretty sure I know how to do everything else.
    Did you find a post in this thread useful? Please click Rate This Post.

  31. #31
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    I assume that you select a phrase from the list, and then click delete.
    Just loop through, checking for the listindex, it it's the same, don't write the line
    VB Code:
    1. for x=0 to list1.listcount
    2.   if x <> list1.listindex then
    3.      ' write line to new file
    4.   endif
    5. next x

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Ok, I'm wondering though, what I need to do is check for the listindex using the code above right, and then I need to make a new .txt file with everything except the listindex in it right, then replace the old .txt file? Am I right, or what do I need to do (just outline it, but a little more detailed if I'm wrong) Thanks.
    Did you find a post in this thread useful? Please click Rate This Post.

  33. #33
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    That's right. Just create a temp file, then delete the temp file, and use NAME to replace the original..

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. ' create test.txt (the original file)
    5.   Open "d:\temp.txt" For Output As #1
    6.     Print #1, "temp"
    7.   Close #1
    8.   Kill "d:\test.txt"
    9.   Name "d:\temp.txt" As "d:\test.txt"
    10. End Sub

    Incidentally, if you allow multiselections in the listbox, then you can check to see if list1.selected(x)=true, and if it is, you can delete more than one item at a time.

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    Oh ok thanks!
    Did you find a post in this thread useful? Please click Rate This Post.

  35. #35

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    So I'm going to have to save the text in the .txt file as a string variable right but exclude the listindex thing...How would I do this?
    Did you find a post in this thread useful? Please click Rate This Post.

  36. #36
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    To get text out of the listbox, use
    VB Code:
    1. print #ff, List1.list(x)

    But, I thought you were using arrays. I would print the two sides with something unusual between them, like you have.
    VB Code:
    1. print #ff, arr(x,0) & "_:_" & arr(x,1)
    Last edited by dglienna; Aug 25th, 2005 at 05:26 PM.

  37. #37

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    I'm confused, did you look at the project files to see what I'm using?
    Did you find a post in this thread useful? Please click Rate This Post.

  38. #38
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    Re: Showing text in listbox and more...

    I think to keep things simple, you should only save the changes when the form closes or the user closes the modification side of the form. Load the list only at startup, then use the list's items only, if 1 is deleted then removeitem from the list, if 1 is added then add item to the list, if 1 is changed then change it in the list, ie:

    VB Code:
    1. Private Sub cmd1_Click()
    2. Dim OldIndex As Long
    3.  
    4.   OldIndex = lis1.ListIndex
    5. 'this will replace the item and keep it in the same place in the list
    6.   lis1.RemoveItem lis1.ListIndex
    7.   lis1.AddItem "Changed", OldIndex 'substitute changes with new text
    8.    
    9. End Sub

    Then when the form is closed delete the old txt file and save the listbox
    contents (and it's counterpart stored in the array) as the new file. Or just overwrite the old, but I like to Kill it just
    to be sure there isn't residule garbage left behind.
    Sometimes what you're looking for is exactly where you left it.

  39. #39

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Showing text in listbox and more...

    But the thing is, I want to be able to modify the .txt file, then continue using the plug-in, so that when "on" is pushed, they can still use thet plug-in with the latest modifications to the .txt file...So how would I delete something like that?
    Did you find a post in this thread useful? Please click Rate This Post.

  40. #40
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Showing text in listbox and more...

    Just re-save the text file with the Modify button

    VB Code:
    1. Open App.Path & "\Definitions.txt" For Output as #1
    2.   For i = 0 To UBound(SpltEnter) - 1
    3.     print #1, SpltEnter(i)
    4.   Next i
    5.   close #1

    To delete an entry, add the code to check for the listindex, rewrite and then read the file into the listbox. The deleted item won't be there.

    Note: I don't know how your app works, but I would think that you'd want to have each half in memory so you can check for the shortcut. Also, you should name your buttons so that I know which is which. Image1 should be imgDelete, or whatever it is.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width