Foxpro

19. You don't need to use SYSMENU to enable cut-and-paste. Just:

define popup dummy
define bar _MED_CUT of dummy prompt "dummy1"
define bar _MED_PASTE of dummy prompt "dummy2"

SET SYSMENU TO _medit
PUSH MENU _msysmenu
FOR i = 1 TO cntpad("_msysmenu")
   RELEASE PAD (getpad("_msysmenu", 1)) of _msysmenu
ENDFOR 

20. to stop a control from being instantiated in a form,
    return .f. in the control's init() method.

21. beware of the commandbuttongroup.default properties.
    It could turn a simple ENTER into a CTRL+W when you exit
    a control in the form.

22. there is a new property textbox.passwordchar for inputing passwords.
    Set it to "*" will do.

23. if the printer definition for a report form was changed,
    clear field XXX.TAG and XXX.TAG2 by opening the FRX as a DBF.
	138396 HOWTO: Use the Default Windows Printer in Visual FoxPro
http://support.microsoft.com/?id=138396

24. SET PRINTER ON in visual foxpro could trigger a print job
    take them out of possible.

25. if you are to translate CLOSE DATABASE into something more
    precise, you must be aware of the side-effect that the command
    will SELECT A after closing all tables. Some programs may make
    use of this side effect.

27. to highlight the current row in a grid with color, and keeping
    it highlighted even after the grid loses focus

    add custom property:
       thisform.currec, thisform.gridback, thisform.leavegrid

    grid.init():
    DODEFAULT()
    thisform.currec = RECNO()
    thisform.gridback = this.backcolor
    WITH THIS
       .SetAll("DynamicBackColor",gridcolor(),"COLUMN")
       * a nicer back color is RGB(255,255,192)
    ENDWITH

    grid.afterrowcolchange():
    LPARAMETERS nColIndex
    dodefault()
    thisform.currec=recno(this.recordsource)
    * This.Columns(This.ActiveColumn).Text1.BackColor = RGB(255,0,0)
    * This.Columns(This.ActiveColumn).Text1.Forecolor = RGB(0,0,0)
    thisform.lockscreen=.f.
    if this.lLeavingGrid=.t.
         this.Refresh()
    endi

    grid.BeforeRowColChange():
    thisform.lockscreen=!this.leavegrid

    grid.when():
    thisform.leavegrid=.f.

    grid.valid():
    thisform.leavegrid=.t.

    function gridcolor
    parameter m.special
    local m.color
    m.color="iif(recno(This.RecordSource)=thisform.currec,"+;
            "RGB(192,255,255),"
    if empty(m.special)
      m.color=m.color+"thisform.gridback"
    else
      m.color=m.color+m.special
    endif
    return m.color+")"

28. DBSETPROP is used with CREATE SQL VIEW (gendbc.prg and view designer)
    CURSORSETPROP is used when the view is opened.

dbname=sys(3)
create database (dbname)
create sql view T_VIEW remote connect foxpro shared ;
  as select * from INVENTRY

select 0
use T_VIEW shared

? CURSORSETPROP("BUFFERING", 5, "T_VIEW")
? CURSORSETPROP("UPDATABLEFIELDLIST", "MEMOTEXT,DSTN,QTYD", "T_VIEW")
? CURSORSETPROP("SENDUPDATE", .t., "T_VIEW")
? CURSORSETPROP("KEYFIELD", "IMRD", "T_VIEW")

on error ? "ERROR", error(), message(), lineno()
? time()
m.time=time()
? m.time
BEGIN TRANSACTION
update T_VIEW ;
  set DSTN=m.time, QTYD=QTYD-1 ;
  where IMRD=5
update T_VIEW ;
  set DSTN=m.time, QTYD=QTYD-1 ;
  where IMRD=6
=inkey(0)
if tableupdate(.t.)
  END TRANSACTION
  ? "transaction completed"
else
  =aerror(errarray)
  for nn=1 to 7
    ? errarray[nn]
  endfor
  ROLLBACK
  errarray=.f.
  ? "reverted =", tablerevert(.t.)
endif



29. In general standard maintenance on Fox2x tables in VFP
    won't cause any table type changes. Using ALTER TABLE, COPY TO,
    and other commands that create "new" tables, will change the
    type, but you can of course change them back with the 
    COPY TO ... TYPE FOX2X.

30. The following would open and close exactly one database.
    If CLOSE DATABASE was called without any active DBC, it would
    work like the old FoxPro.

    OPEN DATABASE test
    CLOSE DATABASE

    to switch databases, 

    SET DATABASE TO database

    to open a table from a particular database:

    select 0
    use database!table
    select table

31. To bring the active row in a grid to be displayed at the top
    of the grid. 

    This.init()
    if !empty(This.RecordSource) and reccount(This.RecordSource) > 0
        This.OldActiveRow = recno(This.RecordSource)
    else
        This.OldActiveRow = 0
    endif

    This.AfterRowColChange:
    if !empty(This.RecordSource) and reccount(This.RecordSource) > 0
        if This.OldActiveRow <> recno(This.RecordSource)
            This.GridRowChange()
            THISFORM.Refresh()
        endif
    endif

    This.GridRowChange()	// custom method
    DO WHILE THIS.RelativeRow > 1
            THIS.DoScroll(1)
    ENDDO

If I understand you, what you are trying to avoid is the
grid seeming to sort of "jump around" as it's refreshed?
You want it to appear to nicely scroll as the new records
come in - with the most recently added record always on
the last displayed row of the grid?

