Results 1 to 28 of 28

Thread: Textbox help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Textbox help

    Hi,

    well i got a textbox1, and multiline=1.

    i cant make this thing work..

    when i paste a text into the texbox to make automatically a new line for pasting...and not allowing to press enter...
    i m going crazy with this thing...

    and...1 more thing...textbox1 on multiline puts the pointer by default at a new line below the last text:

    text bla bla bla
    bliblibli
    blublublu
    | | this is where the pointer goes by default

    i cant make it go back...i mean i can with sendkeys {backspace}

    but i thiunk all would be solved not allowing enter to be pressed nad deleting the last empty line in the textbox..
    please any help?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Textbox help

    Welcome to the forums.

    To not allow the use of the Enter Key do this
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then KeyAscii = 0
    End Sub
    Beyond that I don't know what you are trying to do.

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    Welcome to vbforums

    can you explain me some more

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    thanks

    well...i just want when pasting into a text box a text to put every pasted text in a new line...and after pasting all....(lets say clicking a button) to remove last empy line) and not to permit pressing enter ( i dont know the chr for enter)

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Textbox help

    Quote Originally Posted by batori
    ...textbox1 on multiline puts the pointer by default at a new line below the last text:

    text bla bla bla
    bliblibli
    blublublu
    | | this is where the pointer goes by default.....:
    Pasting text into a multiline textbox does not put the pointer on a new line, but rather at the end of the last line so there is probably a blank line at the end of the data you are pasting.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Textbox help

    You can set the cursor position with the .SelStart and .SelLength properties of the trextbox control. To position it upon a paste operation you will have to subclass the textbox and watch for the WM_PASTE message and then make an additional call to set those properties after the paste operation message.
    Code:
    'Positions the cursor at the end of the text.
    Me.Text1.SelLength = 0
    Me.Text1.SelStart = Len(Me.Text1.Text)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    that did not work for me

    im trying now to implement pasting + vbcrlf i hope it will work.
    after that block the Enter char....

    any ideas how to do that?
    i know something about visual but not too much

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Textbox help

    I told you how to block the Enter Key in Post #2 (and that does work)

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    ups sorry...i had so many replies i didnt notice xD
    ok m8, ill test this soon...ill let u know

  10. #10
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    Pakistan
    Posts
    388

    Re: Textbox help

    If you want to clear out any trailing empty lines, this would do that:

    Code:
    Do While Right(Text1.Text,2) = vbNewLine
       Text1.Text = Left(Text1.Text, Len(Text1.Text) - 2)
    Loop

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    Quote Originally Posted by Hack
    Welcome to the forums.

    To not allow the use of the Enter Key do this
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then KeyAscii = 0
    End Sub
    Beyond that I don't know what you are trying to do.
    that's ok.i would like to put a new line after the pasted text...automatically...i tried with

    CODE]Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
    KeyAscii = 0
    else
    text1.text=split(text1.text,vbcrlf)
    End If

    End Sub[/CODE]

    that did not help

    now i got a problem that i can delete some lines and let them be empty and i dont want that i prevented that partially with the blocking of Enter...but i still can get emtpy lines between the text lines....

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    Quote Originally Posted by lone_REBEL
    If you want to clear out any trailing empty lines, this would do that:

    Code:
    Do While Right(Text1.Text,2) = vbNewLine
       Text1.Text = Left(Text1.Text, Len(Text1.Text) - 2)
    Loop
    this is working...
    thanks m8

  13. #13
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    Code:
    text1.text=split(text1.text,vbcrlf)
    Why are you using this for..???

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    naah..i dont use it..i tought it will work but i found out later it wont help
    now i got everything set....
    now i need to make this thing : when i keypress on text1 i need the text from clipboard and paste it in ( i know how to do that), but, after the paste i need a vbnewline automatically...i tried that with this

    Code:
    Text1.Text=Text1.text + vbnewline
    but this brings me to the first line and when i write i get the words in backward mode LOL

  15. #15
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    use like this:
    Code:
    Text1.SelStart = Len(Text1.Text)
    Text1.Text = Text1.Text & vbNewLine

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    Quote Originally Posted by akhileshbc
    use like this:
    Code:
    Text1.SelStart = Len(Text1.Text)
    Text1.Text = Text1.Text & vbNewLine
    not working as i tought...
    well it keeps making new lines but i get the pointer at position 0, and when i type i get the words in backwards in the first line only...
    i would need that when i paste the text, to go directly to a new line into i will paste again some text,and then again a new line automatically where ill put again pasted text....and so on...

  17. #17
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    what code do you have so far.????

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    i have many code...but i dont have any good code for this small operation...it seems complicated for that...

    ex:
    you staart with a blank textbox,you dont permit entering Enter, and everytime you paste a text CTRL+V your text is pasated on the first line and the pointer goeas automatically on the second line waiting for the next paste command...and them you paste again and the pointer goes automatically on the third line..i cant achieve that

    i tried the code i got here and the one i wrote..but they just kept making empty lines (which can be hanled by the code given up) but the problem is that everytime i write or paste my text goes in the first line

  19. #19
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    Something like this...????
    Code:
    Private Sub Text1_Change()
    Text1.SelStart = Len(Text1.Text)
    End Sub
    
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then KeyAscii = 0
    Text1.Text = Text1.Text & vbNewLine
    End Sub

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    thats nice but...

    i cant delete any line and when i paste in the first line the first line becomes empty...and the pasted textz goes to second line...

  21. #21
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    Oho, you want to replace each line when you paste. Is that so...?
    I will work on it and will soon reply(tomorrow), 'cause I am now on a trip to my homeland
    c u 2morrow

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  22. #22
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Textbox help

    What is in this text box anyway?

    I've never heard of anyone wanting to do the things to text in a textbox that you are doing.

  23. #23
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    After some experiments, I came up with this code...
    I don't have any idea... The below one will select the first line in a multiline textbox, when it gots the focus...
    I think others have good solutions than this...
    -Best wishes
    Code:
    Private Sub Text1_GotFocus()
    Text1.SelStart = 0
    Text1.SelLength = InStr(1, Text1.Text, vbNewLine)
    End Sub

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    ill try that now m8...

    @Hack
    well of course, i have strange idea coming to my mind

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    edit

    nope m8, i tried the last code and it seems to do nothing much...

    but,this code seems to be very useful, just when i paste in the first line i get the pasted text in the second line,that's the problem...
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then KeyAscii = 0
    Text1.Text = Text1.Text & vbNewLine
    End Sub

  26. #26
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Textbox help

    If we are able to find the cursor position, then it will be some more easy to solve the problem....

    @@@@To other members:
    Does anybody know how to find the position of the cursor in a textbox..???

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  27. #27
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Textbox help

    Quote Originally Posted by akhileshbc
    If we are able to find the cursor position, then it will be some more easy to solve the problem....

    @@@@To other members:
    Does anybody know how to find the position of the cursor in a textbox..???
    The cursor position is what you already knew and used: Text1.SelStart
    but you set it to a new value (Text1.SelStart = n) instead of read it (n = Text1.SelStart)
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  28. #28

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Textbox help

    this code seems to be easy but insted it's quite tricky xD

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