Converting FoxPro code.

577 views
Skip to first unread message

Michael Green

unread,
Jan 12, 2011, 10:33:55 AM1/12/11
to Harbour Users
I use MS FoxPro Unix 2.6 at work. However I am trying to convert the
system (running on FreeBSD) to Harbour. I've installed Harbour and
compiled some test programs but when I try to compile the existing
system system I run into a variety of code incompatibilities.

Can anyone direct me to a source of code equivalences?


Additionally can some kind soul advise on converting this FoxPro code:

store "Y" to contv
do while contv = 'Y'
&&create blank array for outstanding treatment
sele treatmnt && structure = code, c, 8; comment, c, 25; done, l.
dime treatv(15,3)

store 1 to countv
do while countv < 16
store 0000000 to treatv(countv,1)
store space(len(code)) to treatv(countv,2)
store space(len(comment)) to treatv(countv,3)
&& treatv(countv,4) is .f. by default
store countv+1 to countv
enddo


&& fill array with outstanding treatment

Thanks, regards, Michael Green

Massimo Belgrano

unread,
Jan 12, 2011, 10:53:54 AM1/12/11
to harbou...@googlegroups.com
Hi Michael Green
try follow
hbmk2 fox.hbp
creating hbp you can also run hbide and open your fox.hbp

------------------------.....fox.hbp
fox.prg
-----------------fox.prg--
func main
store "Y" to contv
do while contv = 'Y'
  &&create blank array for outstanding treatment
  sele treatmnt && structure = code, c, 8; comment, c, 25; done, l.
  private treatv[15,3]

  store 1 to countv
  do while countv < 16
     store 0000000 to treatv[countv,1]
     store space(len(code)) to treatv[countv,2]
     store space(len(comment)) to treatv[countv,3]
     && treatv[countv,4] is .f. by default
     store countv+1 to countv
  ENDDO
enddo
 return



2011/1/12 Michael Green <michael...@gmail.com>

--
Massimo Belgrano

Michael Green

unread,
Jan 12, 2011, 4:05:37 PM1/12/11
to Harbour Users
A BIG thanks for that.

Michael Green

unread,
Jan 14, 2011, 7:54:25 AM1/14/11
to Harbour Users
As a result of the advice above I was able to convert my system so
that it now 'compiles' without error, but i now get these errors :

<snip>
Compiling module 'prrepcca.prg'...
Lines 8123, Functions/Procedures 148
Generating C source output to 'prstart.c'... Done.
./prstart.o(.data+0x458): undefined reference to `HB_FUN_SYS'
./prstart.o(.data+0x1738): undefined reference to `HB_FUN_TREATV'
./prstart.o(.data+0x2368): undefined reference to `HB_FUN_CODEV'
./prstart.o(.data+0x26d8): undefined reference to `HB_FUN_TRTARRV'
./prstart.o(.data+0x2c88): undefined reference to `HB_FUN_ACCMENU'
./prstart.o(.data+0x2e58): undefined reference to `HB_FUN_APPOINTSAV'
./prstart.o(.data+0x2f28): undefined reference to `HB_FUN_PRREPNPV'
./prstart.o(.data+0x2fc8): undefined reference to `HB_FUN_PAV'


How do I start to start to analyse and fix the problems the messages
reference?

Massimo Belgrano

unread,
Jan 14, 2011, 8:20:00 AM1/14/11
to harbou...@googlegroups.com
IMO This are your function missed in your source 
search and add to fox.hbp

2011/1/14 Michael Green <michael...@gmail.com>

--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users



--
Massimo Belgrano

Michael Green

unread,
Jan 14, 2011, 10:19:53 AM1/14/11
to Harbour Users
Thank you so much for your quick and helpful response.

Michael Green

unread,
Jan 17, 2011, 9:55:20 AM1/17/11
to Harbour Users
I have now converted most of my FoxPro application into Harbour code.
This is a list of the problems I had and how I solved them :

Compile time errors

1. ; (line continuation chr) in text areas. Move semicolons out of
text areas.

2. Differences in array syntax. Dimension to private, round brackets
to square.
Example:
dime arrayv(3,5) && FoxPro
private arrayv[3,5] && Harbour

3. recno(0) (Fox) vs set softseek on (Harbour).

4. 'Display' doesn't need the 'fields' clause.

5. 'Browse' not supported, browse().

6. Scroll() function not supported.

7. Errors in the form " undefined reference to `HB_FUN_TREATV'" mean
that Harbour cannot find a udf named treatv(). Typically this will be
because a FoxPro array variable hasn't been reformatted. So, for
instance a line still has
treatv(blah, blah), rather than treatv[blah, blah]. Also the FoxPro
sys() functions will all trigger this (HB_FUN_SYS).
Use grep to identify the file ($ grep -ly 'treatv(' *.prg ), then edit
the file indicated and use the search function to find the missed
array name.

8. Sys(2) = seconds(). Seconds() return numeric, sys(2) returns
character, so val(sys(2)) = seconds().

9. Sys(2002) = set cursor off.

10. Sys(2002,1) = set cursor on.



Run time errors

1. Permissions problems can cause hard to understand error messages. #
chmod a+rw * is the way to go.

2. Memory variable (.mem) files aren't compatible, they have to be
recreated.


I hope this may help anyone who follows the same FoxPro to Harbour
path. If anyone notices something I missed feel free to reply. Thanks
especially to Massimo.

Massimo Belgrano

unread,
Jan 17, 2011, 10:29:52 AM1/17/11
to harbou...@googlegroups.com


2011/1/17 Michael Green <michael...@gmail.com>

Thanks to to You to share your experiences
can you do  a little demo who show sample of your problem
From  foxpro to  harbour

Are you using hbide for visual editing your source?


--
Massimo Belgrano

Przemysław Czerpak

unread,
Jan 17, 2011, 5:43:38 PM1/17/11
to harbou...@googlegroups.com
On Mon, 17 Jan 2011, Michael Green wrote:

Hi,

> I have now converted most of my FoxPro application into Harbour code.
> This is a list of the problems I had and how I solved them :
> Compile time errors
> 1. ; (line continuation chr) in text areas. Move semicolons out of
> text areas.

Can you show some code examples illustrating the problem?

> 2. Differences in array syntax. Dimension to private, round brackets
> to square.
> Example:
> dime arrayv(3,5) && FoxPro
> private arrayv[3,5] && Harbour

Seems that we can hide such difference using PP rules. We have hbfoxpro.ch
file where we can add them so later is enough to compile FP code using
-u+hbfoxpro.ch harbour compiler or hbmk2 switch:

=============================================================================
#xtranslate __FP_DIM( <exp> ) => <exp>
#xtranslate __FP_DIM( <!name!>( <dim,...> ) ) => <name>\[ <dim> \]

#command PUBLIC <var1> [, <varN> ] => ;
<@> PUBLIC __FP_DIM( <var1> ) [, __FP_DIM( <varN> ) ]
#command PRIVATE <var1> [, <varN> ] => ;
<@> PRIVATE __FP_DIM( <var1> ) [, __FP_DIM( <varN> ) ]
#command DIMENSIONS <!name1!>( <dim1,...> ) [, <!nameN!>( <dimN,...> ) ] => ;
PRIVATE <name1>\[ <dim1> \] [, <nameN>\[ <dimN> \] ]
=============================================================================

This rules should allow to use:
() instead of [] in array declarations, i.e.:

publ ar1( 100, 200 ), ar2( 200 )
publ v1, v2 := 100, ar3( 100, 200 ), ar4( 200 )
priv v3, ar5( 100, 200 ), v4, v5, ar6( 200 )
dime ar10( 100, 200 ), ar11( 200 )

Questions:
Does FP allows to use () as index operators to access array items?
Does FP has some other type of declaration (i.e. LOCAL) which also
can use () to define array dimensions?

> 3. recno(0) (Fox) vs set softseek on (Harbour).

Can you describe more precisely the difference?

> 4. 'Display' doesn't need the 'fields' clause.

This can be resolved by such PP rule:

