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:
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