海鸥软件 2017-11-25 11:53 采纳率: 0%
浏览 1228

关于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条回答 默认 最新

  • threenewbee 2017-11-25 15:25
    关注

    If StopFlag Then
    If prN <> 1 Then

    prN = txtN
    

    Else

    prN = 1
    

    End If
    End If

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

    评论

报告相同问题?

悬赏问题

  • ¥15 CMAKE+VS2019+QT5.15.2组合进行二次编译
  • ¥15 nginx 配置静态html访问 ,后台登录时页面始终被重定向到登录页,无法访问到后台的静态html页
  • ¥20 自动登录的j2ee程序编译
  • ¥15 fluent模拟静态气体扩散
  • ¥15 java根据模板,生成word文档,需要带目录
  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 关于cpci总线的几个问题,别用人工智能回答
  • ¥15 乳腺癌数据集 相关矩阵 特征选择