Solved

mouse selection in VB3.0

Posted on 1998-06-07
4
157 Views
Last Modified: 2010-05-03
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
Comment
Question by:sharanya
  • 2
  • 2
4 Comments
 

Author Comment

by:sharanya
ID: 1462747
Edited text of question
0
 

Accepted Solution

by:
loguea earned 100 total points
ID: 1462748
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
 

Author Comment

by:sharanya
ID: 1462749
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
 

Expert Comment

by:loguea
ID: 1462750
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question