Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting VB to VFP 1

Status
Not open for further replies.

wgcs

Programmer
Mar 31, 2002
2,056
EC
Here's a (very rough) useful function that does a quick first pass conversion from VB to VFP. Anybody want to help add capability to it?

Note that the result of this will usually be pretty close to able to be compiled, but some sense of the original code could get lost in the process: A complete conversion requires combing through the code by hand.

The most useful feature of this function is that it shows many of the basic things that have to change for newbies to VB who want to convert publicly available code to VFP:

Code:
FUNCTiON vb2vfp
LPARAMETERS pcFile
if not File(pcFile)
  messagebox("Error!  The file "+pcFile+" does not exist!")
  RETURN .F.
endif
LOCAL lcFileData
lcFileData = FileToStr(pcFile)
* Normalize all CR's and LF's to CRLF
lcFileData = strtran( lcFileData, chr(13)+chr(10), chr(13) )
lcFileData = strtran( lcFileData, chr(10),         chr(13) )
lcFileData = strtran( lcFileData, chr(13),         chr(13)+chr(10) )
* Change all comments that start a line to "*"
lcFileData = strtran( lcFileData, chr(13)+chr(10)+['], chr(13)+chr(10)+[*] )
* Change all mid-line comments to &&
lcFileData = strtran( lcFileData, ['], [&]+[&] )
* Change language constructs
lcFileData = strtran( lcFileData, [End If], [ENDIF] )
lcFileData = strtran( lcFileData, [ Then]+chr(13), chr(13) )
lcFileData = strtranc( lcFileData, chr(10)+[dim ], chr(10)+[LOCAL ] )
lcFileData = strtran( lcFileData, [As Integer], [] )
lcFileData = strtran( lcFileData, [As String],  [] )
lcFileData = strtran( lcFileData, [As Long],    [] )
lcFileData = strtran( lcFileData, [As Boolean], [] )

lcFileData = strtranc( lcFileData, [vbCrLf], [chr(13)+chr(10)] )
lcFileData = strtranc( lcFileData, [vbCr],   [chr(13)] )
lcFileData = strtranc( lcFileData, [vbLf],   [chr(10)] )
lcFileData = strtranc( lcFileData, [ & ],    [ + ] )
lcFileData = strtranc( lcFileData, [ \ ],    [ / ] )
lcFileData = strtranc( lcFileData, [Next ],  [ENDFOR &]+[& ] )
lcFileData = strtranc( lcFileData, [ Mod ],  [ % ] )
lcFileData = strtranc( lcFileData, [$ ],     [ ] )
lcFileData = strtranc( lcFileData, [Mid$(],  [SubStr(] )
lcFileData = strtranc( lcFileData, [Mid(],   [SubStr(] )
lcFileData = strtranc( lcFileData, [End Function],  [ENDFUNC] )
lcFileData = strtranc( lcFileData, [End Sub],       [ENDPROC] )
lcFileData = strtranc( lcFileData, [Private Function ],  [FUNCTION ] )
lcFileData = strtranc( lcFileData, [Public Function ],  [FUNCTION ] )
lcFileData = strtranc( lcFileData, [Private Sub ],  [PROCEDURE ] )
lcFileData = strtranc( lcFileData, [Private Sub ],  [PROCEDURE ] )
lcFileData = strtranc( lcFileData, [Sub ],  [PROCEDURE ] )

StrToFile(lcFileData, ForceExt(pcFile,'PRG') )

RETURN .T.
*************************************
FUNCTION StrTranC
PARAMETERS lcInStr, lcFrom, lcTo
PRIVATE lcRetStr, lnAt, lnAtOld
  lcRetStr = lcInStr
  lnAt = AtC( lcFrom, lcRetStr )
  do while lnAt > 0
    lcRetStr = Stuff( lcRetStr, lnAt, len(lcFrom), lcTo )
    lnAtOld = lnAt
    lnAt = AtC( lcFrom, SubStr(lcRetStr,lnAtOld+len(lcTo)) ) 
    lnAt = iif( lnAt>0, lnAt + lnAtOld + len(lcTo)-1, 0 )
  enddo
RETURN lcRetStr
 
wgcs,

looks like you have a good start...there is a lot of potential here I think...I think that the vb frm files could even be converted into scx files with some constraints and limitations. let me know if you would like to work on this together.

Slighthaze = NULL
 
Hi, that does look pretty good.

Code:
if not File(pcFile)
should probably read
Code:
if .not. File(pcFile)

Do you need to replace the NEXT?
And.. think about AND, NOT, ElseIf and SELECT CASE statements

Brilliant fellas, looks like a new product could be on it's way!

Good luck


Regards

Griff
Keep [Smile]ing
 
VFP doesn't care whether you use " NOT " or " .NOT. "...

The situations with "ElseIf" and "SELECT CASE" illustrate the difficulty in doing a complete automated conversion from VB to VFP... both these situations require some restructuring of code rather than just replacing specific strings.

It seems that my *real* work is starting to get pretty busy again, so I don't have a whole lot of time to devote to this project; Slighthaze, perhaps we could set up a page on the Fox Wiki, perhaps VbToVfp, as a collaboration site. See:
 
Hey wgcs,

Thats a very good work. I am sure you can go on to create a full fledge utility. Ofcourse "real" work comes first. But still congratulations on getting it started.

:)
 
wgcs;

This would be great utility for us non savy in the VB.

If I knew VB as much as I know VFP I would love to help out.

And if you guys ever need a vfp-skin applied to your finished app, I sure hope you look me up!

Seriously, a babelfish for coders - *Great Idea!*

Regards - Wayne
sig_jugler.gif
...all this and tap dancing too!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top