?
Solved

VB6: TextBox: advanced topic

Posted on 2003-03-07
6
Medium Priority
?
516 Views
Last Modified: 2008-03-10
Is there any way to control, via VB code, the position of the keyboard cursor in a TextBox control?

I mean, can I get its (row,col) current position, and set it to a particular (row,col) value? What functions/subs do I use?
0
Comment
Question by:kainashi
[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
6 Comments
 
LVL 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 92 total points
ID: 8086784
You mean the Text1.SelStart ??
0
 
LVL 1

Assisted Solution

by:Fischermaen
Fischermaen earned 92 total points
ID: 8086881
You can place the cursor with text1.SelStart = <Position> and text1.SelLength = 0
0
 
LVL 1

Accepted Solution

by:
irfanazam earned 96 total points
ID: 8087367
this function will give you the line number of current character or where the cursor is

call function like this

GetCurrentLine Text1.Hwnd

Public Function GetCurrentLine(ByVal hwnd As Long) As Long
GetCurrentLine = SendMessage(hwnd, EM_LINEFROMCHAR, -1, 0)
End Function

I will provide code for other features you want.
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 1

Expert Comment

by:irfanazam
ID: 8087464
hi here are 2 functions
'This will give you the line number of cursor position
'in TextBox Text1.
CurLine = GetCurrentLine(Text1)
'This will give you the Column number of cursor position
'in TextBox Text1.
CurCol = GetCurrentCol(Text1)


''''''''''''''''''''''''''''''''''''''''''''''
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long


Function GetCurrentCol(tbox As TextBox) As Long
Dim CurLine As Long
Dim TotalLines As Long
Dim t As Long
CurLine = SendMessage(tbox.hwnd, EM_LINEFROMCHAR, -1, 0)
t = 0
If CurLine > 0 Then
    CurCol = SendMessage(tbox.hwnd, EM_LINEINDEX, CurLine, 0)
    t = CurCol
End If
GetCurrentCol = tbox.SelStart - t + 1
End Function

Public Function GetCurrentLine(tbox As TextBox) As Long
GetCurrentLine = SendMessage(tbox.hwnd, EM_LINEFROMCHAR, -1, 0) + 1
End Function


Hope it will solve your problem
I soon will post the routines to set cursor position in a text box
0
 

Expert Comment

by:CleanupPing
ID: 8900532
kainashi:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9074288
Moderator, my recommended disposition is:

    Split points between: ryancys and Fischermaen and irfanazam

DanRollins -- EE database cleanup volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 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