Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Dynamic Data Exchange
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Listing 9.3 Code in COPYLINK.FRM.
Option Explicit
Private Sub Command1_Click()
Clear the Picture Box.
Picture1.picture = LoadPicture()
End Sub
Private Sub Command2_Click()
Quit the program.
End
End Sub
Private Sub mnuEdit_Click()
Enable the Copy command only if the Picture Box
or the Text Box is active.
If TypeOf Screen.ActiveControl Is TextBox Or TypeOf Screen.ActiveControl _
Is PictureBox Then
mnuEditCopy.Enabled = True
Else
mnuEditCopy.Enabled = False
End If
End Sub
Private Sub mnuEditCopy_Click()
Dim LinkInfo As String
Clear the Clipboard.
Clipboard.Clear
If the active control is the Text Box copy its text and
DDE information to the Clipboard.
If TypeOf Screen.ActiveControl Is TextBox Then
LinkInfo = App.EXEName & | & LinkTopic
LinkInfo = LinkInfo & ! & Screen.ActiveControl.Tag
Clipboard.SetText LinkInfo, vbCFLink
Clipboard.SetText Screen.ActiveControl.TEXT
End If
If the active control is a Picture Box copy its picture and
DDE information to the Clipboard.
If TypeOf Screen.ActiveControl Is PictureBox Then
LinkInfo = App.EXEName & | & LinkTopic
LinkInfo = LinkInfo & ! & Screen.ActiveControl.Tag
Clipboard.SetText LinkInfo, vbCFLink
Clipboard.SetData Screen.ActiveControl.picture
End If
End Sub
More DDE Magic
DDE offers a great deal more capability than is possible to cover here. However, I would like to finish this chapter with one more use for DDEsomething I find very helpful. Using the power of DDE, we can employ Visual Basic to create extensions to existing programs, circumventing omissions or shortcomings in their design and capabilities.
For example, we may like to use the Microsoft Excel spreadsheet program for manipulation and graphing of numerical data. And why not? Excel has a wide range of powerful features, and trying to duplicate even a few of them in a Visual Basic program would be a major programming challenge. In my opinion, however, Excel falls short in one area: data entry. Typing large amounts of data into the spreadsheets row-and-column structure can be an exercise in frustration and error. As you know, however, Visual Basic makes it easy to create attractive, easy-to-use forms for data entry and other purposes, and also to include data validation code to prevent entry of incorrect data. By using DDE, we can create a Visual Basic data-entry program that sends the data to an Excel spreadsheet. We get the best of both worlds: the convenience of a Visual Basic data-entry form and the analytical capabilities of Excel.
Using DDE in this way is quite different from the uses we covered earlier in the chapter. DDE is used to transfer data, but no link is established. Once a piece of data is sent to Excel, we have no link back to the Visual Basic programthe end result is exactly the same as if the data had been typed directly into Excel. In addition to sending data to other programs, DDE can be used to send commands, instructing programs to perform various actions. Youll see that several actions are required for this sort of application.
The first action we will need is the ability to start a program, if it is not already running. To start another Windows application from within a Visual Basic program, you use the Shell function. The syntax is shown here:
result = Shell(CommandString [, WindowStyle])
The CommandString argument specifies the name of the program to execute, including any required arguments or command-line switches. If the program name in CommandString doesnt include a .COM, .EXE, .BAT, or .PIF file extension, .EXE is assumed. The WindowStyle argument specifies the style of the application window when the program starts, such as maximized or minimized. We can omit this argument, and the program is opened, minimized with focus. Table 9.2 shows the possible values for WindowStyle and the defined constants.
If the application is successfully initiated, the Shell function returns the applications task identification, a unique number that identifies the running application. If the Shell function is unable to start the named application, an error occurs.
Table 9.2 Constants for the WindowStyle argument.
Constant
Value
Description
vbHide
0
Window is hidden and focus is passed to the hidden window.
vbNormalFocus
1
Window has focus and is restored to its original size and position.
vbMinimizedFocus
2
Window is displayed as an icon with focus.
vbMaximizedFocus
3
Window is maximized with focus.
vbNormalNoFocus
4
Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus
6
Window is displayed as an icon. The currently active window remains active.
When using the Shell function, remember that it runs other applications asynchronouslythe Visual Basic program does not wait for the Shell command to complete. This means that we cant be sure that a program started with Shell will have completed its start-up procedures before the code following the Shell function in our Visual Basic application is executed.
Sending Commands To Another Program
Once you have established a DDE link, you can use the link for more than transferring data. You can also use it to send commands to the other application using the LinkExecute method. This method is applied to the control that is maintaining the linkthe active destination control. Thats just a syntax requirement, however, as the control has nothing to do with the command we are sending. The syntax for the LinkExecute method is shown here:
ControlName.LinkExecute Command
ControlName is the name of a control that is the destination in an active DDE link. The Command argument is a string that contains the commands to be sent to the DDE source application. The legal commands depend on the specific application. In other words, no universal DDE command set exists that contains commands for use with all applications. Youll need to refer to the documentation for each source application for information on the commands it accepts. Excel, for example, accepts any of its macro commands enclosed in brackets.
Sending Data To Another Program
Once an active DDE link is established, you can send data from the destination program to the source program. Note that this is the reverse of the more typical data flow in a DDE conversation, which is from source to destination. To send data from the destination to the source, use the LinkPoke method. The procedure is as follows:
1. Put the data to be transferred in a Text Box or Picture Box control.
2. Set the controls LinkMode property to 0-None.
3. Set the controls LinkTopic and LinkItem properties to identify the location where you want to poke the data.
4. Set the LinkMode property to 2-Manual.
5. Execute the LinkPoke method.
For example, the following code will poke the text Testing LinkPoke to cell B2 in the Excel spreadsheet TESTDATA.XLS:
Text1.Text = Testing LinkPoke
Text1.LinkMode = 0
Text1.LinkTopic = EXCEL|TESTDATA
Text1.LinkItem = R2C2
Text1.LinkMode = 2
Text1.LinkPoke
Note the use of R2C2 to refer to the second row in the second column of the Excel spreadsheet. For DDE commands, Excel uses numbers for both rows and columns rather than using letters for columns, as is the case when you are working directly in Excel.
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
TI 01 09 06 T pl(2)wyklad 10 09 06 2 komorka chemwyklad 10 09 06 2 komorka budowaxenon E83 od 09 06TI 99 09 06 B pl(1)TO 09 06 2013Referendum ws paktu bezpieczeństwa opóźnione (09 06 2009)pdm? 2016 09 0609 06 19 DTZ prezentacja tenant mix FINAL109 06TI 98 09 06 T pl(1)TI 01 09 06 T B pl(2)09 06 Transport reczny i mechaniczny normy dzwiganiaTI 03 09 06 T pl(1)więcej podobnych podstron