This is actually pretty easy (once you get the hang of
programmatically scrolling the grid).  Check out the
DoScroll method, the ActiveRow property and the RelativeRow
property on the grid.  Then do something like this:

  llOldLock = ThisForm.Lockscreen
  ThisForm.Lockscreen = .T.

  SELECT theGridTable
  GO BOTTOM

  ThisForm.myGrid.SetFocus()

  ** scroll until the grid looks like you want
  ** this is left as an exercise for the 'student' :^)

  ThisForm.Lockscreen = llOldLock

32. To refresh the table under the grip, read these articles
    Take a look at the techniques in these articles:

    140653 PRB: Cursor-Based Grid Goes Blank If SQL SELECT Resets Cursor
    http://support.microsoft.com/?id=140653

    131836 PRB: Grid Not Refreshing Displaying a Cursor From Query
    http://support.microsoft.com/?id=131836

33. Use the thisform.QueryUnload() method to thsiform.release().

    if thisform.cmdSave.enabled
      * waiting for click on Save or Cancel buttons but user
      * clicked the Close button
      if !messagebox("Discard changes?",36,"Warning")==6
          NODEFAULT
          return
       endif
    endif
    dodefault()
    thisform.visible=.f.

34. to close a form price.scx with form.name="pricecrn" from
    a procedure external to the form,
    release window pricecrn
    or 
    price.release

35. then make the portion of the image white that should be transparent .
    . (vfp handles white as transparent  .. but only in bmp images)
make a copy of the bitmap and in this copy replace all white pixels that
should be displayed white (not transparent) with black ones ..

now name this file the same as your original picture but with the file
extension ".msk" .. (eg. upArrow.bmp -> upArrow.msk) add these files also to
your project ..

now VFP should display the portions that are black in the "mask picture" as
white and not transparent ..

36. read these to access registry from visual foxpro

HOWTO: Write a REG_EXPAND_SZ to the Registry
http://support.microsoft.com/?id=271733

265331 HOWTO: Read a REG_EXPAND_SZ Value From the Registry
http://support.microsoft.com/?id=265331

258559 HOWTO: Write a REG_SZ Value to the Registry
http://support.microsoft.com/?id=258559

258556 HOWTO: Read a REG_SZ Value From the Registry
http://support.microsoft.com/?id=258556

258545 HOWTO: Write a REG_MULTI_SZ Value to the Registry
http://support.microsoft.com/?id=258545

258528 HOWTO: Read a REG_MULTI_SZ From the Registry
http://support.microsoft.com/?id=258528

258262 HOWTO: Write a DWORD to the Registry
http://support.microsoft.com/?id=258262

258161 HOWTO: Read a DWORD From the Registry
http://support.microsoft.com/?id=258161

191638 HOWTO: Programmatically Access the Registry in Visual FoxPro
http://support.microsoft.com/?id=191638

244675 HOWTO: Use the Windows Script Host to Read, Write, and Delete 
Registry
http://support.microsoft.com/?id=244675

37. the grid's delete mark can be used.
    Use the grid.deleted() event.  Pop up your messagebox, and if the answer is
    'No,' issue NODEFAULT to block the deletion.

38. to print to a specific printer

162798 HOWTO: Use SET PRINTER TO NAME to Specify Report Destination
http://support.microsoft.com/?id=162798

39. report printing:

PUSH MENU _MSYSMENU
REPORT FORM myreport.frx TO PRINTER PROMPT PREVIEW NOCONSOLE
POP MENU _MSYSMENU

You can control the number of copies programmatically in a report.  See 
this article for more information:

251236 HOWTO: Programmatically Set the Number of Copies for a Report
http://support.microsoft.com/?id=251236

133163 HOWTO: Control Printer Attributes for a Report at Run Time
http://support.microsoft.com/?id=133163

188403 HOWTO: Modify Report Fields Programmatically
http://support.microsoft.com/?id=188403

This article on modifying the report at runtime may be useful also:

133163 HOWTO: Control Printer Attributes for a Report at Run Time
http://support.microsoft.com/?id=133163

e.g. check out www.news2news.com

and look at functions:

SetPrinter
GetPrinter
EnumPrinterData

40. to print an image on a report:
It is usually better not to use general fields. You can store binary data
like JPG's in a binary memo field using FILETOSTR(). Use STRTOFILE() to
store the memo field contents in a new file.
Here's a basic sample on how to print images stored in a binary memo field:
http://www.foxite.com/uploads/_2215n38q.zip

41. barcode font

Find a Code39 font with helper functions. Here is one at
http://www.morovia.com/font/

42. What method are you using to print the HTML or XML file? If you use 
StrToFile() to print do you see the same behavior?

190769 HOWTO: Use STRTOFILE() to Send Output to a Printer
http://support.microsoft.com/?id=190769

43. 156551 HOWTO: Use SYS(3054) to Optimize a Query
http://support.microsoft.com/?id=156551

248608 INFO: SQL SELECT Optimization Levels and Performance
http://support.microsoft.com/?id=248608 

176483 PRB: Large Amounts of RAM Seem to Process Data Slowly
http://support.microsoft.com/?id=176483


44. 137124 HOWTO: Create a PageFrame Parameterized View
http://support.microsoft.com/?id=137124

45. wait for an external file is ready:

declare Sleep in Win32api integer

local fd, FileName

