Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何使用“退出循环”;关键词";_Vb.net - Fatal编程技术网

Vb.net 如何使用“退出循环”;关键词";

Vb.net 如何使用“退出循环”;关键词";,vb.net,Vb.net,这是我的密码: Dim n As String, upper As String, lower As String Label2.Text = "EXIT" Label3.Text = "exit" upper = Label2.Text Label2.Text = upper.ToUpper lower = Label3.Text Label3.Text = lower.ToLower Do

这是我的密码:

Dim n As String, upper As String, lower As String

    Label2.Text = "EXIT"
    Label3.Text = "exit"

    upper = Label2.Text
    Label2.Text = upper.ToUpper

    lower = Label3.Text
    Label3.Text = lower.ToLower

    Do
        Label1.Text = InputBox(" Enter a word. If you would like to quit, type: EXIT in the inputbox")
        n = Label1.Text
        Label1.Text = n.Length
        Label1.Text = Label1.Text & " letters"
    Loop Until n = ""
    Label1.Visible = False
    MsgBox(" Invalid value!")
    End

    Do
        Label1.Text = InputBox(" Enter a word. If you would like to quit, type: EXIT in the inputbox")
        n = Label1.Text
        Label1.Text = n.Length
        Label1.Text = Label1.Text & " letters"
    Loop Until upper = Label2.Text
    Label1.Visible = False
    MsgBox(" You have exited the program!")
    End

    Do
        Label1.Text = InputBox(" Enter a word. If you would like to quit, type: EXIT in the inputbox")
        n = Label1.Text
        Label1.Text = n.Length
        Label1.Text = Label1.Text & " letters"
    Loop Until lower = Label3.Text
    Label1.Visible = False
    MsgBox(" You have exited the program!")
    End

  

这个程序的问题是,当我运行它并按下取消按钮或X按钮退出时,它会正确地执行循环。但对于其他2个循环,当我以大写或小写形式键入“exit”或“exit”时,它只显示单词中的字符数,而不是结束程序。

当答案丢失时,我声明字符串“Label3”不是InputBox字符串defaultValue的一部分。使用“Label1”文本,不更改为保存为“Label2”或“Label3”

Do语句似乎使用整数数据类型进行迭代。样本可在页面上找到。 检索示例的协商导致选择字符或数字。直到布尔语句不被识别,再像上面那样重定向文本

循环直到n=“”

这是最简单的部分

整数值的换行不是布尔值所必需的。整数可以是布尔值。如果整数被分解,直到它们可以用于布尔逻辑,那么可能性可以用于迭代

因此,类似字符串的文本“Label1”不是一个明显的布尔值

    Public Class Form1        
        Private myValue As Object
        ReadOnly AntiPanel As New Label
        Private boolenValueTools As Boolean
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    
            Dim message, title, defaultValue As String
            ' Set prompt.
            message = " Enter a word. If you would like to quit, type: EXIT in the inputbox"
            ' Set title.
            title = "InputBox Demo"
            defaultValue = "1"   ' Set default value.
    
            '' Display dialog box at position 100, 100.
            'myValue = InputBox(message, title, defaultValue, 100, 100)
            '' If user has clicked Cancel, set myValue to defaultValue
            'If myValue Is "" Then myValue = defaultValue
    
            ' Display message, title, and default value.
            Do
                myValue = InputBox(message, title, defaultValue)
                If myValue = "EXIT" Then boolenValueTools = True
            Loop Until boolenValueTools = True
            ' If user has clicked Cancel, set myValue to defaultValue
            If myValue Is "" Then myValue = defaultValue
    
            Me.Controls.Add(AntiPanel)
            With AntiPanel
                .AutoSize = True
                .BackColor = Color.Transparent
                .Location = New Point(100, 100)
                .Font = New Font("Consolas", 55.75, FontStyle.Regular)
                .Text = myValue 'in my case also known as NotNamedInputBoxTextString
            End With
        End Sub
    End Class
我不能用一个将整个过程分开的答案来对这个问题进行抽样,而是发布一个退出循环的部分,将字符串链接到一个布尔值

    Public Class Form1        
        Private myValue As Object
        ReadOnly AntiPanel As New Label
        Private boolenValueTools As Boolean
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    
            Dim message, title, defaultValue As String
            ' Set prompt.
            message = " Enter a word. If you would like to quit, type: EXIT in the inputbox"
            ' Set title.
            title = "InputBox Demo"
            defaultValue = "1"   ' Set default value.
    
            '' Display dialog box at position 100, 100.
            'myValue = InputBox(message, title, defaultValue, 100, 100)
            '' If user has clicked Cancel, set myValue to defaultValue
            'If myValue Is "" Then myValue = defaultValue
    
            ' Display message, title, and default value.
            Do
                myValue = InputBox(message, title, defaultValue)
                If myValue = "EXIT" Then boolenValueTools = True
            Loop Until boolenValueTools = True
            ' If user has clicked Cancel, set myValue to defaultValue
            If myValue Is "" Then myValue = defaultValue
    
            Me.Controls.Add(AntiPanel)
            With AntiPanel
                .AutoSize = True
                .BackColor = Color.Transparent
                .Location = New Point(100, 100)
                .Font = New Font("Consolas", 55.75, FontStyle.Regular)
                .Text = myValue 'in my case also known as NotNamedInputBoxTextString
            End With
        End Sub
    End Class

在所有循环之前,
上限
下限
变量只设置一次。而且,这看起来不像VBA代码。您可能正在使用VB.NET。要准确地了解您在这里所做的事情有点困难,所以您可能需要更好地解释一下。就目前情况而言,首先我想问一下你做了什么调试?在每一点检查您的程序状态可能会给出答案。下一件事,你们确定“结束”是在你们每个循环后正确的点击方式吗?假设这是winforms应用程序中的一种方法,我怀疑这并不是你真正想要的结果。对于延迟,我在这篇文章创建之后就开始研究它,并通过一些尝试和错误最终修复了它。这是我在循环方面犯的一个小错误,现在可以正常工作了。