vb.net - 这有什么问题?(我搜索了几个小时的错误)
问题描述
我有这个代码
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Location1 As String
Dim city As Boolean
Dim sss As Boolean
If Not IsNumeric(TextBox1.Text) Then
MsgBox("Invalid ip address")
Else
city = True
sss = False
geoip()
If Label1.Text = "" Or Label1.Text = " " Then
city = False
Else
city = True
Location1 = Label1.Text
End If
If city = False And Label16.Text = "" Or Label16.Text = " " Then
Location1 = Label17.Text
Else
sss = True
End If
If sss = True Then
Location1 = Label16.Text
End If
End If
TextBox1.Text = ""
If CheckBox2.Checked = True Then
TextBox2.Text = "We look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
If CheckBox1.Checked = True Then
TextBox2.Text = "My name is " + TextBox3.Text + " from " + TextBox4.Text + " and im here for letting you know that we look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
TextBox1.Text = ""
End Sub
而且它没有按预期工作。即使 label1 不是""
或" "
标签 16 也会显示,我在代码中搜索了很长时间的错误,但我认为一切都很好
解决方案
我现在明白了你的问题 - 我留下了我的旧答案,因为括号条件是正确的,你的代码仍然会损坏,但你的问题是你有你If ... else
的 s 这样你就会陷入else
你不想要的地方到。
例如 - 在您的代码中考虑这一行:
If city = False And Label16.Text = "" Or Label16.Text = " " Then
Location1 = Label17.Text
Else
sss = True
End If
如果 city 为 true 或者标签 16 中包含某些内容,则会受到影响。如果 city 仍然为 false并且标签 16 中有else
某些内容,您只会希望它到达那里。
而是专注于通过嵌套条件逻辑来执行逻辑。此代码应按预期工作:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Location1 As String
Dim city As Boolean
Dim sss As Boolean
If Not IsNumeric(TextBox1.Text) Then
MsgBox("Invalid ip address")
Else
geoip()
If Label1.Text.Trim() = "" Then
city = False
If Label16.Text.Trim() = "" Then
Location1 = Label17.Text
Else
sss = True
Location1 = Label16.Text
End If
Else
city = True
Location1 = Label1.Text
End If
End If
TextBox1.Text = ""
If CheckBox2.Checked = True Then
TextBox2.Text = "We look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
If CheckBox1.Checked = True Then
TextBox2.Text = "My name is " + TextBox3.Text + " from " + TextBox4.Text + " and im here for letting you know that we look forward to meet you tomorrow at the meeting place at 1 PM, the package has been shipped already to you to " + Location1 + ". If you wont be there for completing the transaction, we will need to proceed to stage 2."
End If
TextBox1.Text = ""
End Sub
推荐阅读
- django - Django 不支持的语言集成
- r - 如何使用 heatmply R 包为交互式热图正确分配低、中和高颜色限制
- powershell - 将 NULL 从 powershell 传递给 sql
- asp.net-mvc - 测试进行外部 API 调用的控制器操作
- android - Android Room DB - 在查询中使用来自另一个类的静态变量
- angular - 如何修复 ag-grid 表的响应性?
- r - R - 从具有不同列数的数据列表创建数据框
- php - 捆绑特定的异常侦听器
- c - C: if(a
为什么以下 if 语句返回 1(真)?
int main() { short a = 1; short b = 5; short c = 4; if (a<b<c) printf("true \n"); else printf("false \n"); return 0; }
- mysql - 需要从同一张表上的插入触发器插入第二个数据行的替代方法