Hidden Secrets of the VFP IDE, Part 2

vf操作excel vfp vf 操作excel,灰常好的资料,全攻略,保证立马上手! 立即下载

Hidden Secrets of the VFP IDE, Part 2

Cathy Pountney

FoxPro has always had several different ways to do the same thing. How many times have you looked over the shoulder of another developer and said, "Hey! How did you do that?" In this article Cathy Pountney uncovers many ways to work within the IDE, especially those that aren't so obvious or aren't documented. You'll learn several different ways to improve your productivity. Even experienced developers are bound to learn something new.

This is the second of two articles where I've been exposing several unknown secrets of the VFP IDE. In the first part, I discussed various designers, a few controls, the Property Sheet, the Document View, and the Find Dialog. Then I revealed some secrets of IntelliSense as well as several tools and utilities included with Visual FoxPro. In this article, I'll reveal secrets of the Command window, several commands, and wrap up with a potpourri of hidden secrets.

Command window and commands

The Command window is another place we spend a lot of our day. Here are some tips that can be used in the Command window as well as some lesser-known secrets about some of VFP's commands.

Command window

Many people already know that you can highlight a line of code in the Command window, right-click, and choose Execute Selection to execute the highlighted code. But did you know that you can highlight multiple lines of code and execute them at once? However, you have to realize how this works or you might not get the expected results. When multiple lines of code are executed, a temporary program is created and then run. This means that variables can go out of scope after the chunk of code has been run. This is really more of a "hidden gotcha" than a "hidden secret"!

Another thing you can do in the Command window is use the semicolon (;) as a continuation character just as you do in code. This is great when you're copying code from a program or when you're creating a giant SELECT statement that you want to be able to wrap.

_CLIPTEXT

The first extra is a system variable called _CLIPTEXT. This contains the contents of the VFP clipboard. You can use it to set other information based on what's in the clipboard, and you can use it to define what's in the clipboard. It's a two-way variable that you can take advantage of at design time and even at runtime within your application.

To demonstrate, highlight a line of code in the Command window and press Ctrl+C to save it to the clipboard. Now enter ? _CLIPTEXT in the Command window and you'll see that the line of code you highlighted is printed on the screen. Another example is to run the following code to create a program:

_cliptext = '? "FOX ROCKS"' + CHR(13) + CHR(10) + ; '? "VFP 8 IS GREAT"' + CHR(13) + CHR(10) ERASE JUNK.PRG MODIFY COMMAND Junk NOWAIT KEYBOARD '{CTRL+V}' 

The preceding code fills the clipboard with two lines of code, creates a program file, and then pastes the contents of the clipboard into the newly created program.

_VFP.DataToClip()

The second extra that VFP has to help us with cut-and-paste functions is the _VFP.DataToClip() function. This function takes data from a table or cursor and puts it into the clipboard. From there, you can paste it anywhere else, including Microsoft Excel. The third parameter defines the format of the data. If you use a 1 in the third parameter, the data uses spaces to separate each field. However, if you use a 3 in the third column, tabs are used to separate each field, which makes it perfect for inserting into Excel or other applications.

Printing the clipboard

Another little-known feature in VFP is the fact that you can print what's in the clipboard. This is great when you want to print a chunk of code from a program, but not the entire program. Highlight the text you want to print and select File | Print from the main VFP menu to invoke the Print dialog (you can also use Ctrl+P to invoke the same dialog). From the Print dialog, select the Options button to display the Print Options dialog. By default the Print What — Type combo box is filled in with the current program. However, you can select Clipboard, select OK, and then go back to the Print dialog to finish selecting your printing options.

BROWSE keystrokes

When using the BROWSE command, there are several keystrokes you can use to perform special operations, as shown in Table 1.

Table 1. Keystrokes with the BROWSE command.

Keystroke

What it does

Ctrl+F

Find Next

Ctrl+G

Find Previous

Ctrl+Y

Add a record

Ctrl+T

Toggle Deletion flag

Ctrl+Home

Edit a memo field

Ctrl+W

Save and close

Ctrl+F10

Toggle between maximize and restore

What's in a NAME?

