求助:实时错误28溢出堆栈空间
小弟飞、第一次在这里发帖,想各位前辈请教,我最近碰到这个问题:实时错误“28”,溢出堆栈空间我一直没发现到底是怎么回事,请大家帮帮忙,谢谢!
以下是代码(标记红色的部分是报错后调试光标停在的位置):
Dim i As Integer
Dim jiepai_dp As Integer
Dim ks_dp As String
Dim js_dp As String
Dim jishu_i As Integer
Private Declare Sub sleep Lib "kernel32" (ByVal dwmiliseconds As Long)
Private Sub Command1_Click()
Dim rs As New ADODB.Recordset
Dim sql As String
Call sumkc
sql = "select date as '日期',type as '机型',number as '数量',a.erprenwu as '任务号' from "
sql = sql + "t_os inner join (select erpdate ,erpjixing,erprenwu from "
sql = sql + "T_mes_erp group by erprenwu,erpjixing,erpdate) a"
sql = sql + " on type=erpjixing and date=erpdate order by date "
With rs
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql
.Open
End With
If rs.RecordCount > 0 Then
rs.MoveFirst
For i = 0 To rs.RecordCount
If i < rs.RecordCount Then
Labeldate1.ForeColor = &HFF&
Labeltype1.ForeColor = &HFF&
Labelnumber1.ForeColor = &HFF&
Labeldate1.Caption = rs.Fields(0)
Labeltype1.Caption = rs.Fields(1)
Labelnumber1.Caption = rs.Fields(2)
If labcol(Trim(rs.Fields(0)), Trim(rs.Fields(1))) = True Then
Labeldate1.ForeColor = &HFF00&
Labeltype1.ForeColor = &HFF00&
Labelnumber1.ForeColor = &HFF00&
End If
Else
Labeldate1.Caption = ""
Labeltype1.Caption = ""
Labelnumber1.Caption = ""
End If
i = i + 1
If i < rs.RecordCount Then
rs.MoveNext
Labeldate2.ForeColor = &HFF&
Labeltype2.ForeColor = &HFF&
Labelnumber2.ForeColor = &HFF&
Labeldate2.Caption = rs.Fields(0)
Labeltype2.Caption = rs.Fields(1)
Labelnumber2.Caption = rs.Fields(2)
If labcol(Trim(rs.Fields(0)), Trim(rs.Fields(1))) = True Then
Labeldate2.ForeColor = &HFF00&
Labeltype2.ForeColor = &HFF00&
Labelnumber2.ForeColor = &HFF00&
End If
Else
Labeldate2.Caption = ""
Labeltype2.Caption = ""
Labelnumber2.Caption = ""
End If
Call Wait_S(10)
If Labeldate1.Caption = "" Or Labeldate2.Caption = "" Then
Exit For
Else
rs.MoveNext
End If
Next i
End If
If Labeldate2.Caption = "" Or Labeldate1.Caption = "" Then
Call Command1_Click
End If
End Sub Private Sub Command2_Click()
Rem 读取实时完工信息
Dim rs_mes As New ADODB.Recordset
Dim sql_mes As String
sql_mes = "select * from sid09001.tb_if_prd_hist_main t where line_kind='MAIN' and OP_NO='OP670'and log_date like to_date('" & Date & "','YYYY-MM-DD') "
With rs_mes
.ActiveConnection = conmes
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_mes
.Open
End With
If rs_mes.RecordCount > 0 Then
If Text7.Text = "" Then
labrealitynumber.Caption = rs_mes.RecordCount
Else
Dim t71 As Integer
Dim r71 As Integer
t71 = CInt(Trim(Text7.Text))
r71 = rs_mes.RecordCount
labrealitynumber.Caption = t71 + CInt(r71)
End If
If Text3.Text = "" Then
labtype.Caption = rs_mes.Fields(3) + rs_mes.Fields(4)
Else
labtype.Caption = Text3.Text
End If
Else
If Text7.Text = "" Then
labrealitynumber.Caption = 0
Else
labrealitynumber.Caption = 0 + CInt(Trim(Text7.Text))
End If
' If Text3.Text = "" Then
' labtype.Caption = ""
' Else
' labtype.Caption = Text3.Text
' End If
End If
rs_mes.Close
Rem 解决机型不随生产改变的问题
Dim rs_jixing As New ADODB.Recordset
Dim sql_jixing As String
sql_jixing = "select * from sid09001.tb_if_prd_hist_main t where line_kind='MAIN' and OP_NO='OP670' and log_date like to_date('" & Date & "','YYYY-MM-DD') order by inf_seq_no desc "
With rs_jixing
.ActiveConnection = conmes
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_jixing
.Open
End With
If rs_jixing.RecordCount > 0 Then
If Text3.Text = "" Then
labtype.Caption = rs_jixing.Fields(3) + rs_jixing.Fields(4)
Else
labtype.Caption = Text3.Text
End If
Else
If Text3.Text = "" Then
labtype.Caption = ""
Else
labtype.Caption = Text3.Text
End If
End If
rs_jixing.Close
Rem 读取生产计划信息
Dim rs_os As New ADODB.Recordset
Dim sql_os As String
sql_os = "select sum(number) from t_os where date='" & Date & "'group by date"
With rs_os
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_os
.Open
End With
If rs_os.RecordCount > 0 Then
If Text6.Text = "" Then
labdaynumber.Caption = rs_os.Fields(0)
Else
Dim t61 As Integer
Dim o61 As Integer
o61 = CInt(rs_os.Fields(0))
t61 = CInt(Text6.Text)
labdaynumber.Caption = o61 + t61
End If
' If Timerjishu.Enabled = False Then
' Timerjishu.Enabled = True
' End If
Else
If Text6.Text = "" Then
labdaynumber.Caption = 0
Else
labdaynumber.Caption = 0 + CInt(Text6.Text)
End If
'Timerjishu.Enabled = True
rs_os.Close
End If
Rem 计算进度
Dim rs_jindu As New ADODB.Recordset
Dim sql_jindu As String
Dim shuliang_yc As Integer
sql_jindu = "select * from t_jishuwai"
With rs_jindu
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_jindu
.Open
End With
shuliang_yc = rs_jindu.Fields(1)
rs_jindu.Close
If Text8.Text = "" Then
If (CInt(Trim(labrealitynumber.Caption)) - shuliang_yc) > 0 Then
labProgress.Caption = "+" & (CInt(Trim(labrealitynumber.Caption)) - shuliang_yc)
Else
labProgress.Caption = CInt(Trim(labrealitynumber.Caption)) - shuliang_yc
End If
Else
Dim t81 As Integer
t81 = CInt(Trim(Text8.Text))
If (CInt(Trim(labrealitynumber.Caption)) - shuliang_yc + t81) > 0 Then
labProgress.Caption = "+" & (CInt(Trim(labrealitynumber.Caption)) - shuliang_yc + t81)
Else
labProgress.Caption = CInt(Trim(labrealitynumber.Caption)) - shuliang_yc + t81
End If
End If
Rem 紧急要货信息
Dim rs_quejian As New ADODB.Recordset
Dim sql_quejian As String
sql_quejian = "select * from T_jinji where weizhi='0' and biaoshi='1'"
With rs_quejian
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_quejian
.Open
End With
If rs_quejian.RecordCount > 0 Then
Labmiss.Caption = "缺件:" + "件号" + Trim(rs_quejian.Fields(2)) + " 零件名称 " + Trim(rs_quejian.Fields(3)) + " 数量" + Trim(rs_quejian.Fields(4))
End If
rs_quejian.Close
End Sub Private Sub Command3_Click()
Dim rs_jiepai As New ADODB.Recordset
Dim sql_jiepai As String
sql_jiepai = "select * from t_jiepai"
With rs_jiepai
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_jiepai
.Open
End With
Rem 一天一次休息
If Trim(rs_jiepai.Fields(10)) = 1 And Trim(rs_jiepai.Fields(11)) = 0 And Trim(rs_jiepai.Fields(12)) = 0 Then
t_xst1 = Trim(rs_jiepai.Fields(4))
t_xsp1 = Trim(rs_jiepai.Fields(5))
If DateDiff("s", Time, t_xst1) <= 0 And DateDiff("s", Time, t_xsp1) >= 0 Then
Timerjishu.Enabled = False
Else
Call jiayi
End If
ElseIf Trim(rs_jiepai.Fields(10)) = 1 And Trim(rs_jiepai.Fields(11)) = 1 And Trim(rs_jiepai.Fields(12)) = 0 Then
t_xst1 = Trim(rs_jiepai.Fields(4))
t_xsp1 = Trim(rs_jiepai.Fields(5))
t_xst2 = Trim(rs_jiepai.Fields(6))
t_xsp2 = Trim(rs_jiepai.Fields(7))
If (DateDiff("s", Time, t_xst1) <= 0 And DateDiff("s", Time, t_xsp1) >= 0) Or (DateDiff("s", Time, t_xst2) <= 0 And DateDiff("s", Time, t_xsp2) >= 0) Then
' imerjishu.Enabled = False
' Else
' Call jiayi
' End If
'ElseIf Trim(rs_jiepai.Fields(10)) = 1 And Trim(rs_jiepai.Fields(11)) = 1 And Trim(rs_jiepai.Fields(12)) = 1 Then
'' t_xst1 = Trim(rs_jiepai.Fields(4))
'' t_xsp1 = Trim(rs_jiepai.Fields(5))
'' t_xst2 = Trim(rs_jiepai.Fields(6))
'' t_xsp2 = Trim(rs_jiepai.Fields(7))
'' t_xst3 = Trim(rs_jiepai.Fields(8))
'' t_xsp3 = Trim(rs_jiepai.Fields(9))
'' If (DateDiff("s", Time, t_xst1) <= 0 And DateDiff("s", Time, t_xsp1) >= 0) Or (DateDiff("s", Time, t_xst2) <= 0 And DateDiff("s", Time, t_xsp2) >= 0) Or (DateDiff("s", Time, t_xst3) <= 0 And DateDiff("s", Time, t_xsp3) >= 0) Then
'' jishu_i = jishu_i - 1
'' Else
'' Call jiayi
'' End If
'
'End If
'rs_jiepai.Close
'End Sub
Private Sub Command4_Click()
End
End Sub
Rem 将修改后的欢迎词写入数据库
Private Sub Command5_Click()
Dim sql_huanyingci As String
Dim cmd_huanyingci As New ADODB.Command
sql_huanyingci = "Update T_BasicData set showtime ='" & Trim(Text1.Text) & "',readtime='" & Trim(Text2.Text) & "',"
sql_huanyingci = sql_huanyingci + "serverip='" & Trim(Text9.Text) & "',servername='" & Trim(Text4.Text) & "' , serverusername='" & Trim(Text5.Text) & "'"
cmd_huanyingci.ActiveConnection = conn
cmd_huanyingci.CommandType = adCmdText
cmd_huanyingci.CommandText = sql_huanyingci
cmd_huanyingci.Execute
Call Command20_Click
End Sub
Private Sub Command9_Click()
If Timergundong.Enabled = False Then
Timergundong.Enabled = True
Timergundong.Interval = 150
Else
Timergundong.Enabled = False
End If
End Sub
Private Sub Command6_Click()
Call qingling
End Sub
Private Sub Command7_Click()
' Timerjishu.Enabled = False
Timerjishi.Enabled = False
labdaynumber.Caption = 0
labrealitynumber.Caption = 0
labProgress.Caption = 0
labtype.Caption = ""
Text3.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
End Sub
Private Sub Command8_Click()
' Timerjishu.Enabled = True
Timerjishi.Enabled = True
End Sub
Private Sub Form_Load()
Formshowbig1.Visible = True
Dim datetime As String
Dim datetimeshow As String
Dim week As String
Dim nowtime As String
Call con
Call conm
'显示日期
datetime = Date2Str(Date)
datetimeshow = Mid$(datetime, 1, 4) & "年" & Mid$(datetime, 6, 2) & "月" & Mid$(datetime, 9, 2) & "日"
Label1.Caption = datetimeshow
'显示星期
week = weekdayshow(Weekday(Date))
Label2.Caption = week
Rem 读取生产节拍相关信息
Dim rs_jiepai As New ADODB.Recordset
Dim sql_jiepai As String
sql_jiepai = "select * from t_jiepai"
With rs_jiepai
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_jiepai
.Open
End With
jiepai_dp = CInt(Trim(rs_jiepai.Fields(1)))
ks_dp = Trim(rs_jiepai.Fields(2))
js_dp = Trim(rs_jiepai.Fields(3))
Call Command20_Click
Call Command9_Click
Call Command9_Click
Call Command1_Click
End Sub
Private Sub Command20_Click()
Rem 读取欢迎词
Dim rs_huanyingci As New ADODB.Recordset
Dim sql_hyc As String
sql_hyc = "select * from t_basicdata"
With rs_huanyingci
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_hyc
.Open
End With
Label10.Caption = Trim(rs_huanyingci.Fields(0))
Label11.Caption = Trim(rs_huanyingci.Fields(1))
Label16.Caption = Trim(rs_huanyingci.Fields(2))
Label9.Caption = Trim(rs_huanyingci.Fields(3))
Label12.Caption = Trim(rs_huanyingci.Fields(4))
End Sub
Public Function Date2Str(vntDate As Date, _
Optional strConvertType As String = "yyyy-mm-dd") As String
'日期转化为指定格式的字符串形式,默认"yyyy-mm-dd"
Dim strDateYear As String, strDateMonth As String, strDateDay As String
Select Case strConvertType
Case "yyyy-mm-dd"
strDateYear = Right$(str$(Year(vntDate) + 10000), 4)
strDateMonth = Right$(str$(Month(vntDate) + 100), 2)
strDateDay = Right$(str$(Day(vntDate) + 100), 2)
Date2Str = strDateYear & "-" & strDateMonth & "-" & strDateDay
Case Else
End Select
End Function
Public Function weekdayshow(week As Integer) As String
Select Case week
Case 2
weekdayshow = "星期一"
Case 3
weekdayshow = "星期二"
Case 4
weekdayshow = "星期三"
Case 5
weekdayshow = "星期四"
Case 6
weekdayshow = "星期五"
Case 7
weekdayshow = "星期六"
Case 1
weekdayshow = "星期日"
End Select
End Function
Private Sub Timer1_Timer()
Dim datetime As String
Dim datetimeshow As String
Dim week As String
Dim nowtime As String
'显示日期
datetime = Date2Str(Date)
datetimeshow = Mid$(datetime, 1, 4) & "年" & Mid$(datetime, 6, 2) & "月" & Mid$(datetime, 9, 2) & "日"
Label1.Caption = datetimeshow
'显示星期
week = weekdayshow(Weekday(Date))
Label2.Caption = week
'显示时间
Label3.Caption = Mid$(Time, 1, 2) & "时" & Mid$(Time, 4, 2) & "分" & Mid$(Time, 7, 2) & "秒"
If Time = ks_dp Then
' Timerjishu.Enabled = True
Timerjishi.Enabled = True
End If
If Time = js_dp Then
Call qingling
' Timerjishu.Enabled = False
Timerjishi.Enabled = False
labdaynumber.Caption = 0
labrealitynumber.Caption = 0
labProgress.Caption = 0
labtype.Caption = ""
Text3.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
End If
End Sub
Rem 延时函数
Public Sub Wait_S(SecondV As Single)
Dim i As Single, j As Single
i = Timer + SecondV
Do While i > Timer
If Timer < 1 And i >= 86400 Then '跨0点处理
i = i - 86400
End If
DoEvents
Loop
End Sub
Private Sub mov(Labeldate1 As Label)
Dim width As Integer
width = 500
Labeldate1.Left = Labeldate1.Left - 100
If Labeldate1.Left + width < 0 Then Labeldate1.Left = Me.ScaleWidth
End Sub
Private Sub Timer2_Timer()
Call mov(Labeldate1)
Call mov(Labeltype1)
Call mov(Labelnumber1)
Call mov(Labeldate2)
Call mov(Labeltype2)
Call mov(Labelnumber2)
End Sub
Private Function labcol(da As String, typea As String) As Boolean
Dim rs As New ADODB.Recordset
Dim sql As String
Dim cmd As New ADODB.Command
Dim sql_cmd As String
Dim x As Integer
sql = "select partid as '零件号',number as '库存',a.erpshuliang as '计划',number -a.erpshuliang as '剩余'"
sql = sql + " From T_partno inner join (select * from t_mes_erp where erpdate='" & da & "'and "
sql = sql + " erpjixing='" & typea & "') a on a.erplingjian = partid"
With rs
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql
.Open
End With
If rs.RecordCount > 0 Then
rs.MoveFirst
For x = 1 To rs.RecordCount
If rs.Fields(3) > 0 Then
sql_cmd = "update t_partno set number='" & rs.Fields(3) & "'where partid='" & rs.Fields(0) & "'"
cmd.ActiveConnection = conn
cmd.CommandType = adCmdText
cmd.CommandText = sql_cmd
cmd.Execute
rs.MoveNext
Else
labcol = False
sql_cmd = "update t_partno set number='" & rs.Fields(3) & "'where partid='" & rs.Fields(0) & "'"
cmd.ActiveConnection = conn
cmd.CommandType = adCmdText
cmd.CommandText = sql_cmd
cmd.Execute
Exit Function
End If
Next x
labcol = True
End If
End Function
Sub sumkc()
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim rs_kc As New ADODB.Recordset
Dim sql_rs As String
Dim sql_cmd As String
Dim sql_kc As String
Dim j As Integer
sql_rs = "select partid as '零件号',SUM(partnumber) as '库存' from T_part group by partid"
With rs
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_rs
.Open
End With
If rs.RecordCount > 0 Then
rs.MoveFirst
For j = 1 To rs.RecordCount
sql_kc = "select * from t_partno where partid='" & rs.Fields(0) & "'"
With rs_kc
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_kc
.Open
End With
If rs_kc.RecordCount < 1 Then
sql_cmd = "insert into t_partno values ('" & rs.Fields(0) & "','" & rs.Fields(1) & "')"
Else
sql_cmd = "update t_partno set number='" & rs.Fields(1) & "'where partid='" & rs.Fields(0) & "'"
End If
cmd.ActiveConnection = conn
cmd.CommandType = adCmdText
cmd.CommandText = sql_cmd
cmd.Execute
rs_kc.Close
rs.MoveNext
Next j
End If
End Sub
'Private Sub Timer3_Timer()
''Call Wait_S(5)
'Call Command1_Click
'End Sub
Sub jindu()
Rem 读取生产计划
Dim rs_os As New ADODB.Recordset
Dim sql_os As String
sql_os = "select * from t_os where time<'" & Time & "' and date='" & Date & "' order by time desc "
With rs_os
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sql_os
.Open
End With
If rs_os.RecordCount > 0 Then
Dim dp_i As Integer
Dim ys As Integer
rs_os.MoveFirst
rs_os.MoveNext
For dp_i = 2 To rs_os.RecordCount
ys = ys + CInt(Trim(rs_os.Fields(2)))
rs_os.MoveNext
Next dp_i
End If
End Sub
Private Sub Timer3_Timer()
Call Command1_Click
End Sub
Private Sub Timergundong_Timer()
Label10.Move Label10.Left, Label10.Top - 50
If Label10.Top < 4080 Then Label10.Top = 7500
Label11.Move Label11.Left, Label11.Top - 50
If Label11.Top < 4080 Then Label11.Top = 7500
Label16.Move Label16.Left, Label16.Top - 50
If Label16.Top < 4080 Then Label16.Top = 7500
Label9.Move Label9.Left, Label9.Top - 50
If Label9.Top < 4080 Then Label9.Top = 7500
Label12.Move Label12.Left, Label12.Top - 50
If Label12.Top < 4080 Then Label12.Top = 7500
End Sub
Private Sub Timerjishi_Timer()
Call Command2_Click
End Sub
'Private Sub Timerjishu_Timer()
'Dim DT1 As Date, DT2 As Date
'Dim Date1 As Date
'Dim S As Integer
'Dim SS As Long
'Dim Time1 As Date
'Dim Time2 As Date
'Date1 = Now
'Time1 = Now
'If jiepai_dp = 0 Then
' jishu_i = 0
'Else
' DT1 = CDate(Format(Date1, "yyyy-mm-dd") & " " & Format(Time1, "hh:mm:ss"))
' DT2 = CDate(Format(Now, "yyyy-mm-dd") & " " & Format(ks_dp, "hh:mm:ss"))
'
' SS = DateDiff("S", DT2, DT1) '计算出两个日期差多少秒
' jishu_i = SS \ 300
' Call Command3_Click
'End If
'End Sub
'Sub jiayi()
'Dim rs_jishu As New ADODB.Recordset
'Dim sql_jishu As String
'Dim cmd_jishu As New ADODB.Command
'Dim sql_cmd As String
'Dim shuliang_jiayi As Integer
'sql_jishu = "select * from t_jishu"
'
'With rs_jishu
' .ActiveConnection = conn
' .CursorLocation = adUseClient
' .CursorType = adOpenDynamic
' .LockType = adLockOptimistic
' .Source = sql_jishu
' .Open
'End With
'shuliang_jiayi = CInt(Trim(rs_jishu.Fields(1)))
'shuliang_jiayi = shuliang_jiayi + 1
'sql_cmd = "update t_jishu set shuliang='" & jishu_i & "' "
'cmd_jishu.ActiveConnection = conn
'cmd_jishu.CommandType = adCmdText
'cmd_jishu.CommandText = sql_cmd
'cmd_jishu.Execute
'rs_jishu.Close
'jishu_i = 0
'End Sub
Sub qingling()
Dim cmd_ql As New ADODB.Command
Dim sql_ql As String
sql_ql = "update T_jishu set shuliang='0'"
cmd_ql.ActiveConnection = conn
cmd_ql.CommandType = adCmdText
cmd_ql.CommandText = sql_ql
cmd_ql.Execute
End Sub ....看得我脑袋溢出先. 建议楼主尽量不要将系统关键字作为数据库表名、字段名或代码中的变量名使用
补充:VB , 数据库(包含打印,安装,报表)