FileName = 'Whatever'

do while .T.
    fd = fopen(FileName, 12)

   do case
    case (fd < 0)
        =sleep(1000)

    otherwise
         =fclose(fd)
        exit
    endcase
endwhile

46. visual studio sp4 dated aug 14 2000

47. pulling data from clipboard populated with data from excel:

If you use _CLIPTEXT, like Christian suggests, you have the excel-data as
simple text.
You have to parse the text into a cursor to populate it in a grid.
It could look like this (tested with Excel 97, Win XP)

<Snip>
LOCAL lcTmpFile   AS String
LOCAL lnFieldCnt  AS Integer
LOCAL lnCnt    AS Integer
LOCAL aStructure[1,4] AS Array

lcTmpFile= ForceExt( Sys(2015), "TMP" )
StrToFile( _CLIPTEXT, lcTmpFile )
lnFieldCnt= Occurs( Chr(9), MLine( _CLIPTEXT, 1 ) )  && Fields are delimited
with TAB

DIMENSION aStructure[ lnFieldCnt, 4 ]

FOR lnCnt= 1 TO lnFieldCnt
 aStructure[ lnCnt, 1]= "Field_"+Transform( lnCnt )
 aStructure[ lnCnt, 2]= "C"
 aStructure[ lnCnt, 3]= 100
 aStructure[ lnCnt, 4]= 0
ENDFOR

CREATE CURSOR curExcel FROM ARRAY aStructure
APPEND FROM (lctmpFile) TYPE DELIMITED WITH TAB
BROWSE
<Snip>

There may be other, easier ways to accomplish this.
Here are 2:

1. Simple import into a cursor (the traditional way).
IMPORT FROM "myExcelFile.XLS" TYPE XL5

2. Automation (the fancy way <s>)
loExcel= GetObject( "myExcelFile.XLS" )
loSheet= loExcel.Sheets(1)
? loSheet.Cells(1,1).Value
? loSheet.Cells(2,1).Value

48.  Here is an article that may help you recreate the indexes on your tables:

202520 FILE: Use CDX(),TAG(), and SYS(14) Function to Create an Index 
Utility
http://support.microsoft.com/?id=202520

49. If you still have the FPT file, then you can buy a third party tool that 
repairs memo fields.  Here are a few articles that list software companies 
that supply this software:

87688 PRB: "Not a Database File" Error Using a Database File
http://support.microsoft.com/?id=87688

189458 INFO: Third Party Utility Repairs FoxPro Record and Memo Data
http://support.microsoft.com/?id=189458

If the FPT file is truly missing and you have no backup, then you can make 
a table with memo field (call the table junk). Then rename the Junk.fpt to 
<tablename>.fpt.  You should then be able to open your table; however, all 
the data that was in the memo field will be lost. Clearly, this method is 
used as a last resort. 

50. Is "out of memory" the exact syntax of the message? 

Have you tried adding a SYS(3050) function to the code?  You might want to 
first try a very low number.  For example, SYS(3050,1,256).  If this does 
not help, I would try 5000000 (no commas) as the last parameter and work 
your way up 5000000 bytes at a time. 

I don't know what your code is doing, but I have seen the usage of 
SYS(1104) helpful when VFP is not releasing memory. For example, if you had 
a loop to import or export data, you might want to add a SYS(1104) before 
entering the loop or after exiting the loop.  Since I don't know what your 
code is doing, I am just offering this since it has helped others in the 
past. 

Here are two articles that offer more information on these functions:

Along with all the other suggestions you have received, you might want to 
use the SYS(3050) function to ensure the VFP is using internal memory 
buffers efficiently

176483 PRB: Large Amounts of RAM Seem to Process Data Slowly
http://support.microsoft.com/?id=176483

Also, this article might be helpful regarding the suggestions involving 
anti virus software:

321550 HOWTO: Optimize Visual FoxPro Applications While Using Norton 
AntiVirus
http://support.microsoft.com/?id=321550

I have two suggestions: First, add a SYS(3050) function to the SELECT-SQL 
command.  For example:

SELECT ID,NAME,DESC, SYS(3050,15000000) as junk FROM <TABLE> WHERE DESC 
LIKE 'WINTER%'

You might try values higher and lower than 15000000 in the last parameter.  
You can go as low as 256. Here is some more information on the SYS(3050) 
function:

176483 PRB: Large Amounts of RAM Seem to Process Data Slowly
http://support.microsoft.com/?id=176483

Second, you might try using an ATC() function in the SELECT-SQL command:

Fixing the memory leak is obviously the best route, but this might help

http://support.microsoft.com/?kbid=234562

51. SET ANSI OFF
SELECT * FROM Table WHERE sst LIKE '001'
SELECT * FROM Table WHERE sst == '001'

SET ANSI ON
SELECT * FROM x WHERE sst = '001'

(SET EXACT ON or OFF makes no difference in SQL queries)
 
52. If you are trying to print a Word .DOC file from Visual FoxPro, you need to 
use OLE automation.  You are controlling Word from within VFP using code 
causing Word to print the document and return back to VFP.

Here are some articles that should help get you started:

138205 HOWTO: Use OLE Automation with Microsoft Word
http://support.microsoft.com/?id=138205

176069 HOWTO: Print a Range of Pages in Word Using OLE Automation
http://support.microsoft.com/?id=176069

170393 HOWTO: Prevent Word Printing Error with OLE Automation
http://support.microsoft.com/?id=170393

