Thursday, May 22, 2008

Save Excel to Excel 5

Foxpro gives error "Invalid Excel file format", when appending from Excel file which was created in mac version. To append this file, we need to save it in older version (Excel 5).
I use the following code to save file in Excel 5.


lcx = Getfile('xls')

lcfname = JUSTFNAME(lcx)

lcsave = FULLPATH(CURDIR()) +lcfname + '_5.xls'
loExcel = CREATEOBJECT("Excel.Application")
lowb = loExcel.Workbooks.Open(lcx)
lowb.SaveAs(lcsave, 39)
loexcel.Quit()
loexcel = null

Wednesday, May 14, 2008

Trace messages in IE

To view ASP.net Ajax , Sys.Debug.trace messages in IE, put this markup near the end of the page.

<textarea id="TraceConsole" rows="20" cols="60"></textarea>

Wednesday, May 7, 2008

Create desktop shortcut to a Visual FoxPro application

Microsoft KB -

creates desktop shortcut to a Visual FoxPro application


http://support.microsoft.com/kb/q238553/

Tuesday, May 6, 2008

Update Excel sheet from Foxpro

My client wants to get tracking number on the spreadsheet they supplied. Tracking numbers are in foxpro cursor created by exporting from Fedex software.


lca = ALIAS() && table created from Fedex Export


lcxls = GETFILE('xls')

ConnectionString = [Provider=Microsoft.Jet.OLEDB.4.0;Data Source=]+lcxls +[;Extended Properties="Excel 8.0;HDR=Yes;"]
oConn = CREATEOBJECT('adodb.Connection')
oConn.OPEN(ConnectionString)
ors = CREATEOBJECT('adodb.recordset')
ors.LockType = 3

lcsql = "select * from [Sheet1$] where track is null"
ors.OPEN(lcsql, oConn)

DO WHILE NOT ors.EOF
lcPid = TRANSFORM(ors.Fields(0).value)
SELECT (lca)
LOCATE FOR pid = lcpid
IF FOUND()
ors.FIELDS("Track").VALUE = ALLTRIM(track)
ors.FIELDS("Shipdate").VALUE = shipdate
ENDIF
ors.UPDATE()
ors.movenext()
ENDDO
ors.CLOSE()
oConn.CLOSE()

RETURN

Monday, May 5, 2008

Remove line numbers from code listing

Sometime code listed on web page may contain line numbers. I have used regular expression to remove the line numbers from the code.

LPARAMETERS tcString

LOCAL loRegex as "vbscript.regexp"
LOCAL ARRAY laLines[1]
LOCAL lnLines, lcLine, lcStr, lni

loRegex = CREATEOBJECT('vbscript.regexp')
loRegex.GLOBAL = .T.
loRegex.IgnoreCase = .F.
loRegex.Multiline = .T.

IF EMPTY(tcString)
tcString = _CLIPTEXT
ENDIF

lnLines = ALINES(laLines, tcString)

lcStr = ""
loRegex.PATTERN = "^\s*(\d+:?)(.*)"
FOR lni = 1 TO lnLines
lcLine = laLines[lnI]
IF EMPTY(lcLine)
*!* lcStr = lcStr + lcLine
ELSE
lcStr = lcStr + loRegex.REPLACE(lcLine, "$2") + CHR(13) + CHR(10)
ENDIF
ENDFOR


WAIT CLEAR
CREATE CURSOR curtmpfile (CODE m)
INSERT INTO curtmpfile VALUES (lcStr)

MODIFY MEMO CODE

RETURN

Friday, May 2, 2008

Missing Index in Sql Server

The following query displays required index on sql database.

use databse
go

select *

from sys.dm_db_missing_index_details
where database_id = db_id()

Thursday, May 1, 2008

Open windows explorer from Foxpro

Open windows explorer from Foxpro in Current Directory

LOCAL loshell as Shell32.application
loshell = CREATEOBJECT('shell.application')
loShell.Explore(FULLPATH(CURDIR()))
loShell = null

Foxpro Regular Expression

Below code converts Sql code generated for Insert from Management studio into Foxpro code.
Right click on a table in SSMS -> Script table As -> Insert To -> New Query Editor Window

Below was generated from Publishers table from Pubs database

INSERT INTO [pubs].[dbo].[publishers]
([pub_id]
,[pub_name]
,[city]
,[state]
,[country])
VALUES
(<pub_id, char(4),>
,<pub_name, varchar(40),>
,<city, varchar(20),>
,<state, char(2),>
,<country, varchar(30),>)


Select all & Copy

In foxpro command window
lcStr = _cliptext
This will put the generated code in clipboard.



loR = CREATEOBJECT('vbscript.regexp')
lor.Global = .t.
lor.Multiline = .t.
lor.IgnoreCase = .t.
lor.Pattern = "(,\s\w+\(?\d*\)?,\>)"
lcstr = lor.Replace(lcSTr, '')
lcstr = STRTRAN(lcStr, '<', '?')

This is what will be the value of lcStr after executing above code

INSERT INTO [pubs].[dbo].[publishers]
([pub_id] ,[pub_name] ,[city] ,[state] ,[country])
VALUES
(?pub_id ,?pub_name ,?city ,?state ,?country)