Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Copy and Paste Function


Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2006, 12:04 PM
fabbie fabbie is offline
Freshman
 
Join Date: Jun 2006
Posts: 25
Default Copy and Paste Function


Im trying to write my own copy and paste function for my program, but I seem to be having some problems starting off.
I just want to enquire this first, how does a typical copy function work? Whenever, we press ctrl+c, where are the text words copied to? a text file or maybe a string array?

In another matter, is there a built-in function to detect where the running program currently has its 'focus' on? Its like I want to know on which form is my focus at.
Reply With Quote
  #2  
Old 08-11-2006, 01:39 PM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

1. Whatever you like, normal you would keep it in memory by placing it on the ClipBoard
2. ActiveForm, ActiveControl
Reply With Quote
  #3  
Old 08-11-2006, 01:41 PM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,734
Default

The .Clipboard object gives you direct access to the Windows clipboard and usually prevents needing to write your own functions. Just be sure that you do not programatically corrupt the clipboard contents, otherwise users will get unexpected results when they are using the clipboard elsewhere.

For which form has focus, look into Screen.ActiveForm.
Reply With Quote
  #4  
Old 08-14-2006, 11:12 AM
fabbie fabbie is offline
Freshman
 
Join Date: Jun 2006
Posts: 25
Default

I still seem to be having problem with this. I've tried using Flyguy's example code on highlighting multiple cells at once and tried using:

Clipboard.SetText Screen.ActiveControl.Text.

It seems what is being copied is only on the text of cell being focused on. How can i copy text of multiple cells that is being highlighted? I intend to do something like the Excels copy and paste function.
Reply With Quote
  #5  
Old 08-14-2006, 02:47 PM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

You have to give more information.
Are you referring to a flexgrid control on some form?
Reply With Quote
  #6  
Old 08-14-2006, 08:31 PM
fabbie fabbie is offline
Freshman
 
Join Date: Jun 2006
Posts: 25
Default

Oh yes. It is for the flexgrid. I must have missed that out.

I intend to copy any highlighted cells into the clipboard. But I could only copy the text of the cell being focused on. How can i copy text of multiple cells that is being highlighted?
Reply With Quote
  #7  
Old 08-15-2006, 01:10 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

Use the .Clip property of the FlexGrid
Reply With Quote
  #8  
Old 08-15-2006, 04:35 AM
fabbie fabbie is offline
Freshman
 
Join Date: Jun 2006
Posts: 25
Default

Just a simple question.
I found this while browsing through the net.

http://www.expressnewsindia.com/c4/ex1/C1000.html

Private Sub EditPaste()
'Insert Clipboard contents
If Len(Clipboard.GetText) Then MSFlexGrid1.Clip = _
Clipboard.GetText
End Sub

I can't seem to comprehend this coding. Normally when I use the IF statement, it would always end with a '='. In this case , it does not have an equals. How does this work? Besides that, this line :

MSFlexGrid1.Clip = _
Clipboard.GetText.

What is the ' _ ' for? normally i would just put
MSFlexGrid1.Clip = Clipboard.GetText. Please do explain. thanks
Reply With Quote
  #9  
Old 08-15-2006, 05:15 AM
FiRe_Jas FiRe_Jas is offline
Regular
 
Join Date: Nov 2004
Posts: 98
Default

I use:
Code:
Private Sub mnuCopy_Click() Clipboard.Clear Clipboard.SetText FlexGrid.Text End Sub
mnuCopy is a control in a popup menu that appears when you right click on the flexgrid.
__________________
If (Online = True) Then
Shell "firefox.exe -remote openURL(www.xeweb.net)"
End If
Reply With Quote
  #10  
Old 08-15-2006, 05:21 AM
bushmobile's Avatar
bushmobile bushmobile is offline
Junior Contributor
 
Join Date: Mar 2004
Posts: 357
Default

the If construct evaluates a Boolean expression
Code:
If [Boolean Expression] Then
so you will commonly use it
Code:
If strMyName = "bushmobile" Then
where strMyName = "bushmobile" is evaluated to True or False.

In VB False = 0 and True = Not False. So if Clipboard.GetText = "", then Len(Clipboard.GetText) = 0 and it is evaluated to False.

Conversely, if there is some text in Clipboard.GetText then Len(Clipboard.GetText) will return a number other than zero and hence be evaluated to True.

The underscore (_) is just used to break long lines for readability.
Reply With Quote
  #11  
Old 08-15-2006, 05:28 AM
Xamonas Chegwe's Avatar
Xamonas Chegwe Xamonas Chegwe is offline
Junior Contributor
 
Join Date: Jun 2006
Posts: 228
Default

Quote:
Originally Posted by fabbie
I can't seem to comprehend this coding. Normally when I use the IF statement, it would always end with a '='. In this case , it does not have an equals. How does this work? Besides that, this line :

MSFlexGrid1.Clip = _
Clipboard.GetText.

What is the ' _ ' for? normally i would just put
MSFlexGrid1.Clip = Clipboard.GetText. Please do explain. thanks
An If statement evaluates the following conditions as True or False. In mathematical terms, 0 is False, anything else is True. This form of the If statement is a shortcut for:

Code:
If Len(Clipboard.GetText) <> 0

The '_' is a continuation character. It tells the compiler that the statement continues on the next line. It is used to make the code more readable and to stop you having to scroll right to read the end of a long statement.

MSFlexGrid1.Clip = _
Clipboard.GetText.

&

MSFlexGrid1.Clip = Clipboard.GetText

Are exactly the same to the compiler.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->