The NAME clause can be very helpful for passing data around. The SCATTER, GATHER, and INSERT INTO commands all honor the NAME clause. This makes these commands much more powerful than in earlier days when you were used to SCATTERing into MEMVARs. Now that you can SCATTER to a NAME, you can pass the data to another object as a parameter. The following code shows an example of how to do this:

*-- Open Tables CLOSE TABLES ALL USE MyTable1 IN 0 USE MyTable2 IN 0 EXCLUSIVE ZAP IN MyTable2 *-- Copy records from MyTable1 to MyTable2 SELECT MyTable1 GOTO TOP SCAN SCATTER NAME oMyTable AddToTableGather('MyTable2', oMyTable) AddToTableInsert('MyTable2', oMyTable) ENDSCAN SELECT MyTable2 BROWSE *-- Close tables CLOSE TABLES ALL RETURN ************************* FUNCTION AddToTableGather ************************* LPARAMETERS pcTable, poFields LOCAL lcAlias lcAlias = ALIAS() SELECT (pcTable) poFields.Descr = ALLTRIM(poFields.Descr) + 'G' APPEND BLANK GATHER NAME poFields SELECT (lcAlias) RETURN ************************* FUNCTION AddToTableInsert ************************* LPARAMETERS pcTable, poFields poFields.Descr = ALLTRIM(poFields.Descr) + 'I' INSERT INTO (pcTable) FROM NAME poFields RETURN 

Another great example of using the NAME clause is with the BROWSE command. In the Command window, enter the following:

USE MyTable1 BROWSE NAME oBrowse 

