Results 1 to 8 of 8

Thread: Problem concatenating text in textbox

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Problem concatenating text in textbox

    I have a really strange problem.
    I have a textbox "myTextbox" and a listbox "myList" which shows a list of strings e.g "AAA", "BBB", "CCCC".

    When the user clicks on an item from the listbox the text must be appended to the end of whatever is in myTextbox with a space preceeding it. e.g " AAA".

    The user must never be allowed to delete the added text.

    The user must be allowed to manually enter text in the textbox but it must always be in front of the added text.

    They must never be allowed to type over the added text or after the added text.


    I have been trying to get my head around this for a day now and cannot figure it out.
    Can anyone point me in the right direction?
    Has anyone had a similar request to deal with?

    Thanks in advance

    Parksie

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Problem concatenating text in textbox

    Why does the text from the ListBox have to be added to the same TextBox the user is editing? A String is a String. Just use two TextBoxes with the second being read-only or use a Label instead. You can then just join the Text from the two controls in code when you're done.

    Alternatively, you could probably use a MaskedTextBox and continually change the Mask as the user types. The data from the ListBox would be literal characters forming part of the mask.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Problem concatenating text in textbox

    Quote Originally Posted by venerable bede View Post
    I have a really strange problem.
    I have a textbox "myTextbox" and a listbox "myList" which shows a list of strings e.g "AAA", "BBB", "CCCC".

    When the user clicks on an item from the listbox the text must be appended to the end of whatever is in myTextbox with a space preceeding it. e.g " AAA".
    Until here everything was easy, using "MyTextbox.text = MyTextBox.text & " " & myList.List(myList.ListIndex)" in the _click event of the ListBox should do the trick.
    Quote Originally Posted by venerable bede View Post
    The user must never be allowed to delete the added text.

    The user must be allowed to manually enter text in the textbox but it must always be in front of the added text.

    They must never be allowed to type over the added text or after the added text.
    these parts make the problem, I wouldn't use a textbox for that, since you would have to manually "disable" most of the features of a textbox!. Why not use a Label. The only problem remaining would be the "The user must be allowed to manually enter text in the textbox but it must always be in front of the added text." I'd use another textbox for that.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  4. #4

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Problem concatenating text in textbox

    Thanks for the replys but unfortunatly I must use a single textbox. It's in my spec and I have no choice in the matter.

    Now you know why I am pulling my hair out.
    It seems easy on the surface but it is far from it.

    Parksie

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem concatenating text in textbox

    Just out of curiosity, who wrote the spec? An applications designer/architect (ie, a fellow geek) or the business analyst?

    I'm hoping that it was the BA that wrote that spec. And the truth is, they have no business writing that kind of specification. BA's should be writing specs that say WHAT the system needs to do ("system needs to have the ability to enter information....") but not HOW it should be done ("entry will use a text box with the following restrictions").

    If it was written by technical person then.... *cue the rolling of the eyes*

    Last thing to note - is your shop so inflexible that you can't take it back to the person that wrote the spec and explain "Hey this isn't going to work, here's why... X, Y, Z. I think we should to it this way instead A, B, C."

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Problem concatenating text in textbox

    You are correct.

    It was not written by a developer.
    The general rule is "If it is possible (which in this case it is) it does not matter how difficult it is. It must be done".

    It is a pain in the backside.
    I knew I should have been a hairdresser.
    Last edited by venerable bede; Feb 14th, 2011 at 08:36 AM.

    Parksie

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem concatenating text in textbox

    Except what's possible and what isn't shouldn't be left up to the non-technical. It's possible that I could swell up like a giant blueberry... doesn't mean I want it written out in a spec.

    That's the kind of spec I kick back for re-write or removal. It doesn't belong.

    Layer two textboxes, modify their borders so they look like one... embed them into a picture box so you get a border.... make the one text box readonly.... you could also then make it a user control... make it act and look like one text box.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Problem concatenating text in textbox

    I knew this would stump you guys.
    I've been looking at it for an age and I'm pulling my hair out.

    Parksie

Posting Permissions

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



Click Here to Expand Forum to Full Width