Solved

mouse selection in VB3.0

Posted on 1998-06-07
4
152 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
Comment Utility
Edited text of question
0
 

Accepted Solution

by:
loguea earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now