过去一周我一直在寻找各地试图解决这个问题。我有一个小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
我只提供了三个程序,希望能给出它的要点。所以&#34;如果&#34;我尝试使用的语句"And", "ElseOr", "&", "Or"..
当我在Visual Studio中进入并运行此代码时,它会自动默认为焊接第一个过程。我查看了Select Case
块,我不确定如何用这些信息对它们进行排序?任何帮助深表感谢!我真的不太确定我所做的事情是否部分正确!
谢谢大家!
答案 0 :(得分:0)
当您使用&
(或And
)时,您正在使用AndAlso
在VB.NET中: -
&
运算符“生成两个表达式的字符串连接。”
And
运算符“对两个布尔表达式执行逻辑连接,或对两个数字表达式执行按位连接”
我怀疑你实际上想要使用与AndAlso
相同的And
,但如果其中一个结果为假,则将布尔表达式短路为False