0

I have been looking everywhere for the past week trying to figure this out. I have a small console application which asks the user a series of questions and stores the answers in variables. What I would like it to do is compare these answers against a series of conditions (welding procedures in this case) then select the procedure that matches all of the conditions. I tried doing this using if and statements but the program only uses my first If statement and does not try to compare anything... Clearly I am doing something quite wrong.. Here's my code:

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

I only included three procedures hopefully that gives the gist of it. so on the "If" statements I tried to use "And", "ElseOr", "&", "Or".. When I step into and run through this code in visual studio it Automatically defaults to the very weld first procedure. I looked at the Select Case blocks I am unsure how to sort this information with them? Any help is much appreciated! I'm really not too sure if what I am doing is even partially correct!

Thanks Everyone!

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
Kyle Moffat
  • 163
  • 1
  • 2
  • 17

1 Answers1

0

You are using & when you should be using And (or AndAlso)

In VB.NET:-

The & Operator "Generates a string concatenation of two expressions."

The And operator "Performs a logical conjunction on two Boolean expressions, or a bitwise conjunction on two numeric expressions"

I suspect that you actually want to use AndAlso which does the same as And but short-circuits the boolean expression to False if one of the results is false

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143