[英]if statements with multiple conditions
在过去的一周中,我一直在到处寻找信息。 我有一个小型console application
,它会向用户询问一系列问题并将答案存储在变量中。 我想要做的是将这些答案与一系列条件进行比较(在这种情况下为焊接过程),然后选择与所有条件匹配的过程。 我尝试使用if和语句执行此操作,但该程序仅使用我的第一个If语句,并且不尝试进行任何比较。显然,我做错了很多。这是我的代码:
Dim r As String
Dim a As String
Dim x As Double
Dim y As Double
Dim z As String
Dim v As String
Dim t As String
Dim b As String
Dim i As Double
Console.WriteLine("Is this for pipeline or facility?")
t = Console.ReadLine()
Console.WriteLine("Is this a repair procedure?")
b = Console.ReadLine()
Console.WriteLine("Is this CSA or ASME?")
r = Console.ReadLine()
Console.WriteLine("Registered with BCSA or ABSA?")
a = Console.ReadLine()
If a = "" Then
a = "bcsa"
End If
Console.WriteLine("Please Enter a Pipe Size")
x = Console.ReadLine()
Console.WriteLine("Please Enter a Wall Thickness")
y = Console.ReadLine()
Console.WriteLine("What is the Grade?")
z = Console.ReadLine()
If r = "ASME" Then
Console.WriteLine("Please Enter the Material Group e.x: Group 1, 2, 3..")
v = Console.ReadLine()
Else
v = 1000
End If
Console.WriteLine("Please enter an Impact Temperature (numerical values only please)")
i = Console.ReadLine()
If i = "" Then
i = "0"
End If
If t = "facility" And r = "asme" And a = "bcsa" & x <= 100 & x > 0 & y <= 25.4 & y >= 1.5748 & z = "p1" & v >= 1 & v <= 3 & i >= -40 Then
Console.WriteLine("I suggest the Weld Procedure MII-13-FAB11 Rev.1_BCSA")
Console.WriteLine("Would you like to open this file?")
If Console.ReadLine() = "yes" Then
Dim yes As String = "Q:\Macro Database\Use\MII-13-FAB11 Rev.1_BCSA Reg..pdf"
Process.Start(yes)
ElseIf Console.ReadLine() = "no" Then
Console.WriteLine("Okay fair enough. Thank you for using Citrus WPS Selection tool.")
End If
End If
'MII-13-FAB11 Rev.0_ABSA
If t = "facility" & r = "asme" & a = "absa" & x <= 100 & x > 0 & y <= 25.4 & y >= 1.5748 & z = "p1" & v >= 1 & v <= 3 & i >= -40 Then
Console.WriteLine("I suggest the Weld Procedure MII-13-FAB11 Rev.0_ABSA")
Console.WriteLine("Would you like to open this file?")
If Console.ReadLine() = "yes" Then
Dim yes As String = "Q:\Macro Database\Use\MII-13-FAB11 Rev.0_ABSA Reg..pdf"
Process.Start(yes)
ElseIf Console.ReadLine() = "no" Then
Console.WriteLine("Okay fair enough. Thank you for using Citrus WPS Selection tool.")
End If
End If
' MII-10-PL4 Rev.1
If t = "pipeline" & b = "no" & r = "csa" & a = "bcsa" & x <= 323.9 & x > 0 & y <= 12.84 & y >= 1.5 & z <= 386 & i >= -20 Then
Console.WriteLine("I suggest the Weld Procedure MII-10-PL4 Rev.1")
Console.WriteLine("Would you like to open this file?")
If Console.ReadLine() = "yes" Then
Dim yes As String = "Q:\Macro Database\Use\MII-10-PL4 Rev.1.pdf"
Process.Start(yes)
ElseIf Console.ReadLine() = "no" Then
Console.WriteLine("Okay fair enough. Thank you for using Citrus WPS Selection tool.")
End If
End If
我只希望包括三个过程,以便给出要点。 因此在“ If”语句上,我尝试使用"And", "ElseOr", "&", "Or"..
当我进入并在Visual Studio中运行此代码时,它会自动默认为焊接优先程序。 我查看了Select Case
块,但不确定如何使用它们对这些信息进行排序? 任何帮助深表感谢! 我真的不太确定自己在做什么是否部分正确!
感谢大家!
您在使用&
时应使用And
(或AndAlso
)
在VB.NET中:
&
运算符“生成两个表达式的字符串连接。”
And
运算符“ 对两个布尔表达式执行逻辑连接 ,或对两个数值表达式执行按位连接”
我怀疑您实际上要使用与And
相同的AndAlso
,但如果结果之一为false,则将布尔表达式短路为False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.