Monday, July 25, 2005

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.

Monday, July 25, 2005 10:20:12 AM (Central Daylight Time, UTC-05:00)  #    Comments [8]
Monday, July 25, 2005 11:14:39 AM (Central Daylight Time, UTC-05:00)
Hi Craig

This sounds like a great utility. Thanks. I have just downloaded it and can't wait to try it out.
Tuesday, July 26, 2005 6:30:29 AM (Central Daylight Time, UTC-05:00)
Thanks for the positive feedback. I hope you find it useful.
Thursday, September 15, 2005 1:25:55 PM (Central Daylight Time, UTC-05:00)
Hello!
I am Visual Foxpro 5,6,7,8 from 1997, Now I would like to Create My VFP Bases Application in Visual Basic 6, but there is a problem to Creating Application in VB , VFP Grid is the Best and Powerfull Grid ,I Tried many Other Third Party Grids but there is no any one like VFP Grid. So Please Tell me the Idea that Can I Use VFP GRID in VB.

Waiting for your Reply!

Thanks
Kamran Khania
Kamran Khania
Saturday, October 01, 2005 9:03:26 AM (Central Daylight Time, UTC-05:00)
Hi Kamran,

I would first counsel you to not move to VB 6 as it is on limited life support and going nowhere. Now, that having been said, there is no equivalent to the VFP Grid in VB. You may try the FlexGrid, but you will be sorely disappointed after having used VFP's grid class.
Tuesday, October 04, 2005 1:46:13 PM (Central Daylight Time, UTC-05:00)
I have downloaded Code & exe but it want shows what shown in picture there is calling button on code & exe


may be this is a bug !!!!!!


chandresh
Monday, December 05, 2005 11:06:21 PM (Central Standard Time, UTC-06:00)
Thanks Craig !!

You can find the Spanish version of this article at (Puede encontrar la versión en Español de este artículo en:)

http://www.portalfox.com/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=101

Regards / Saludos,

Ana
www.amby.net
www.PortalFox.com
Friday, February 03, 2006 7:58:04 PM (Central Standard Time, UTC-06:00)
Hi, I have downloaded the file vbtovpf, but in the .zip file I dont find the .bas and in the form I can´t see the ellipsis button [...], whi?

I am use VFP 9.0 SP1.

Best regards.
Roberto Barros - BH/Brasil

Roberto Barros
Monday, March 12, 2007 11:24:19 PM (Central Daylight Time, UTC-05:00)
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

Walter John Claros
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):


 

Archive

<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456