• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

mouse selection in VB3.0

I need to select a section using a mouse from a body of text  in a textbox.I want to be able to use this selected text later in the program for other purposes. I am using VB3.0/Win95 can somebody help me?
0
sharanya
Asked:
sharanya
  • 2
  • 2
1 Solution
 
sharanyaAuthor Commented:
Edited text of question
0
 
logueaCommented:
You can obtain the selected text by using the Textbox SelText property and it can be copied to the clipboard as follows:

Clipboard.SetText = Text1.SelText

You can then later retrieve the text from the clipboard with:

Clipboard.GetText

0
 
sharanyaAuthor Commented:
Need clarification:
when i type Clipboard.SetText = Text1.SelText in the code for textbox, i get "Need expression" error.Why?
I have defined a string variable , selection = Clipboard.GetText,why does it expect a ()for GetText?
My books dont talk about this, please clarify.
0
 
logueaCommented:
Sorry about that, the SetText sample code should say:

Clipboard.SetText Text1.SelText
or
Call Clipboard.SetText(Text1.SelText)

This is because SetText is a method of the Clipboard object as opposed to a property.
And as you point out the GetText sample should really have parentheses as well ie.

yourVar = Clipboard.GetText()

Once again this is because GetText is a method of the clipboard object not a property.

As a simple example follow these steps:

Step 1) Create a new project (Project1 is created by default)

Step 2) Add two textboxes to the form these will be called Text1 and Text2 by default and the form is called Form1 by default.

Step 3) Copy the following code into the code window for Form1

Private Sub Text1_MouseUp(Button As Integer,Shift As Integer,X As Single,Y As Single)
    If Text1.SelText <> "" Then
        Clipboard.SetText Text1.SelText
    End If
   
    Text2.Text = Clipboard.GetText()
End Sub

Step 4) Run the project and use the mouse to select some of the text in Text1. You'll notice that when the mouse is released if there is any text selected then the text property of Text2 is set to the selected text from Text1.

Hope this helps.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now