194306 HOWTO: Make Word Print Duplex Using OLE Automation
http://support.microsoft.com/?id=194306

222101 HOWTO: Find and Use Office Object Model Documentation
http://support.microsoft.com/?id=222101

241942 HOWTO: Prevent Word Printing Error with BackgroundPrintingStatus 
Property
http://support.microsoft.com/?id=241942

Another options is to embed or link the Word document into a general field 
of a table. You can then use the Picture/ActiveX Bound control to print the 
general field that contains the Word document. 

52. You can use the MSCOMM32 actice x control to connect VFP to a serial
interface. Here's some
general information about VFP and COM ports.

HOWTO: Receive from the Serial Port by Using MScomm32.ocx.
http://support.microsoft.com/default.aspx?scid=140525
Also useful may be
HOWTO: Send to the Serial Port by Using Mscomm32.ocx.
http://support.microsoft.com/default.aspx?scid=139526
And of course,
HOWTO: Transmit and Receive Binary Data using MSCOMM32.
http://support.microsoft.com/default.aspx?scid=154741

53. automatic log display

Add a timer control to the form and set these properties:

Enabled=.f.
Interval=3000
Timer:
SKIP
thisform.Refresh

** You need to check for EOF() but you get the idea.

In the command button toggle the timer control on and off:

IF thisform.timer1.enabled=.t.
thisform.timer1.enabled=.f.
ELSE
thisform.timer1.enabled=.t.
endif

If you have a text boxes with a ControlSource attached to a table, you will 
see each record be displayed every three seconds. 

54. 174524 HOWTO: Retrieve and Insert HTML Into Memo Field
http://support.microsoft.com/?id=174524

>Automatic Application Updates over the Web with Visual FoxPro 7.0
>http://www.west-wind.com/presentations/wwCodeUpdate/codeupdate.asp

55. If you want a form window outside the screen for you application the forms
ShowWindow property should be set to 2 Top-level form.
The screen can the be hidden by including a Config.fpw file in the project
with the line SCREEN=OFF
Other forms launched from this main form can be ShowWindow=2 or
ShowWindow=1, combined with Desktop=.T. or .F. and WindowType=0 Modeless, or
WindowType=1 Modal.  A Top-level form can't be Modal too.

156088 HOWTO: Hide Desktop in Run-Time (.exe) VFP5 Application
http://support.microsoft.com/?id=156088

190350 HOWTO: Create Top-Level Splash Screen with No TaskBar Icon
http://support.microsoft.com/?id=190350

56.  on pad iv_window of iv_menu activate popup _mwindow

57.  Set your Column.InputMask to your picture, not the Text1 control.

thisform.oGrid.ColumnX.InputMask = "999,999.99"

58.  Hmm...if I add thisform.draw() after 'additem()' it 
works...go figure

I'm using my listbox as a display device for a given 
process and I'm trying to display it's progress and I'd 
like to select the latest action.  My problem is that the 
newest 'action item' isn't displayed right 
away...somtimes 'starting' and 'processing' appear at the 
same time when in fact there is a delay of a few 

minutes.  

Here's what I got:

method1:
thisform.addmsg("starting")
thisform.startprg()
thisform.addmsg("processing")
thisform.continue()
....

addmsg:
lparameters tmsg
thisform.lst1.additem(tmsg)
 
59. for a good list of icons:

http://www.coolarchive.com/
http://dir.yahoo.com/Arts/Design_Arts/Graphic_Design/Web_Page_Design_and_Layaout/Graphics/Icons/

60. playing sound

You can also use the MessageBeep API to play a WAV file:

193223 HOWTO: Use the MessageBeep API to Play System .WAV Files
http://support.microsoft.com/?id=193223

Here are two options:

DECLARE INTEGER sndPlaySound IN "winmm.dll" STRING lpszSoundName, INTEGER
uFlags
#DEFINE SND_NOWAIT 0x2000
#DEFINE SND_ASYNC 0x1
#DEFINE SND_SYNC 0x0
sndPlaySound("yourwavefile.wav", SND_NOWAIT + SND_ASYNC)
You can also use the native VFP SET BELL TO command:
SET BELL TO "yourwavefile.wav"
?? CHR(7)

61. 156788 FIX: Report Print Preview Illegible Under Windows NT
http://support.microsoft.com/?id=156788

62. and here is info on how to hide the program from the task bar ..
    http://support.microsoft.com/?id=175909

> > > If your application has only one form, here is another way to hide the
> > > application:
> > >
> > > From your main program call your form like this:
> > >
> > > _VFP.VISIBLE = .F.
> > > DO FORM MyFormName NOSHOW
> > > READ EVENTS
> > >
> > > Then from the Systray click or doubleclick you can show your form

In my case it is a simple form, here the code for the Resize:
IF THISFORM.WINDOWSTATE = 1 && Minimized
 THISFORM.HIDE()
ENDIF

The API code was only used to hide or show the taskbar icon, and for that I
used the ShowWindow API call:

Declare Integer ShowWindow in Win32API Integer hWnd, Integer nCmdShow
ShowWindow(_VFP.Hwnd, 0 )
ShowWindow(_VFP.Hwnd, 5 )

It hides the window (which is already minimized anyhow) but more
importantly, it also hides the taskbar icon, which is what I want.

