简体   繁体   English

vbnet的if语句

[英]If statement for vbnet

I want to make an if statement with conditions that have 2 result 我想做一个if语句,条件为2

Example

if (id = "25" OR "36") then
print "The id is 25 or 36"
else
print "the id is not 25 or 36"
end if

My concern is in the if condition statement for "OR" 我担心的是if条件语句中的“ OR”

I try with "AND" but this only takes id = 25 as true whereas id = 36 as false 我尝试使用“ AND”,但这仅将id = 25设为true,而id = 36设为false

I try with "OR" "ORELSE" "XOR" this takes everything as true. 我尝试使用“ OR”,“ ORELSE”,“ XOR”将所有内容视为真实。

I try || 我尝试|| sign but I got syntax error 标志,但语法错误

您在或之后缺少比较项:

If (id = "25" Or id = "36") Then

You need to provide the variable to check each time 您需要提供变量以进行每次检查

If id = "25" or id = "36" Then

Alternatively, if this is likely to expand to include other numbers, you could use 或者,如果此数字可能会扩展为包括其他数字,则可以使用

If {"25","36"}.Contains(id) Then

Alternatively, you could use a Select Case statement: 另外,您可以使用Select Case语句:

Select Case id
     Case "25", "36"
          Print("The id is 25 or 36")
     Case Else
          Print("The id is not 25 or 36")
End Select

This works the same way as an if..else statement, but allows you to easily supply different test expressions. 这与if..else语句的工作方式相同,但是使您可以轻松提供不同的测试表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM