+ -
当前位置:首页 → 问答吧 → 请教一下这段代码会不会让程序崩溃?

请教一下这段代码会不会让程序崩溃?

时间:2011-11-01

来源:互联网

VB code


While btnItem.Count > 1
        Unload btnItem(btnItem.Count - 1)
    Wend
    DoEvents
    
    While btnPrice.Count > 1
        Unload btnPrice(btnPrice.Count - 1)
    Wend
    DoEvents
    
    While BtnPic.Count > 1
        Unload BtnPic(BtnPic.Count - 1)
    Wend
    DoEvents
    
    If pPayment = "" Then
        
        picMain.Visible = True
        For iCtr = frmMainTS.grdItem.RowCount To 1 Step -1
            With frmMainTS.grdItem
                .Row = iCtr
                If .Value(4) <> "" Then
                    If jCtr > 10 Then Exit For
                    sPrnLn = PADR(.Value(4), 6) & PADLChinese(Mid(.Value(5), 1, 24), 24)
                    sPrnLn1 = PADL(Trim$(.Value(8)), 8)
                    
                    If jCtr = 0 Then
                        btnItem(0).Caption = Trim(sPrnLn)
                        btnItem(0).Visible = True
                        btnPrice(0).Caption = Trim(sPrnLn1)
                        btnPrice(0).Visible = True
                        BtnPic(0).Visible = True
                        BtnPic(0).Move btnItem(0).Left, btnItem(0).Height + btnItem(0).Top, Pic2.Width
                    Else
                        Load btnItem(jCtr)
                        btnItem(jCtr).Caption = ""
                        btnItem(jCtr).Tag = ""
                        btnItem(jCtr).Visible = True
                            
                        Load btnPrice(jCtr)
                            
                        btnPrice(jCtr).Caption = ""
                        'btnPrice(jCtr).CaptionAlign = vbRightJustify
                        btnPrice(jCtr).Tag = ""
                        btnPrice(jCtr).Visible = True
                            
                        Load BtnPic(jCtr)
                        
                        BtnPic(jCtr).Visible = True
                        
                        btnItem(jCtr).Move btnItem(0).Left, btnItem(jCtr - 1).Top + btnItem(jCtr - 1).Height + BtnPic(jCtr).Height, _
                                            btnItem(0).Width, btnItem(0).Height
                        btnItem(jCtr).Caption = Trim(sPrnLn)
                        
                        btnPrice(jCtr).Move btnPrice(0).Left, btnPrice(jCtr - 1).Top + btnPrice(jCtr - 1).Height + BtnPic(jCtr).Height, _
                                            btnPrice(0).Width, btnPrice(0).Height
                                            
                        btnPrice(jCtr).Caption = Trim(sPrnLn1)
                        
                        BtnPic(jCtr).Move btnItem(0).Left, btnItem(jCtr).Height + btnItem(jCtr).Top, Pic2.Width
                    End If
                    jCtr = jCtr + 1
                Else
                    sPrnLn = Space(8) & "- " & Trim(.Value(5))
                End If
                DoEvents
                .MoveNext
            End With
        Next
        
        pItemCount = jCtr
        MainpictureMove
        
        'show Total&qty
        PicTotal.Visible = True
        PicTotal.Move Pic7.Left, Pic7.Top + Pic7.Height + 200, Pic7.Width, PicTotal.Width
        total.Visible = True
        total.Width = PicTotal.Width
        total.Caption = PADR("TOTAL :", 15) & PADL(Trim$(oCurrency.FormatCurrency(sTotal)), 10)
        
        Cash(0).Visible = True
        Cash(0).Width = PicTotal.Width
        Cash(0).Caption = PADR("Total Qty:", 15) & PADL(frmMainTS.txtTotalQty.Caption, 10)
        
        change.Visible = False
        
    Else
        picMain.Visible = False
        PicTotal.Visible = True
        
        PicTotal.Move Pic2.Left, Pic6.Top, Pic2.Width, 5 * (total.Height)
        
        While Cash.Count > 1
            Unload Cash(Cash.Count - 1)
        Wend
        DoEvents
        
        total.Visible = True
        total.Width = PicTotal.Width
        total.Caption = PADR("TOTAL", 15) & PADL(Trim$(oCurrency.FormatCurrency(sTotal)), 10)
        
        
        sPlitGst() = Split(pPayment, "|")
        For iCtr = 0 To UBound(sPlitGst)
            sPrnLn = Left(sPlitGst(iCtr), InStr(sPlitGst(iCtr), ",") - 1)
            sAmount = Replace(sPlitGst(iCtr), sPrnLn & ",", "")
            sPrnLn = PADR(sPrnLn, 15) & PADL(Trim$(oCurrency.FormatCurrency(sAmount)), 10)
            If iCtr = 0 Then
                Cash(0).Visible = True
                Cash(0).Width = PicTotal.Width
                Cash(0).Caption = sPrnLn
                
            Else
                If iCtr > 2 Then Exit For
                Load Cash(iCtr)
                
                Cash(iCtr).Visible = True
                Cash(iCtr).Move Cash(0).Left, Cash(iCtr - 1).Top + Cash(iCtr - 1).Height, Cash(0).Width, Cash(0).Height
                Cash(iCtr).Caption = sPrnLn
            End If
            
        Next iCtr

        If pChanges <> 0 Then
        
            sPrnLn = PADR("CHANGE ", 15) & PADL(Trim$(oCurrency.FormatCurrency(pChanges)), 10)
            change.Visible = True
            change.Move Cash(0).Left, Cash(iCtr - 1).Top + Cash(iCtr - 1).Height, Cash(0).Width, Cash(0).Height
            
        End If
    
    End If


