Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor column in EDITBOX

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
Is there a way to calculate the column position of the cursor in an EDITBOX ?

I would like to limit the characters per line to 70 - 90 characters. If the cursor goes beyond 70, I could use the KEYPRESS method to signal the user.

Thanks,
Sam
 
Hang on a second. I see you want to limit the number of characters per line. Selstart won't do that. It returns the position of the cursor relative to the start of the text, not the start of the line.

Maybe there's some way of doing it with ALINES():

- Copy the contents of the edit box to a variable.

- Use ALINES() to get it into an array.

- Use Selstart to work out which row in the array the cursor is on, and which character position within the line.

It sounds a bit fiddly to me. Maybe someone else will have a better idea.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,

Thanks. I tried that. It gives me the character count from the beginning of the text. I need to know the character count from the beginning of the line that the cursor is on.

Sam

 
Mike,

I think I forgot to refresh the page. I answered before I saw your second reply.

I'll try to do something with your suggestion and get back.

Thanks,
Sam
 
This works, in the keypress event.

*- Text from beginning to Insertion Point
lcTempString = LEFT(THIS.TEXT,THIS.SELSTART)
*- Last Carriage Return, end of previous line
lcBegOfLine = RAT(CHR(13),lcTempString)

IF THIS.SELSTART - lcBegOfLine > 70
IF FILE((ADDBS(GETENV('windir')))+'MEDIA\DING.WAV')
SET BELL TO (ADDBS(GETENV('windir')))+'MEDIA\DING.WAV'
?? CHR(7)
SET BELL TO
ENDIF
ENDIF

Thanks for pointing me in the right direction.

Sam
 
Sam,

Yes, that looks like it should work.

By the way, you don't really need the IF FILE(... test. If the WAV file is not present, the code will still work, but you'll hear the default beep.

I know that's not related to your oiginal problem. I just thought I'd mention it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike,

Suggestion noted.

Thank you.

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top