Re: Migrating from QuickBasic to VisualBasic
- From: Mike Williams <gagamomo@xxxxxxxxxxx>
- Date: Mon, 7 Jan 2008 05:12:53 -0800 (PST)
On 7 Jan, 08:54, sinus...@xxxxxxxxx wrote:
I finished my project 'do.vbp' thanks to your help.
And then I did the same with a little more complex
QB program of mine. I have a shell instruction that
calls an exe program (made in QB), which creates a
large data file.
That's okay I suppose, but surely it would be better to re write the
code that creates your large data file in VB, and then you'll have
full control over it and you'll be able to modify it to perform
different tasks (or perhaps the same task in a different way) at any
time you wish.
I've been using that code for years,[some QB
Shell and wait for a file code] and I don't
understand why it doesn't work in VB.
To be perfectly honest I haven't looked at your QB code. Too many
Gotos in it for my liking ;-) (one Goto is one too many, other than
the On Error Gotos which are usually unavoidable!). Try doing it the
VB6 way, which is better because it allows you to Shell any app and
wait for it to terminate without testing for the creation of a file or
anything else. To try it out create a new VB project and paste the
following code into your Form:
Mike
Option Explicit
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal _
dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As String, ByVal lpCommandLine _
As String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles _
As Long, ByVal dwCreationFlags As Long, ByVal _
lpEnvironment As Long, ByVal lpCurrentDirectory As _
String, lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
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 String
lpDesktop As String
lpTitle As String
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 Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Const WAIT_TIMEOUT = 258
Private Sub ShellAndWait(s1 As String)
Dim start As STARTUPINFO, Retval As Long
Dim proc As PROCESS_INFORMATION
start.cb = Len(start)
Retval = CreateProcessA(vbNullString, s1, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
Do
Retval = WaitForSingleObject(proc.hProcess, 10)
Me.Refresh
Loop While Retval = WAIT_TIMEOUT
Call GetExitCodeProcess(proc.hProcess, Retval)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
End Sub
Private Sub Command1_Click()
Dim s1 As String
s1 = "c:\temp\mick4.exe" ' or the name of your QB exe
ShellAndWait s1
MsgBox "Shelled program has finished."
End Sub
.
- References:
- Migrating from QuickBasic to VisualBasic
- From: sinusLog
- Re: Migrating from QuickBasic to VisualBasic
- From: Norm Cook
- Re: Migrating from QuickBasic to VisualBasic
- From: Norm Cook
- Re: Migrating from QuickBasic to VisualBasic
- From: sinusLog
- Re: Migrating from QuickBasic to VisualBasic
- From: Mike Williams
- Re: Migrating from QuickBasic to VisualBasic
- From: sinusLog
- Re: Migrating from QuickBasic to VisualBasic
- From: Mike Williams
- Re: Migrating from QuickBasic to VisualBasic
- From: sinusLog
- Re: Migrating from QuickBasic to VisualBasic
- From: Mike Williams
- Re: Migrating from QuickBasic to VisualBasic
- From: sinusLog
- Migrating from QuickBasic to VisualBasic
- Prev by Date: Re: add date string to filename
- Next by Date: Re: add date string to filename
- Previous by thread: Re: Migrating from QuickBasic to VisualBasic
- Next by thread: Re: Migrating from QuickBasic to VisualBasic
- Index(es):
Relevant Pages
|