#command DISPLAY [[FIELDS] <v,...>] [<off:OFF>] ;
[<prn:TO PRINTER>] [TO FILE <(f)>] ;
[FOR <for>] [WHILE <while>] [NEXT <next>] ;
[RECORD <rec>] [<rest:REST>] [<all:ALL>] => ;
__dbList( <.off.>, { <{v}> }, <.all.>, ;
<{for}>, <{while}>, <next>, ;
<rec>, <.rest.>, <.prn.>, <(f)> )

> 5. 'Browse' not supported, browse().

#command BROWSE => Browse()

but I guess BROWSE command in FP supports some additional clauses which
should be implemented too.

> 6. Scroll() function not supported.

???
Scroll() is standard Clipper and Harbour function. It's fully supported.
What does not work for you?

> 7. Errors in the form " undefined reference to `HB_FUN_TREATV'" mean
> that Harbour cannot find a udf named treatv(). Typically this will be
> because a FoxPro array variable hasn't been reformatted. So, for
> instance a line still has
> treatv(blah, blah), rather than treatv[blah, blah]. Also the FoxPro
> sys() functions will all trigger this (HB_FUN_SYS).

So I guess that FP also allows to access array items using () as
array index operator. Am I right or it was only from declaration?

> 8. Sys(2) = seconds(). Seconds() return numeric, sys(2) returns
> character, so val(sys(2)) = seconds().
> 9. Sys(2002) = set cursor off.
> 10. Sys(2002,1) = set cursor on.

Viktor already created SYS() function in hbfoxpro library with
such few entries but FP users should add other ones which exist
in FP.

> 2. Memory variable (.mem) files aren't compatible, they have to be
> recreated.

Probably we can add some simple converted though I do not think it's
critical problem.

> I hope this may help anyone who follows the same FoxPro to Harbour
> path. If anyone notices something I missed feel free to reply. Thanks
> especially to Massimo.

If FP users participate in adding PP rules to hbfoxpro.ch, adding
missing functions to hbfoxpro library and extending existing one
then we can probably address most of FP features and syntax.
I do not know FP so I cannot help here but I can help to resolve
clearly defined problems.

best regards,
Przemek

Michael Green

unread,
Jan 18, 2011, 6:18:48 AM1/18/11
to Harbour Users
@ Przemysław Czerpak

Thanks for your detailed post. I was unaware of this FoxPro
compatibility functionality. I suspected something like this might
exist but Goggling and browsing didn't turn it up.

In the end I'm happier trying to keep things simple. The conversion
process didn't take long. Most of the time was spent working out the
equivalences.

Now that my code is running in Harbour what concerns me most is the
possibility of table (.dbf) corruption, as my tables are all as
created in FoxPro Unix. I'm running FreeBSD 7.2 and the ported version
of Harbour is 1.0.1 Intl. (Rev. 9429). Does anyone have any experience
with FoxPro tables (.dbf) when modified by version 1.0.1? Is there a
recommendation to always convert to Harbour created tables?

Anyway, thanks a lot.

Przemysław Czerpak

unread,
Jan 18, 2011, 6:37:01 AM1/18/11
to harbou...@googlegroups.com
On Tue, 18 Jan 2011, Michael Green wrote:

Hi,

> Now that my code is running in Harbour what concerns me most is the


> possibility of table (.dbf) corruption, as my tables are all as
> created in FoxPro Unix. I'm running FreeBSD 7.2 and the ported version
> of Harbour is 1.0.1 Intl. (Rev. 9429). Does anyone have any experience
> with FoxPro tables (.dbf) when modified by version 1.0.1? Is there a
> recommendation to always convert to Harbour created tables?

I strongly suggest to use newer Harbour version.
You can rebuild Harbour SVN code in FreeBSD very simple.
BTW It would be nice if some FreeBSD user can update this old
Harbour port.

Please send some FP DBF examples here so I can check their headers.

best regards,
Przemek

Michael Green

unread,
Jan 18, 2011, 6:53:18 AM1/18/11
to Harbour Users

> I strongly suggest to use newer Harbour version.
> You can rebuild Harbour SVN code in FreeBSD very simple.
> BTW It would be nice if some FreeBSD user can update this old
> Harbour port.

I'll nag the maintainer at FreeBSD to port the new version.

>
> Please send some FP DBF examples here so I can check their headers.
>
I'll upload example.dbf.