I put the code in _screen.resize, and it simply checks _screen.WindowState
to see if we are minimized or not. If we are minimized, we hide the taskbar
icon. If not, we unhide and set AlwaysOnTop to .T. and then to .F. so that
the VFP windows is made visible. There is an API call that makes it the
foreground app, but I haven't had the time to find out which that is, so
AlwaysOnTop is good enough for now. Before it goes into production I'll find
tune it to do things like checking to see if the window is already visible
before setting it visible, checking to see if the window is on top before
setting it on top, etc.

Hiding the VFP window by setting _Screen.Visible to .F. also hides the
systray icon, so that was not an option.

63. For registry read/writes, I use Windows Shell Scripting, which works quite
well and neatly hides any API calls, e.g.

oSh = CreateObject("WScript.Shell")
cKey =  "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\WinLogon\"
cValue = "DefaultUserName"
cData = "John"
oSh.RegWrite(cKey + cValue, cData)
? oSh.RegRead(cKey + cValue)

64. As for printer driver memory leaks, have you tried using _fpreset()
before and after any printer/report-related commands ...

Declare _fpreset in msvcrt.dll && in your main.prg

Then, before and after any printer or report commands, issue _fpreset().

For more info, check out KB article Q183522.

65. DECLARE integer MessageBox IN User32 as MBox;
integer hwnd, string lpText, string lpCaption, integer uType
?mbox(_screen.HWnd,"Hi There","Testing",0)

66. http://www.utmag.com/March2002/

see article: "VFP and Winsock: Desmystifying"

Directly communication via that TCP/IP address might be another options.  
See this white paper:

http://www.west-wind.com/presentations/internetenabling/InternetEnabling.htm

MSMQ is another viable option
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msmq/msmq_overview_4ilh.asp


67. While I don't have a help file to send you, I did find some code on 
www.universalthread.com.
Go to UT, click on the Download icon and choose VFP as the product.  Search 
for the following:

  I have just download a freeware DynaZipAX from
>http://www.jassing.com/vfp.htm which is a zip program 

68. you've identified the cmdSave.Click on one of your forms as being one of the processes that is too slow.  This method contains hundreds of lines of code, and calls other methods and user-defined functions.

69. you've identified the cmdSave.Click on one of your forms as being one of the processes that is too slow.  This method contains hundreds of lines of code, and calls other methods and user-defined functions.

You add the statement:
set coverage to save.log
at the top of the cmdSave.Click, and
set coverage to
just before any exit points (return statements).

1) create table profiler free ;
(elapesed N(11,3), dummy c(1), procname c(30), ;
linenum N(5,0), filename c(30))

2) Import the log file using this:
append from save.log delimited

3) Browse the profiler table to see that everything was imported correctly (not a necessary step, obviously)

69. foxpro event firing sequence:

dataenvironment.beforeopentables
form.load
 dataenvironment.init
 object.init		&& from innermost to outermost
  form.init
   form.activate	&& form+objects displayed
    object.when		&& follow tab order
     form.gotfocus
      object.gotfocus
       object.valid
      object.lostfocus
   form.queryunload	&& form closed by "x"
  form.destroy
 object.destroy		&& from outermost to innermost
form.unload
dataenvironment.afterclosetables
dataenvironment.destroy

70. 254478 Use the ActiveX Progress Bar OCX Control
http://support.microsoft.com/?id=254478

259296 HOWTO: Display a Progress Bar in a Status Bar
http://support.microsoft.com/?id=259296

167192 HOWTO: Create a Progress Indicator Using Threed Panel Control
http://support.microsoft.com/?id=167192

Check out the thermometer foundation class located in your foxpro directory.
The file is ...\Samples\Solution\Ffc\therm.scx, this is probably what you're
looking for

71. You might want to check out Mark McCasland's CursorAdaptor class at http://www.mctweedle.com . He has a whole set of samples for it's use.

72.  I was able to insert a page break with
this VFP code:

oExcel = CREATEOBJECT("Excel.Application")
oExcel.Visible = .T.    && For testing
oBook = oExcel.Workbooks.Add()
oBook.Sheets(1).Cells(4, 4).Select()
oExcel.ActiveWorkbook.ActiveSheet.HPageBreaks.Add(oBook.Sheets(1).Cells(5,
5))

73. 138107 PRB: Standard Toolbar Visible in .Exe
http://support.microsoft.com/?id=138107

74. LOCAL lcExecutable, lcShortLNK, lcDesktopFolder
LOCAL Array laShortCutInfo[2,2]

laShortcutInfo[1,1] = "MyFirstExe.exe"
laShortcutInfo[1,2] = "MyFirstExe.lnk"
laShortcutInfo[2,1] = "MySecondExe.exe"
laShortcutInfo[2,2] = "MySecondExe.lnk"
oShell = create("wscript.shell")

if type('oShell') = "O" and not isnull(oShell)
   lcDesktopFolder= addbs(oShell.SpecialFolders("desktop"))
   for lnI = 1 to alen( laShortcutInfo,1)
      lcExecutable = laShortcutInfo[lnI,1]
      lcShortLNK = laShortcutInfo[lnI,2]

      if file( (lcExecutable) )
         oShortCut = oShell.CreateShortcut(
addbs(lcDesktopfolder)+lcShortLNK)

         With oShortcut
            .Targetpath= addbs(fullpath( curdir()))+lcExecutable
            .WorkingDirectory= addbs(fullpath( curdir()))
            .WindowStyle = 2
            .save()
         endwith
      endif
   endfor