Now in the Command window, enter the string "oBrowse." (don't forget the trailing period) and you'll see IntelliSense kick in as soon as you type the period. This is great–the browse window is now an object you can manipulate. Start picking some properties, such as fontbold or rowheight, from IntelliSense and you can manipulate the browse window right from the Command window.

Implicit TRANSFORM()

In VFP 8, a few commands have implemented an implicit TRANSFORM() feature. This means that you can use data types that aren't character, and the command will TRANSFORM it automatically for you. If the item being transformed is an object, the text "(Object)" is used.

Try the following commands and you'll be pleasantly surprised that they don't throw an error!

WAIT WINDOW DATE() MESSAGEBOX(500) DEBUGOUT DATE() ? _VFP 

Potpourri

Here are a few more hidden secrets that are scattered throughout Visual FoxPro.

Shifty tricks

Using the Shift key before selecting a menu option can change the options on the menu. For example, pressing Shift and selecting the File menu changes the Close option to Close All. Using Shift along with the Window menu changes Hide to Hide All. Normally, the Format | Font option changes the font in the Command window. However, using the Shift key with the Format menu changes the Font option to Screen Font, which changes the font of the VFP screen.

Another feature that's been around for years and years in FoxPro and VFP is the Outshow feature. Pressing Ctrl+Alt+Shift hides all the windows except the one accepting output. They stay hidden as long as you continue pressing the key combination. As soon as you let go, all the hidden windows appear again. This is extremely useful when you display something from the Command window with the question mark (?) character and the results end up getting shown behind a bunch of other windows.

Copy a class

At first, it appears that there isn't a way to copy an existing class in VFP. You can subclass it–but there doesn't seem to be any way to copy a class. Well, with the use of the Project Manager it can be accomplished quite quickly with the following steps:

1. Drag the source class from one library to another.

2. Rename the class in the new library.

3. Drag the newly named class back to the original library.

4. Delete the class from the temp library.

Of course, it would be nice if there was a copy button on the right-click menu or somewhere else. But heck, we can't have everything!

Drag and drop

In VFP 8, the Project Manager was improved by allowing you to add multiple files at once. Prior to this version, you could only add one file at a time. However, you can use drag and drop to add multiple files, and this feature has been around for quite a while. Open the Project Manager and then open Explorer. Select some files in Explorer and drag them to the Project Manager. An added benefit is that the Project Manager is smart enough to figure out what tab to put each of the different files on based on their file extensions.

_VFP.SetVar()

This little-known function can be used to set variables in situations where you can't execute a command but you can call a function. A perfect example of when to use this is in the Report Designer. I use it all the time in the OnEntry and OnExit expressions of the various bands. For example, in the OnExit expression of a Group Footer, you can use _VFP.SetVar('rnRecordCount', 0) to clear the value of the rnRecordCount variable. Or you can use _VFP.SetVar('rnCountDataGroups', rnCountDataGroups+1) to increase a variable that tracks the number of data groups processed.

Wildcards

Some commands accept wildcards, and although this can be great to work with, it can also be dangerous. There's not much harm in entering MODI COMM MyProg*. All it's going to do is open up all the programs that are named starting with MyProg. However, issue DELETE FILE MyProg*.prg and "Danger! Danger! Danger!" flashes across my mind. Be careful in how you use wildcards!

Just for fun

Whew! This has been an article full of information. By now your brain is probably getting fuzzy, so I'm going to end with a few fun things.

Filer

Years ago, Filer was what most FoxPro developers used to search and find files. After VFP 3.0, this disappeared and many developers screamed. Well, the Fox Team has listened and decided to bring back a little nostalgia. Enter the following in the Command window to see an example of how it runs:

DO FORM (HOME(1) + 'Tools/Filer/Filer.scx') 

Search through the VFP Help file and read up on the new Filer, because this one is object-oriented and you can interact with it and implement it in your own applications. I guess you could call this FilerX!

Puzzle

Here's another long-lost feature of FoxPro that has been brought back in VFP 8. Enter the following in the Command window. However, be forewarned that this may severely reduce your productivity at work!

ACTIVATE WINDOW PUZZLE 

Error-free programs

Did you know that writing error-free programs is a cinch with VFP? Just enter the following line of code in your startup program and you're all set.

ON ERROR * 

Of course, this doesn't mean that your program is bug free. It only means that you won't get any error messages!

Love your work!

I know you love VFP so much that you never want to leave it. Well, no problem. When you start up VFP, enter the following line of code:

ON SHUTDOWN * 

No matter how hard you try, you can't get out of VFP now. This is great–you can sit in VFP 24/7 and never have to leave! Okay, okay, I guess this isn't such a great idea. I guess you'd better undo the damage with the following code:

ON SHUTDOWN 

Work smarter, not harder

This pair of articles has been crammed full of information. My goal was to expose you to as many cool features as possible and to give you some "ah ha" moments. Some of it may not have been new to you, but for the parts that were new, they could be huge time-savers for you in the future. As I always say, "Work smarter, not harder!"

To find out more about thisjournalname and Pinnacle Publishing, visit their Web site at http://www.pinpub.com/

Note: This is not a Microsoft Corporation Web site. Microsoft is not responsible for its content.

This article is reproduced from the March 2004 issue of thisjournalname. Copyright 2004, by Pinnacle Publishing, Inc., unless otherwise noted. All rights are reserved. thisjournalname is an independently produced publication of Pinnacle Publishing, Inc. No part of this article may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent of Pinnacle Publishing, Inc. To contact Pinnacle Publishing, Inc., please call 1-800-788-1900.

PCL 点到面的ICP算法【2024最新版】 经典的点到面的ICP算法。博客长期更新,本文最新更新时间为:2024年10月18日。 阅读详情

相关推荐

R语言分布式滞后非线性模型DLNM实战:空气污染与健康数据的动态效应可视化与政策启示

本文详细介绍了R语言中分布式滞后非线性模型(DLNM)的应用,特别关注空气污染与健康数据的动态效应可视化。通过dlnm包实现PM2.5等污染物的滞后效应分析,提供从数据预处理、模型构建到结果可视化的完整流程,并探讨了其在公共卫生政策制定中的实际应用价值。

weixin_29079643的博客 514

VFP 数据复制入粘贴板 _vfp.DataToClip() _cliptext

1、把网格数据源表的数据复制到粘贴板 _vfp.DataToClip(logrid.RecordSource,,3) 2、把文本复制至剪贴板 _cliptext= “要复制到剪贴板字符串”

weixin_41999297的博客 2328

问题解决:打开VMware创建的虚拟机,电脑立刻蓝屏并重启

VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credenti

weixin_55118477的博客 3万+

VFP grid 表格数据复制入粘贴板 _vfp.DataToClip() _cliptext

直接上代码 **************************************************** * * 当是网格时,复制网格的数据进粘贴板 * 2020-3-28 修改 Set Textmerge On Suspend Do Case This.linedit Return Case Empty(This.RecordSource) Return .F. C...

weixin_41999297的博客 963

TPRI-DMP平台介绍

TPRI-DMP为华能集团西安热工院自主产权的工业云PaaS平台,已经过13年的发展和迭代,其具备大规模能源电力行业生产应用软件开发和运行能力

ashou706的专栏 2271

红外协议 IR NEC 协议深度解析-简单易懂协议详解

1. 协议特征 使用双向编码(又称曼彻斯特编码); 使用38K载波对编码后的波形进行调制; 位时间 1.12ms 或 2.25ms 2. 调制 定义脉冲560µS为脉冲基本宽度T; 根据脉冲时间长短来解码。推荐载波占空比为1/3至1/4: (1) Logic “1” 位宽为2.25ms,脉冲时间560us(T + 3T); (2) Logic “0” 位宽为1.12ms,脉冲时间560us(T + T)。 (3 ) 重复码: 位宽为11.25ms,脉冲时间9ms(16T + 4T)。 3. 协议

代码打工人的博客 1万+

Hidden Secrets of the VFP IDE, Part 1

  Hidden Secrets of the VFP IDE, Part 1 Cathy Pountney FoxPro has always had several different ways to do the same thing. How many times have you looked over the shoulder of another developer and

Visual FoxPro实践 2856

目前固态激光雷达在机器人领域的应用难点汇总

固态激光雷达在机器人领域面临性能与成本的双重挑战:探测性能上,动态范围不足(60-80dB)导致高/低反射物体识别困难,近距盲区(30-50cm)与长距精度(±3cm)矛盾突出;结构上视场角与点云密度难以平衡,多雷达拼接又带来同步误差。成本方面,核心元件(SPAD/OPA芯片)良率低(<50%)、校准工序复杂,单机成本超200美元。环境适应性上,粉尘附着、振动偏移(±2°)和光衰(1万小时衰减15%)制约可靠性。

start_up_go的博客 480

VFP全面控制EXCEL

VFP和Excel都可以用来进行处理数据库表格,如果巧妙地将二者的优点结合起来,将会大大方便我们的工作。比如我们可以利用VFP进行处理数据,而利用Excel的预览打印功能进行报表打印。这就需要我们在VFP中直接来控制Excel。下面就在开发VFP应用项目时对Excel的控制作一下介绍:*!* 1.创建Excel对象oExcel=Createobject("Excel.application"

apple_8180(十豆三) 的专栏 8万+

汇川AM系列ethercat控制伺服的使用说明(含转矩模式)

本文以一个实际例子,介绍ethercat伺服驱动器的工作原理,以及在汇川AM系列PLC中,如何点动、定位、速度、转矩控制ethercat伺服。

qq_34047402的博客 5110

SDA 还是 SDI:SAP HANA 数据虚拟化与数据集成的取舍、组合与实战

结论先放在前面:SDA 面向数据虚拟化与联邦查询,强调不落地、不复制、按需实时访问;SDI 面向数据集成与复制,强调抽取、转换、装载与近实时增量同步。两者共享 Remote Source 与 Adapter 的理念,但侧重点与运行时组件明显不同。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 583

VFP开源项目之:Visual FoxPro IntelliSense增强工具FoxcodePlus

项目经理: Rodrigo Bruscain 下载:http://vfpx.codeplex.com/downloads/get/507407 FoxcodePlus项目旨在为Visual FoxPro IDE环境带来类似Visual Studio的新IntelliSense功能,包括: 针对函数、命令等的递增IntelliSense; 书写时刻的变量; 书写时刻访问变量

张洪举 4475

【GameFramework扩展应用】6-5、GameFramework框架出包时增加版本信息Version.txt文件

框架在热更新的时候,会先去获取文件,然后获取版本号,对比版本号和资源大小,才会开始下载资源。但是,框架生成AssetBundle资源的包里面是没有这个文件的,只能我们新建一个文件,然后手动填入数据,非常麻烦。好消息是,框架把这些接口都留给我们了,我们只需要继承接口,重写函数,然后在打包的时候选择这个辅助器即可。下面就来看一下如何实现把。

优快云博客专家,Unity3D高级软件工程师,《Unity 3D从入门到实战》作者。 1037
上一篇: Hidden Secrets of the VFP IDE, Part 1
下一篇: 命名约定
addwings
博客等级 码龄22年 0粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值