AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Edit Line Text.

Here's a good one for you. This will allow you to select any line of text, and then edit it using a dialogue box.

Note : This will only work with Line Text. Sorry :-(

Edit Line Text

First of all you need a Module with this coding in it : 

Option Explicit
Public objPicked As AcadObject
Public Const VK_ESCAPE = &H1B
Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer

Function checkkey(lngKey As Long) As Boolean If GetAsyncKeyState(lngKey) Then checkkey = True Else checkkey = False End If End Function
Public Sub textedit() Dim BasePnt As AcadPoint 'declare variables Start: On Error GoTo errControl 'if there is an error ThisDrawing.Utility.GetEntity objPicked, BasePnt, _ "Select Line Text" 'select the object UserForm1.TextBox1.Text = objPicked.TextString 'get the existing textstring and put it in 'the text box UserForm1.Show 'display the dialogue Exit Sub 'exit the sub routine errControl: 'define the error control If Err.Description = "Method 'GetEntity' of object _ 'IAcadUtility' failed" Then 'if the error matches these.. If checkkey(VK_ESCAPE) = True Then 'if the escape key is selected End 'end Else 'or else Resume 'repeat "Select Object" End If Else MsgBox Err.Description 'it must be another type of error End If End Sub


Now insert a userform with a text box and two buttons. Keep the default
names and add this coding to the form :


Private Sub CommandButton1_Click()

If TextBox1.Text = "" Then
'if all text is deleted

    TextBox1.Text = " "
    'put in a space
End If

objPicked.TextString = TextBox1.Text
'get the text string from the text box

'update the text


End Sub

Private Sub CommandButton2_Click() End End Sub
Private Sub UserForm_Activate() UserForm1.TextBox1.SetFocus 'set focus to the textbox UserForm1.TextBox1.SelStart = 0 'start at the first character UserForm1.TextBox1.SelLength = Len(UserForm1.TextBox1.Text) 'highlight the text string End Sub


Now run the macro "TextEdit" and select some line text when prompted.
Change the text and select O.K. Crikey, I'm good hey!!!!
If you would like to download the source code for this Application/s, then click Here
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website