Link to home
Start Free TrialLog in
Avatar of sharanya
sharanya

asked on

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?
Avatar of sharanya
sharanya

ASKER

Edited text of question
ASKER CERTIFIED SOLUTION
Avatar of loguea
loguea

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.