关于 主程序调用子程序 运行异常
关于 主程序调用子程序 运行错误
1、在开始的时候没有注意到这一点,以为vb有编译不成功、编译成功两种情况,编译成功有运行成功、运行不成功两种情况,运行不成功也没有想到它们很在不受控制的弹出警告框,一开始的时候其实也注意到除数为零、数组越界、为声明变量等问题,感觉那是些逻辑上错误,挺多不会出现预期的结果,可是…… 郁闷。
开始的思路 编译->运行。这里的运行使用shell命令,直接调用的。到现在突然出现运行错误无法控制了。怎么办???
VB code
Dim WindH As Long Dim hWnd As Long Dim hWndParent As Long '父窗体句柄 Dim ParentTitle As Long '父窗体标题 Dim ParentTitleBuffer As String Dim CountControl As Double CountControl = 0 shellval = Shell(ExeFile, vbHide) '如果编译成功调用shell运行学生程序 Sleep 1000 If shellval <> 0 Then frmMain.RichTextBox1.Text = frmMain.RichTextBox1.Text & filestudent & "成功执行" & vbCrLf End If hWndParent = FindWindow(vbNullString, "Form1") '父窗体句柄 Sleep 100 ParentTitleBuffer = String(20, 0) ParentTitle = GetWindowText(hWndParent, ParentTitleBuffer, 255) '父窗体标题 RichTextBox1.Text = RichTextBox1.Text & filestudent & Space(2) & "父窗体句柄:" & hWndParent & Space(2) & "窗体名称:" & ParentTitleBuffer & vbCrLf RichTextBox1.Text = RichTextBox1.Text & "*****************" & vbCrLf If hWndParent <> 0 Then ret = EnumChildWindows(hWndParent, AddressOf EnumChildProc, 0) RichTextBox1.Text = RichTextBox1.Text & "*****************" & vbCrLf Sleep 1000 End If AdodcFrmMainMessage.RecordSource = "select * from [Message] where wordId='" & wordid & "' " 'MsgBox "adodc" & AdodcFrmMainMessage.RecordSource Dim i As Integer AdodcFrmMainMessage.Refresh For i = 0 To AdodcFrmMainMessage.Recordset.RecordCount - 1 Dim tempParent As Long '临时父句柄 Dim temp As Long '临时子窗体句柄 'MsgBox "ParentTitle" & Len(AdodcFrmMainMessage.Recordset.Fields("ParentTitle")) & Trim(AdodcFrmMainMessage.Recordset.Fields("ParentTitle")) & "voer" If Mid$(AdodcFrmMainMessage.Recordset.Fields("ParentTitle"), 1) = "Form1" Then ' 判断是否是Form1的直接孩子窗体 temp = FindWindowEx(hWndParent, 0, vbNullString, AdodcFrmMainMessage.Recordset.Fields("Caption")) 'MsgBox "temp" & temp & AdodcFrmMainMessage.Recordset.Fields("Caption") Else tempParent = FindWindowEx(hWndParent, 0, vbNullString, AdodcFrmMainMessage.Recordset.Fields("ParentTitle")) ' MsgBox "tempParent" & tempParent & "hwndparent" & hWndParent temp = FindWindowEx(tempParent, 0, vbNullString, AdodcFrmMainMessage.Recordset.Fields("Caption")) 'MsgBox "标题" & AdodcFrmMainMessage.Recordset.Fields("Caption") End If If temp <> 0 Then Dim tempClassBuffer As String tempClassBuffer = Space(MAXPATH) ' ret = RealGetWindowClass(hwnd, dwWindowClassBuffer, MAXPATH) retval = GetClassName(temp, tempClassBuffer, MAXPATH) ClassName = StrConv(LeftB(StrConv(tempClassBuffer, vbFromUnicode), retval), vbUnicode) '去掉不可打印的字符 ClassName = Trim(ClassName) 'MsgBox "classname" & Len(ClassName) & ClassName & "over" If retval <> 0 Then If ClassName = "ThunderRT6OptionButton" Or ClassName = "ThunderRT6CheckBox" Then SendMessage temp, BMSETCHECK, ByVal CLng(1), ByVal CLng(0) End If If ClassName = "ThunderRT6CommandButton" Then SendMessage temp, WMLBUTTONDOWN, 0, ByVal &H10001 Sleep 100 SendMessage temp, WMLBUTTONUP, 0, ByVal &H10001 End If End If End If AdodcFrmMainMessage.Recordset.MoveNext Next PostMessage hWndParent, WM_CLOSE, 0, 0 '关闭窗口 Call WordIdControlKey Call WordIdkey score = Round(wordM * WordIdControlKey * WordIdkey, 2) '四舍五入保留两位小数 Adodc2.Refresh ' adodc2先刷新 要不会覆盖上一条记录 Adodc2.Recordset.AddNew Adodc2.Recordset.Fields("stuid") = stuid Adodc2.Recordset.Fields("score") = Format(score, "0.00") '截取两位 Adodc2.Recordset.Update
相关链接
VisualBasic程序开发环境 程序开发 VisualBasic