主题:[讨论]VB调用Fortran的EXE执行文件
各位大侠,请多多帮忙!
我以用Fortran编写的一个排序的程序,可以成功运行。
想用VB输入数据,形成一个.dat文件,然后EXE执行文件调用该输入文件,希望运行后,可以将结果显示在richtextbox控件中。但是,VB输入文件形成后,在单击Button时,就是不能得出计算结果,好像此时的EXE文件无法找到已经形成的输入文件,程序代码如下,希望可以得到大家的帮助,非常感谢!!!
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
Private Sub Command1_Click()
Dim iTask As Long, ret As Long, pHandle As Long
filepath = App.Path
FileName1 = filepath & "\BeforeSort.dat"
FileName2 = filepath & "\AfterSort.dat"
For i = 0 To 9
If Text1(i).Text = " " Then
MsgBox "请输入序号为" & i + 1 & "的实数!", vbCritical + vbOKOnly, "警告"
Exit Sub
End If
Next
Open FileName1 For Output As #1
For i = 0 To 9
Print #1, Val(Text1(i).Text)
Next
Close #1
iTask = Shell(filepath & "\paixu.exe", vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
ret = WaitForSingleObject(pHandle, INFINITE)
ret = CloseHandle(pHandle)
RichTextBox1.LoadFile FileName2, rtfText
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
我以用Fortran编写的一个排序的程序,可以成功运行。
想用VB输入数据,形成一个.dat文件,然后EXE执行文件调用该输入文件,希望运行后,可以将结果显示在richtextbox控件中。但是,VB输入文件形成后,在单击Button时,就是不能得出计算结果,好像此时的EXE文件无法找到已经形成的输入文件,程序代码如下,希望可以得到大家的帮助,非常感谢!!!
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
Private Sub Command1_Click()
Dim iTask As Long, ret As Long, pHandle As Long
filepath = App.Path
FileName1 = filepath & "\BeforeSort.dat"
FileName2 = filepath & "\AfterSort.dat"
For i = 0 To 9
If Text1(i).Text = " " Then
MsgBox "请输入序号为" & i + 1 & "的实数!", vbCritical + vbOKOnly, "警告"
Exit Sub
End If
Next
Open FileName1 For Output As #1
For i = 0 To 9
Print #1, Val(Text1(i).Text)
Next
Close #1
iTask = Shell(filepath & "\paixu.exe", vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
ret = WaitForSingleObject(pHandle, INFINITE)
ret = CloseHandle(pHandle)
RichTextBox1.LoadFile FileName2, rtfText
End Sub
Private Sub Command2_Click()
Unload Me
End Sub