messagebox("Shortcut(s) created on your desktop"+chr(13)+"maybe you will
have to adjust some settings"+chr(13)+"Check manual Chapter:
'INSTALLATION'",48+16, "At your Service")
else
messagebox("Creating shortcut(s) failed"+chr(13)+"You will have to do this
yourself"+chr(13)+"See manual for Installation",48+16, "At your Service")
endif

75.  
CREATE CONNECTION CONFRIENDS ; 
   DATASOURCE "Friends" ; 
   USERID "Eldor" ; 
   PASSWORD "guess"

****
=DBSetProp('CONFRIENDS', 'Connection', 'Asynchronous', .T.)
=DBSetProp('CONFRIENDS', 'Connection', 'BatchMode', .T.)
=DBSetProp('CONFRIENDS', 'Connection', 'Comment', '')
=DBSetProp('CONFRIENDS', 'Connection', 'DispLogin', 1)
=DBSetProp('CONFRIENDS', 'Connection', 'ConnectTimeOut', 15)
=DBSetProp('CONFRIENDS', 'Connection', 'DispWarnings', .F.)
=DBSetProp('CONFRIENDS', 'Connection', 'IdleTimeOut', 0)
=DBSetProp('CONFRIENDS', 'Connection', 'QueryTimeOut', 0)
=DBSetProp('CONFRIENDS', 'Connection', 'Transactions', 1)
=DBSetProp('CONFRIENDS', 'Connection', 'Database', '')


76.
REATE SQL VIEW "RV_CARDS" ; 
   REMOTE CONNECT "conFriends" ; 
   AS SELECT * FROM dbo.tblCards Tblcards

DBSetProp('RV_CARDS', 'View', 'UpdateType', 1)
DBSetProp('RV_CARDS', 'View', 'WhereType', 3)
DBSetProp('RV_CARDS', 'View', 'FetchMemo', .T.)
DBSetProp('RV_CARDS', 'View', 'SendUpdates', .T.)
DBSetProp('RV_CARDS', 'View', 'UseMemoSize', 255)
DBSetProp('RV_CARDS', 'View', 'FetchSize', 100)
DBSetProp('RV_CARDS', 'View', 'MaxRecords', -1)
DBSetProp('RV_CARDS', 'View', 'Tables', 'dbo.tblCards')
DBSetProp('RV_CARDS', 'View', 'Prepared', .F.)
DBSetProp('RV_CARDS', 'View', 'CompareMemo', .T.)
DBSetProp('RV_CARDS', 'View', 'FetchAsNeeded', .F.)
DBSetProp('RV_CARDS', 'View', 'FetchSize', 100)
DBSetProp('RV_CARDS', 'View', 'Comment', "")
DBSetProp('RV_CARDS', 'View', 'BatchUpdateCount', 1)
DBSetProp('RV_CARDS', 'View', 'ShareConnection', .F.)
*!* Field Level Properties for RV_CARDS
* Props for the RV_CARDS.card_id field.
DBSetProp('RV_CARDS.card_id', 'Field', 'KeyField', .T.)
DBSetProp('RV_CARDS.card_id', 'Field', 'Updatable', .F.)
DBSetProp('RV_CARDS.card_id', 'Field', 'UpdateName', 'dbo.tblCards.Card_id')
DBSetProp('RV_CARDS.card_id', 'Field', 'DataType', "I")
* Props for the RV_CARDS.friend_id field.
DBSetProp('RV_CARDS.friend_id', 'Field', 'KeyField', .F.)
DBSetProp('RV_CARDS.friend_id', 'Field', 'Updatable', .T.)
DBSetProp('RV_CARDS.friend_id', 'Field', 'UpdateName', 'dbo.tblCards.Friend_id')
DBSetProp('RV_CARDS.friend_id', 'Field', 'DataType', "I")
* Props for the RV_CARDS.occasion field.
DBSetProp('RV_CARDS.occasion', 'Field', 'KeyField', .F.)
DBSetProp('RV_CARDS.occasion', 'Field', 'Updatable', .T.)
DBSetProp('RV_CARDS.occasion', 'Field', 'UpdateName', 'dbo.tblCards.occasion')

77. parameter passing and return values from form

add custom propery retval to myform.

form.init()
lparameters arg1, arg2

form.unload()
return thsiform.retval

do form myform to retval


78. * Start one/single occurence/instance of this program. Test this using
Win32API
DECLARE long FindWindow IN Win32API integer, string

DECLARE long ShowWindow in Win32API long, long
DECLARE long SetForegroundWindow in Win32API long

#DEFINE TITLE "<Your application title>"
#DEFINE SW_RESTORE 9  && Show application maximized

LOCAL lnHandle
lnHandle = FindWindow(0, TITLE)  && Check if window exist
IF lnHandle > 0
   * Application is running. Show the running one and quit
this one
   ShowWindow(lnHandle, SW_RESTORE)
   SetForegroundWindow(lnHandle)
   RETURN
ENDIF

79. programmatically create form:

oForm = CREATEOBJECT("Form")
oForm.AddObject("Header1","NameHeader")
oForm.Header1.Left = 1

oForm.Caption = "Listbox Headers Work Great!"

FOR EACH oControl IN oForm.Controls
     oControl.Visible = .T.
ENDFOR
oForm.Show(1)

CLEAR ALL
*** end of main program

DEFINE CLASS TestForm as Form
     custom_property = ""

     ADD OBJECT Edit1 as Editbox ;
         WITH Left = 5, Top = 5

     PROCEDURE Init
          THIS.AddProperty("aItems[1,3]")
     ENDPROC

     PROCEDURE custom_method
	THIS.custom_property = "init"
     ENDPROC
ENDWITH
ENDDEFINE

DEFINE CLASS ColorHeader AS HeaderButton
     Caption = "Color"
     PROCEDURE Click
          THIS.PARENT.List1.SortOrder = "TheColor"
          THIS.PARENT.List1.Direction = THIS.LastDirection          
          DODEFAULT()
     ENDPROC
ENDDEFINE

80. Convert SCX into PRG, view form code:

DO (_BROWSER) WITH "yourform.scx"
and then use the "View Class Code" button.

Yes! Open the form in the Class Browser and click on the 4th icon (Show
classcode)  and the Form with all methods and properties will be displayed
at once.

81. passing array as parameter

oArrayPar=CREATEOBJECT("custom")
oArrayPar.AddProperty("myArray[1]")
do form myInputform  with oArrayPar

***************************
*Init method of myInputForm
***************************
lparameter toArrayPar
if Type("toArrayPar")="O"
    thisform.oParameter=toArrayPar
endif

In the Release-Method of myInputform you should copy the Array to the
Parameterobject

=acopy(myProcessedArray,thisform.oParameter) &&copies the Array to the
caller object
thisform.oParameter=.null. && releases the reference of the caller object
because we don't like hanging references

82. to browse a sql server table

go next:
select xx.pk, xx.amount, count(*), sum(yy.amount) as recno 
from tx xx, tx yy
where xx.pk >= yy.pk and yy.pk > @curpk
group by xx.pk, xx.amount
order by xx.pk

pk   amount       recno       balance                                  
---- ------------ ----------- ----------
A    10.00        1           10.00
B    20.00        2           30.00
C    30.00        3           60.00

go previous:
select xx.pk, xx.amount, count(*), sum(yy.amount) as recno 
from tx xx, tx yy
where xx.pk <= yy.pk and yy.pk < @curpk
group by xx.pk, xx.amount
order by xx.pk desc

pk   amount       recno       balance                                  
---- ------------ ----------- ----------
DD   50.00        1           50.00
D    40.00        2           90.00
C    30.00        3           120.00

83. to call a stored procedure using OLEDB:

**FORM LOAD
#Include adovfp.h
*#DEFINE ADCMDSTOREDPROC      &H0004
WITH Thisform
   .oCn = CREATEOBJECT("ADODB.Connection")
   .oRS = CREATEOBJECT("ADODB.RecordSet")
   .oCmd = CREATEOBJECT("ADODB.Command")
   IF VARTYPE(.oCn)="O" AND VARTYPE(.oRS) = "O"
      .oCn.ConnectionString = "Provider=SQLOLEDB;User ID=user;Password=pass;Initial Catalog=Cap;Data Source=192.168.3.2"
      .oCn.Open()
      IF .oCn.State = 1

         WITH .oCmd
            .CommandText = 'usp_AT_Test2'
            .Activeconnection = Thisform.ocn
            .CommandType = 4 &&adCmdStoredProc
         ENDWITH
         *SET STEP ON
         .oCmd.Parameters("@custno").Value = 'PA9035'
         .oRS = Thisform.oCmd.Execute
         SET STEP ON


*!*            WITH .oRS
*!*               .ActiveConnection = Thisform.oCn
*!*               .CursorType = 3
*!*               .Open("SELECT * FROM AT_Comments")
*!*            ENDWITH
      ENDIF
   ENDIF
ENDWITH
***********************************************************************
**FORM INIT

WITH ThisForm
   .oledtcATComments.Object.RecordSet = .oRS
   .oledtcATComments.Object.Refresh()
   .oleGrdATComments.Object.DataSource = .oledtcATComments.Object
   .oleGrdATComments.Object.Refresh()
ENDWITH

84.

FUNCTION tbsave
   *
   * save the settings
   *
   PUBLIC ARRAY gaTBSets[11, 2]
   *
   LOCAL lnCntr
   *
   *-- Fill an array with toolbar names.
   *
   gaTBSets[ 1, 1] = "Color Palette"
   gaTBSets[ 2, 1] = "Database Designer"
   gaTBSets[ 3, 1] = "Form Controls"
   gaTBSets[ 4, 1] = "Form designer"
   gaTBSets[ 5, 1] = "Layout"
   gaTBSets[ 6, 1] = "Print Preview"
   gaTBSets[ 7, 1] = "Query Designer"
   gaTBSets[ 8, 1] = "Report Controls"
   gaTBSets[ 9, 1] = "Report Designer"
   gaTBSets[10, 1] = "Standard"
   gaTBSets[11, 1] = "View Designer"
   *
   *-- Check toolbars for their visibility
   *-- If so, store that setting in the 2nd column.
   *-- and hide the toolbar
   *
   _SCREEN.LOCKSCREEN = .T.
   *
   FOR lnCntr = 1 TO ALEN(gaTBSets,1)
      IF WEXIST( gaTBSets[lnCntr,1] )
         gaTBSets[ lnCntr,2 ] = .T.
         HIDE WINDOW (gaTBSets[lnCntr,1])
      ELSE
         gaTBSets[ lnCntr,2 ] = .F.
      ENDIF
   ENDFOR

   _SCREEN.LOCKSCREEN = .F.
   *
ENDFUNC

***********
FUNCTION TBRest
   *
   *-- Make the toolbars visible that are stored as previously visible in the gaTBSets array
   *
   LOCAL lnCntr
   *
   _SCREEN.LOCKSCREEN = .T.
   *
   FOR lnCntr = 1 TO ALEN( gaTBSets ,1 )

      IF gaTBSets[ lnCntr, 2 ]

         SHOW WINDOW ( gaTBSets[ lnCntr, 1 ] )

      ENDIF

   ENDFOR

   _SCREEN.LOCKSCREEN = .F.

ENDFUNC

85.
> thisform.olecontrol2.reportfilename = xReportName
> thisform.olecontrol2.datafiles(0) = fnd
> thisform.olecontrol2.connect = 'DSN=TEMP'
> thisform.olecontrol2.destination = 0
> thisform.olecontrol2.printreport

if not 'FOXTOOLS'$set('LIBRARY')
 set libr to sys(2004)+"FoxTools"
endi

foxwind=mainhwnd()
getactive=regfn('GetActiveWindow','','I')
do whil .t.
 if foxwind=callfn(getactive)
  exit
 endi
endd

86.

Automating the built-in fax server

lcMyServer="\\W2K"    && your PC name
lcDokument=GetFile()

loF=CreateObject("FaxServer.FaxServer")
lnHandle=loF.Connect(lcMyServer)
loD=loF.CreateDocument(FullPath(lcDokument))
loD.FaxNumber="+420499320708"
loD.Send()
loF.Disconnect() 

87.

PROCEDURE newguid
	LOCAL lcPK,lcBuffer,i,lnHex,lnUpper,lnLower
	DECLARE INTEGER CoCreateGuid IN OLE32.DLL STRING @lcBuffer
	lcBuffer=SPACE(17)
	lcPK=SPACE(0)
	IF CoCreateGuid(@lcBuffer) = 0
		FOR i=1 TO 16
			lnHex=ASC(SUBSTR(lcBuffer,i,1))
			lnUpper=INT(lnHex/16)
			lnLower=lnHex-(lnUpper*16)
			lcPK=lcPK+SUBSTR('0123456789ABCDEF',lnUpper+1,1)+;
				SUBSTR('0123456789ABCDEF',lnLower+1,1)
		ENDFOR
	ENDIF
	RETURN lcPK
	ENDPROC

88.

To auto-refresh an image control inside a grid.column:

grid.init():
this.setall("DynamicFontBold","this.updatepic()","column")

grid.updatepic():
with thisform.grid.column1
	.image1.refresh()
endwith
return .f.

89. Only one instance allowed

At the beginning of the program: 

*-- Turn off DDE error messages.
=dddesetoption( "SAFETY", .f.)

*-- Check to see if DDE service was already started.
achan = ddeinitiate( "pkf1", "System" )
IF achan # -1
   *-- You'll probably want a more informative message.
   WAIT WINDOW "Program already running."
   QUIT
ENDIF

*-- If we got here, the service was not started, so start it.
=ddesetservice( "pkf1", "DEFINE" )

( ... main body of code goes here ... )

*-- At the end of the program, turn off the service, so we can get in
*-- next time.
=ddesetservice( "pkf1", "RELEASE" )

90.
To allow the classbrowser to operate from a network directory, patch
classbrowser.scx, in the init() event:

IF NOT EMPTY(this.cBrowserTable)
	lcBrowserDBF=this.cBrowserTable
ELSE
	lcBrowserDBF=this.cProgramName
ENDIF

* added by chang
local m.xx, m.ff
m.xx=fullpath(curdir())
m.ff=m.xx+sys(2015)+".txt"
m.hdl=fcreate(m.ff)
if m.hdl < 0
	wait window "Unable to write to browser.dbf at "+m.xx
	return .f.
endif
fclose(m.hdl)
delete file (m.ff)
lcBrowserDBF=m.xx+"browser.dbf"

lcBrowserDBF=FORCEEXT(lcBrowserDBF,"dbf")
lcBrowserFPT=FORCEEXT(lcBrowserDBF,"fpt")

this.cBrowserTable=lcBrowserDBF

91.
 XML ADAPTER TEST #1
oo=CREATEOBJECT("XmlAdapter")
XML = CREATEOBJECT("MSXML2.ServerXMLHTTP")
xml.open("GET","http://www.nhc.noaa.gov/nhc_at1.xml",.f.)
xml.send
xms=xml.responsexml
oo.LoadXML(xms.xml,.f.,.t.)
CREATE CURSOR CHANNEL (tITLE M,LINK M,DESCRIPTION M,COPYRIGHT M, LANGUAGE 
M,image M,lastBuildDate M,Item M)
CREATE CURSOR item(title m, link m, description m) && content of item 
collection

OO.ADDTABLESCHEMA("channel") && RSS Root
oo.AddTableSchema("item") && Item detail record

t1=oo.Tables.Item(1)
t1.tocursor(.t.,"channel") && append to channel cursor (header record)

SELECT (t1.alias)
BROWSE

T2=OO.TABLES.ITEM(2)
T2.TOCURSOR(.T.,"item") && append to item cursor (many records)

SELECT (t2.alias)
BROWSE FIELDS cTitle=PADR(Title,45), cLink=PADR(LINK,70), cDesc = 
PADR(Description,45)

92.
Subpages (3): Cantonese Input Linux Work
Comments