hsgzr1
海鸥软件
采纳率0%
2017-11-25 11:53 阅读 1.2k

关于vb不能退出窗体问题

今天由于试验一个数据,没有采取递归方法,做了一个简单的笨笨的字符串组合程序, 设了一个退出标志
stopflag 为true时跳出循环,可程序就是不跳出,所以造成窗体退不出,大家给看看,问题出在哪里?

Option Explicit

Private StopFlag As Boolean

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private val As Long

Private prN As Integer

Private Const Str = "abcdefghijklmnopqrstuvwxyz1234567890"

Private Sub Command1_Click()

Dim i As Integer

Dim ii As Integer

Dim iii As Integer

Dim iiii As Integer

Dim iiiii As Integer

Dim n As Integer

Dim s As String

Dim s1 As String

Dim L As Integer

L = Len(Str)

prN = 1

If StopFlag Then

If prN <> 1 Then

    prN = txtN

Else

    prN = 1

End If

End If

s = ""

StopFlag = False

For iiiii = 1 To L

    txti(4) = iiiii

    For iiii = 1 To L

        txti(3) = iiii

        For iii = 1 To L

            txti(2) = iii

            For ii = 1 To L

                txti(1) = ii

                For i = 1 To L

                    Select Case prN

                        Case 1: s = Mid(Str, i, 1)

                        Case 2: s = Mid(Str, ii, 1) & Mid(Str, i, 1)

                        Case 3: s = Mid(Str, iii, 1) & Mid(Str, ii, 1) & Mid(Str, i, 1)

                        Case 4: s = Mid(Str, iiii, 1) & Mid(Str, iii, 1) & Mid(Str, ii, 1) & Mid(Str, i, 1)

                        Case 5: s = Mid(Str, iiiii, 1) & Mid(Str, iiii, 1) & Mid(Str, iii, 1) & Mid(Str, ii, 1) & Mid(Str, i, 1)

                    End Select

                    'Call ShowResults(s) 这里的过程我注释掉也不行

                    txti(0) = i

                    prN = 1

                                                If StopFlag Then GoTo Exit_    '发现StopFlag的值不改变

                                                DoEvents    '后来加了一个这个
                Next

                prN = 2

            Next

             prN = 3

        Next

         prN = 4

    Next

    prN = 5

Next

Exit Sub

Exit_:

prN = 99  '这里设了个值是为了检查这个值的变化

End Sub

Private Sub Command2_Click()

StopFlag = True

End Sub

Private Sub Command3_Click()

StopFlag = False

End Sub

Private Sub Command4_Click()

StopFlag = True

n = 1

End Sub

'主要是下面这个过程
Private Sub Command5_Click()

StopFlag = True ‘停止循环标志

Sleep (5000) '后来加了一个延时 也不行

Unload Me

End Sub

Private Sub Form_Load()

prN = 1

StopFlag = False

End Sub

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • caozhy 从今以后生命中的每一秒都属于我爱的人 2017-11-25 15:25

    If StopFlag Then
    If prN <> 1 Then

    prN = txtN
    

    Else

    prN = 1
    

    End If
    End If

    这个判断要写在循环的最里层

    点赞 1 评论 复制链接分享

相关推荐