Thanks again.

Michael Green

unread,
Jan 18, 2011, 7:01:22 AM1/18/11
to Harbour Users
As we can't upload to the files section any more I've put the file
here :

https://docs.google.com/leaf?id=0B3N9d9JU_5czY2E0ZWY0OWItODVjZS00Y2VkLTg3MmMtMTlhZjkwZWI0YmU5&sort=name&layout=list&num=50

Leave a message if you can't access the file. Thanks.

Massimo Belgrano

unread,
Jan 18, 2011, 7:05:42 AM1/18/11
to harbou...@googlegroups.com
Have you a sample dbf with all possible datatype of visual foxpro 9.0?

2011/1/18 Michael Green <michael...@gmail.com>

--
Massimo Belgrano


Przemysław Czerpak

unread,
Jan 18, 2011, 8:07:18 AM1/18/11
to harbou...@googlegroups.com
On Tue, 18 Jan 2011, Michael Green wrote:

Hi,

> As we can't upload to the files section any more I've put the file

It's standard DBASEIII file which can be used by Harbour and Clipper
without any problems.

best regards,
Przemek

Michael Green

unread,
Jan 18, 2011, 9:55:00 AM1/18/11
to Harbour Users
@Massimo
>Have you a sample dbf with all possible datatype of visual foxpro 9.0?
Sorry, no. only MS Foxpro Unix 2.6

@Przemysław
> It's standard DBASEIII file which can be used by Harbour and Clipper
> without any problems.
Thanks for that. I guess the closer you stick to dBase III the simpler
your life is.

As for the scroll() issue above, I can't understand why that was
flagged as an issue when I was originally compiling, it seems the same
(well as far as I can gather from the docs at xHarbour). Still it all
seems good now.

Michael Green

unread,
Jan 19, 2011, 5:59:45 AM1/19/11
to Harbour Users
The FoxPro approach to softseek is this (quoted from the FoxPro Unix
help file):


RECNO(0) Soft Seek
After an unsuccessful SEEK in an indexed table/.DBF,
RECNO(0) uses "soft seek" logic to determine the record
number to return. RECNO(0) returns the record number of
the closest match if the SEEK is unsuccessful and no
matching record is found. RECNO(0) returns 0 if a close
match cannot be found. The message "Record out of range"
is generated if you issue GO RECNO(0) and a close match
hasn't been found.

so you might do this:

if not found()
go recno(0)
endif

HOWEVER you'll note the vagueness of the term 'close match'.

Michael Green

unread,
Jan 20, 2011, 12:12:26 PM1/20/11
to Harbour Users
Here's a sample of FoxPro code with an array being used:

&& create 2D array
dime oinputv(20,lastpagev)

&& initialise array
store 1 to countv
do while countv < (20*lastpagev)+1
store ' ' to oinputv(countv)
store countv +1 to countv
enddo

&& fill array
go top
do while .not. eof()
store ((page-1)*20)+line to arrposv
store fieldname to oinputv(arrposv)
skip
enddo

Enjoy!

Alain Aupeix

unread,
Jan 21, 2011, 5:10:01 PM1/21/11
to harbou...@googlegroups.com
Hi,

I have some troubles to localize my prog.

I compile it with gtxwc (same problem without it). It work ok, but I have some trouble with accents in memoedit()

Without using hb_setTermCP and hb_CDPselect, all the semi-graphic characters are ok (it seems to use utf-8), but if I use :
hb_CDPselect("FR850")
hb_setTermCP("FR850","FR850")
the semi-graphics characters chr(199) and chr(182) are bad.

In memoedit(), if I don't use it, the accent are replaced with 2 characters. If I use it, the accent are replaced with 1 character, like in a console under Windows.

I suppose that no param gives:
UTF-8 under Linux
ANSI under Windows

with parameters, it uses OEM codage.

Where am-I wrong ?
Perhaps, there is no solution ?

As I was searching for CP in src, I found msgfr.c where a lot of messages wheren't translated. I translate it, and send it.

To open it I have used PSPad with OEM encoding.

A+


Thanks

A+

msgfr.c.zip
Reply all
Reply to author
Forward
0 new messages