VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Insert text

by justin holland (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (38 Votes)

This code inserts text at the end of a textbox (or anything with a .text, .selstart, .sellength, and .seltext property) without adding the entire contents of the textbox all over again
it saves a lot of time with long text and opening text files

Inputs
textcontrol as object,text as string
Assumes
nothing
Code Returns
1 if successful 0 if any error occurs
Side Effects
none i know of
API Declarations
nope

Rate Insert text

Function AddText(textcontrol As Object, text2add As String)
  On Error GoTo errhandlr
  tmptxt$ = textcontrol.Text 'just in case of an accident
  textcontrol.SelStart = Len(textcontrol.Text) ' move the "cursor" to the end of the text file
  textcontrol.SelLength = 0 ' highlight nothing (this becomes the selected text)
  textcontrol.SelText = text2add ' set the selected text ot text2add
  AddText = 1
  GoTo quitt ' goto the end of the sub
'error handlers
errhandlr:
  If Err.Number <> 438 Then   'check the error number and restore the
    textcontrol.Text = tmptxt$ 'original text if the control supports it
  End If
  AddText = 0
  GoTo quitt
quitt:
  tmptxt$ = ""
End Function

Download this snippet    Add to My Saved Code

Insert text Comments

No comments have been posted about Insert text. Why not be the first to post a comment about Insert text.

Post your comment

Subject:
Message:
0/1000 characters