Visual Basic (versions 6 and below) code examples are everywhere. It’s a huge resource that many Visual FoxPro developers utilize, but converting a Visual Basic example to Visual FoxPro is, more often than not, a pain. It’s the same thing over and over again… change dims to locals, change msgbox to messagebox, add parenthesis around the procedure calls, etc., etc., ad nauseam.
As a programmer who develops in Visual Basic as well as Visual FoxPro, I was intrigued when, about a year ago on Tek-Tips, William GC Steinford offered the idea of a Visual Basic to Visual FoxPro converter. I decided it was a great idea and created my own. It is driven from a conversion table (of course), and handles most of the basic things that need to be changed when porting Visual Basic code to Visual FoxPro.
I’ve used it internally for awhile now, and it is a real time saver. Now, bear in mind that I’m not putting on a code clinic with this thing (like I said, I was just using it internally for some down and dirty conversions), but it’s functional and new vb to vfp syntax conversions can be added to the program just by adding records in the conversion.dbf. There are a couple of extra fields in that table as well that are reserved for future use (they will be used for such things as converting API Declare statements properly and such – basically anything that can’t be done in one pass through the conversion.dbf or needs special handling).
If you add to the conversion table or the program, I would really appreciate it if you would email me the changes. I would like to incorporate any useful changes with my own, and continue to offer them back to the Visual FoxPro community. Other than that, feel free to use it however or whenever you see fit.
A sample Visual Basic .BAS file has been included in the zip. When you run the vbtovfp.exe just click the ellipsis button […] and select the vbsample.bas file to open it in the conversion utility. Here’s a screen shot of vbtovfp and you can download vbtovfp here (source included).
Note: Originally written in VFP 7, but ported to VFP 9 – so, you will need VFP 9 to run this (or take the time to take out the VFP 9-only features and recompile it in whatever VFP you got). Also, there is selection/right-click functionality with the editboxes you’ll want to explore.
Please helpme to convert the following VB program to VFP program; i am not work in VB.
thank you. the utility vbtovfp not full convertion.
Walter John
Option Explicit
‘ ///
‘ /// Ejecutar una aplicación con permisos de otro usuario ("Run As")
‘ /// Lluís Franco i Montanyés (MVP-MCP-VB) 07/06/2004
‘ /// Ejemplo: fRunAsEx "NOTEPAD.EXE", "<usuario>@<dominio>", "<password>"
‘ ///
Private Const LOGON_WITH_PROFILE = &H1&
Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
Private Const CREATE_NEW_CONSOLE = &H10&
Private Const CREATE_NEW_PROCESS_GROUP = &H200&
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const LANG_NEUTRAL = &H0
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CreateProcessWithLogon Lib _
"Advapi32" Alias "CreateProcessWithLogonW" _
(ByVal lpUsername As Long, ByVal lpDomain As Long, ByVal _
lpPassword As Long, ByVal dwLogonFlags As Long, ByVal _
lpApplicationName As Long, ByVal lpCommandLine As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, ByVal lpStartupInfo As STARTUPINFO, _
ByVal lpProcessInfo As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" _
(ByVal dwFlags As Long, ByVal lpSource As Any, ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, _
ByVal Arguments As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Public sError As String
Public Sub Main()
Dim sParams() As String, sParam, i As Long, fReturn As Long
Dim sApp As String, sUser As String, sPwd As String
‘Verificación de argumentos correctos (/path aplicación /usuario@dominio /contraseña)
If Trim(Command$) = "" Then
MsgBox("Error! No se han suministrado argumentos para ejecutar RunAs:" & _
vbNewLine & vbNewLine & _
"Parametros= /<path aplicación> /<usuario> /<password>" & _
vbNewLine & vbNewLine & _
"Ejemplo= /NOTEPAD.EXE /administrador@dominio.com /mypassword", vbExclamation)
Exit Sub
End If
sParams = Split(Command$, "/")
For Each sParam In sParams
If Trim(sParam) <> "" Then
i = i + 1
If i = 1 Then sApp = Trim(sParam)
If i = 2 Then sUser = Trim(sParam)
If i = 3 Then sPwd = Trim(sParam)
End If
Next
fReturn = fRunAsEx(sApp, sUser, sPwd)
If fReturn = 0 Then MsgBox(sError, vbExclamation)
End Sub
Public Function fRunAsEx(ByVal sFileName As String, _
ByVal sUserName As String, ByVal sUserPwd As String) As Long
‘Declaració vars
Dim lpBuffer As String * 200
Dim fReturn As Long
Dim lpUsername As String, lpDomain As String
Dim lpPassword As String, lpApplicationName As String
Dim lpCommandLine As String, lpCurrentDirectory As String
Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
lpApplicationName = sFileName
lpUsername = sUserName
lpPassword = sUserPwd
lpCommandLine = vbNullString
lpCurrentDirectory = vbNullString
StartInfo.cb = LenB(StartInfo)
StartInfo.dwFlags = 0&
fReturn = CreateProcessWithLogon(StrPtr(lpUsername), StrPtr(lpDomain), _
StrPtr(lpPassword), LOGON_WITH_PROFILE, StrPtr(lpApplicationName), _
StrPtr(lpCommandLine), CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE _
Or CREATE_NEW_PROCESS_GROUP, ByVal 0&, StrPtr(lpCurrentDirectory), _
StartInfo, ProcessInfo)
If fReturn = 0 Then
If GetLastError = 0 Then
sError = "La operación no se ha podido completar con éxito."
Else
FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, _
GetLastError, LANG_NEUTRAL, lpBuffer, 200, ByVal 0&
sError = lpBuffer
End If
End If
fRunAsEx = fReturn
CloseHandle(ProcessInfo.hThread)
CloseHandle(ProcessInfo.hProcess)
End Function