这个程序用于双屏幕中,所以FORM是不会消失的,但是不停的UNLOAD和LOAD控件,会影响程序的运行吗?

作者: lxq19851204   发布时间: 2011-11-01

。。。。一个注释都没

作者: sysdzw   发布时间: 2011-11-01

引用 1 楼 sysdzw 的回复:

。。。。一个注释都没

同上

作者: BestBadGod   发布时间: 2011-11-01

VB code
While btnItem.Count > 1   '注销显示ITEM的按钮数量
        Unload btnItem(btnItem.Count - 1)
    Wend
    DoEvents
    
    While btnPrice.Count > 1        '注销显示ITEM PRICE的按钮数量
        Unload btnPrice(btnPrice.Count - 1)
    Wend
    DoEvents
    
    While BtnPic.Count > 1          '注销LABEL的按钮数量
        Unload BtnPic(BtnPic.Count - 1)
    Wend
    DoEvents
    
    If pPayment = "" Then    '当单据还没付款
        
        picMain.Visible = True
        For iCtr = frmMainTS.grdItem.RowCount To 1 Step -1    '双屏幕显示按钮从下到上 
            With frmMainTS.grdItem
                .Row = iCtr
                If .Value(4) <> "" Then
                    If jCtr > 10 Then Exit For
                    sPrnLn = PADR(.Value(4), 6) & PADLChinese(Mid(.Value(5), 1, 24), 24) '
                    sPrnLn1 = PADL(Trim$(.Value(8)), 8)
                    
                    If jCtr = 0 Then
                        btnItem(0).Caption = Trim(sPrnLn)
                        btnItem(0).Visible = True
                        btnPrice(0).Caption = Trim(sPrnLn1)
                        btnPrice(0).Visible = True
                        BtnPic(0).Visible = True
                        BtnPic(0).Move btnItem(0).Left, btnItem(0).Height + btnItem(0).Top, Pic2.Width
                    Else
                        Load btnItem(jCtr)
                        btnItem(jCtr).Caption = ""
                        btnItem(jCtr).Tag = ""
                        btnItem(jCtr).Visible = True
                            
                        Load btnPrice(jCtr)
                            
                        btnPrice(jCtr).Caption = ""
                        'btnPrice(jCtr).CaptionAlign = vbRightJustify
                        btnPrice(jCtr).Tag = ""
                        btnPrice(jCtr).Visible = True
                            
                        Load BtnPic(jCtr)
                        
                        BtnPic(jCtr).Visible = True
                        
                        btnItem(jCtr).Move btnItem(0).Left, btnItem(jCtr - 1).Top + btnItem(jCtr - 1).Height + BtnPic(jCtr).Height, _
                                            btnItem(0).Width, btnItem(0).Height
                        btnItem(jCtr).Caption = Trim(sPrnLn)
                        
                        btnPrice(jCtr).Move btnPrice(0).Left, btnPrice(jCtr - 1).Top + btnPrice(jCtr - 1).Height + BtnPic(jCtr).Height, _
                                            btnPrice(0).Width, btnPrice(0).Height
                                            
                        btnPrice(jCtr).Caption = Trim(sPrnLn1)
                        
                        BtnPic(jCtr).Move btnItem(0).Left, btnItem(jCtr).Height + btnItem(jCtr).Top, Pic2.Width
                    End If
                    jCtr = jCtr + 1
                Else
                    sPrnLn = Space(8) & "- " & Trim(.Value(5))
                End If
                DoEvents
                .MoveNext
            End With
        Next
        
        pItemCount = jCtr
        MainpictureMove
        
        'show Total&qty
        PicTotal.Visible = True
        PicTotal.Move Pic7.Left, Pic7.Top + Pic7.Height + 200, Pic7.Width, PicTotal.Width
        total.Visible = True
        total.Width = PicTotal.Width
        total.Caption = PADR("TOTAL :", 15) & PADL(Trim$(oCurrency.FormatCurrency(sTotal)), 10)
        
        Cash(0).Visible = True
        Cash(0).Width = PicTotal.Width
        Cash(0).Caption = PADR("Total Qty:", 15) & PADL(frmMainTS.txtTotalQty.Caption, 10)
        
        change.Visible = False
        
    Else
        picMain.Visible = False
        PicTotal.Visible = True
        
        PicTotal.Move Pic2.Left, Pic6.Top, Pic2.Width, 5 * (total.Height)
        
        While Cash.Count > 1
            Unload Cash(Cash.Count - 1)
        Wend
        DoEvents
        
        total.Visible = True
        total.Width = PicTotal.Width
        total.Caption = PADR("TOTAL", 15) & PADL(Trim$(oCurrency.FormatCurrency(sTotal)), 10)
        
        
        sPlitGst() = Split(pPayment, "|")
        For iCtr = 0 To UBound(sPlitGst)
            sPrnLn = Left(sPlitGst(iCtr), InStr(sPlitGst(iCtr), ",") - 1)
            sAmount = Replace(sPlitGst(iCtr), sPrnLn & ",", "")
            sPrnLn = PADR(sPrnLn, 15) & PADL(Trim$(oCurrency.FormatCurrency(sAmount)), 10)
            If iCtr = 0 Then
                Cash(0).Visible = True
                Cash(0).Width = PicTotal.Width
                Cash(0).Caption = sPrnLn
                
            Else
                If iCtr > 2 Then Exit For
                Load Cash(iCtr)
                
                Cash(iCtr).Visible = True
                Cash(iCtr).Move Cash(0).Left, Cash(iCtr - 1).Top + Cash(iCtr - 1).Height, Cash(0).Width, Cash(0).Height
                Cash(iCtr).Caption = sPrnLn
            End If
            
        Next iCtr

        If pChanges <> 0 Then     '有找换钱的时候
        
            sPrnLn = PADR("CHANGE ", 15) & PADL(Trim$(oCurrency.FormatCurrency(pChanges)), 10)
            change.Visible = True
            change.Move Cash(0).Left, Cash(iCtr - 1).Top + Cash(iCtr - 1).Height, Cash(0).Width, Cash(0).Height
            
        End If
    
    End If

作者: lxq19851204   发布时间: 2011-11-01

刚刚有客户拖住我了,我等会回去注释一下~~

作者: lxq19851204   发布时间: 2011-11-01

error handler 呢?

作者: patrickkong   发布时间: 2011-11-01