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.

保姆级教程:用CH34xSerCfg工具修改USB转串口芯片的VID/PID,避免驱动冲突 本文详细介绍了如何使用CH34xSerCfg工具修改USB转串口芯片的VID/PID,解决驱动冲突问题。通过实战案例和配置技巧,帮助开发者高效管理嵌入式设备,避免常见的USB设备识别问题,提升开发效率。 阅读详情

相关推荐

RTOS任务调度原理:高优先级任务为何在低优先级任务执行时无法响应

实时操作系统(RTOS)的核心在于其确定性的任务调度机制,它通过优先级抢占确保关键任务及时执行。其基本原理是调度器仅在特定调度点(如任务主动阻塞、中断退出时)运行,比较就绪态任务的优先级并切换上下文。这一机制的技术价值在于为嵌入式系统提供可预测的响应时间,广泛应用于工业控制、汽车电子和物联网设备等对实时性要求高的场景。当低优先级任务执行**长时间非阻塞运算**且无中断发生时,调度器无法被触发,导致高优先级任务虽处于就绪态却无法获得CPU,造成系统响应延迟。理解**任务状态机**与调度点,是优化实时性、避免此

weixin_33508411的博客 296

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

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

weixin_41999297的博客 2328

GOM引擎单机传奇架设全攻略——从DBC2000配置到登录器生成

本文详细解析了使用GOM引擎架设单机传奇的完整流程,从DBC2000的安装配置、服务端部署、引擎控制器设置,到登录器生成与客户端补丁放置。文章重点解决了单机架设中的常见问题,如数据库路径配置、IP地址设置及Key.lic文件处理,旨在帮助玩家快速搭建稳定的个人游戏环境,体验GM乐趣。

weixin_28318011的博客 665

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的博客 964

智能环境感知:STM32多传感器数据融合与报警策略设计

本文详细介绍了基于STM32的多传感器数据融合系统设计,整合DHT11温湿度传感器、MQ-2烟雾检测和光照强度检测模块,通过智能算法实现环境感知与动态报警。系统采用数据滤波、多传感器校验和自适应阈值策略,显著提升监测精度与可靠性,并通过OLED显示屏提供清晰的多级报警界面。

plant的博客 204

Win10更新后黑屏只剩鼠标?火绒误杀explorer.exe的5种自救方案(附详细步骤)

本文详细介绍了Win10更新后出现黑屏只剩鼠标的5种专业修复方案,重点解决火绒误杀explorer.exe的问题。从基础的任务管理器操作到安全模式下的系统修复,再到注册表编辑和系统还原,提供了全面的解决方案,帮助用户快速恢复系统正常运行。

weixin_29306571的博客 666

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实践 2859

CMU动作捕捉数据集实战:从AMC文件到Python可视化的完整流程

本文提供了CMU动作捕捉数据集的完整实战指南,详细解析了AMC文件格式,并对比了MATLAB转换、Python原生解析及转换为BVH格式三种数据解析策略。重点介绍了如何构建Python数据处理与可视化管道,包括将数据转换为Pandas DataFrame、绘制时间序列与相关性热力图,以及实现3D骨架动画,帮助开发者高效利用这一经典动作捕获数据集进行运动分析与模型训练。

android的专栏 722

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

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

张洪举 4476

python 携程登陆_Python 学习练习之用户登录接口

目的:用python实现简单用户注册,登陆,加黑功能,放个流程图吧。以下内容仅为练习 执行流程:[root@zabbix login]# python user_login.pyusername:tompassword:123456Are you want to register ? [y/n]yRegister successful,Please relogin ![root@zabbix lo...

weixin_28679635的博客 525

从设计到实战:手把手教你用SolidWorks完成一个简易离心泵叶轮的水力设计全流程

本文详细介绍了使用SolidWorks进行简易离心泵叶轮水力设计的全流程,涵盖参数计算、水力设计和三维建模等关键步骤。通过实际案例演示,帮助机械设计工程师和学生掌握从理论到实践的转化技巧,特别适合低比转速离心泵叶轮的设计需求。

weixin_30621711的博客 245

VFP全面控制EXCEL

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

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

双端之Nginx+Php结合PostgreSQL搭建Wordpress

制作的 PG4WP 分支版本,它与所有版本的 WordPress 兼容,解决了原版的一些问题。参数,确保 PostgreSQL 正在监听默认端口(通常是 5432),或者你自定义的端口。:PG4WP 插件存在缺陷和不完整的功能,可能与最新版本的 WordPress 不兼容。的插件,它允许 WordPress 使用 PostgreSQL 数据库。,如果看到 Nginx 的默认欢迎页面,说明 Nginx 已正确安装。,如果看到 Nginx 的默认欢迎页面,说明 Nginx 已正确安装。

宇宙第一小趴菜的博客 1898
上一篇: 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、付费专栏及课程。

余额充值