?
Solved

move to next line in text box vb6

Posted on 2014-01-30
13
Medium Priority
?
2,619 Views
Last Modified: 2014-02-03
I have a text box in vb6 and I set the multiline property to true.  When I type a sentence in the textbox and then want to go to a new line, how is that possible?  It seems that I have to press spacebar until I get to the next line.
0
Comment
Question by:al4629740
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 10

Expert Comment

by:Korbus
ID: 39821703
What does the "enter" key do?  Take you to the next field?
Usually, the enter key should take you to the next line (in a multi-line enabled text box).
0
 

Author Comment

by:al4629740
ID: 39821741
Ahh,

I have the default set on a command button within the same screen.  I guess the two cannot coexist...
0
 
LVL 10

Expert Comment

by:Korbus
ID: 39821754
No way, that would be awful!  I'm going to test that right now myself, I'll let you know if I get the same.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:Korbus
ID: 39821782
Confirmed:  With "Accept Button" specified in the form properties, the enter key no longer works in the multi-line text box.   Pretty poor IMO.

Here is a possible workaround (untested):
In the text box's "gotfocus" event: you can change the accept button on the form properties to nothing,  then on "lostfocus", change the form's accept button property back to  your button.

(Pretty sure I used the wrong names for those focus events, but hopefully you see what I mean.)
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39821790
If you want to type in a new line you could just add a command button with this code.

Text1.Text = Text1.Text & vbCrLf

If instead you want to continue the current line then do this

Text1.SelStart = Len(Text1.Text)
0
 

Author Comment

by:al4629740
ID: 39821825
Boy.  Seems like an extra annoying step...

Thanks guys
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39821855
In defense of VB6, it really doesn't know that you want to add a new line rather than adding something at the start or the middle.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39822185
You say 'sentence', so how does this suit?
Option Explicit

Private Sub Text1_Change()
    Select Case Right(Text1.Text, 1)
        Case ".", "!", "?"
            Text1.Text = Text1.Text & vbCrLf
            Text1.SelStart = Len(Text1.Text)
    End Select
End Sub

Open in new window

0
 

Author Comment

by:al4629740
ID: 39822443
Graham

That's a great solution but a little too specific to punctuation
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39822601
How about this?

Private Sub Text1_LostFocus()
If Right(Text1.Text, 2) = vbCrLf Then
    Exit Sub
Else
    Text1.Text = Text1.Text & vbCrLf
End If
End Sub

Open in new window

0
 
LVL 28

Expert Comment

by:Ark
ID: 39822947
Assuming TextBox name is Text1 and default button is Command1:
Private Sub Command1_Click()
    Static ignoreClick As Boolean
    If ignoreClick = False Then
        If Me.ActiveControl Is Text1 Then
           SendKeys vbCrLf
           ignoreClick = True
           Exit Sub
        End If
    Else
        ignoreClick = False
        Exit Sub
    End If
    
    ' your code for default button clicked/enter pressed

End Sub

Open in new window

0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 39823133
Improved a bit - keeps Enter behavior for all multiline textboxes if default button (name=Command1) presents:
Private Sub Command1_Click()
    Static ignoreClick As Boolean
    If ignoreClick Then 'fired by SendKeys
       ignoreClick = False
       Exit Sub
    Else
       Dim ctrl As Control
       Set ctrl = Me.ActiveControl
       If TypeOf ctrl Is TextBox Then
          If ctrl.MultiLine = True Then 'enter was pressed in multiline textbox
             SendKeys vbCrLf
             ignoreClick = True
             Exit Sub
          End If
       End If
    End If
    ' your code for default button clicked/enter pressed
    MsgBox "Pressed"
End Sub

Open in new window

0
 

Author Closing Comment

by:al4629740
ID: 39830961
Thats exactly what I am looking for.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question