• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 66
  • Last Modified:

IF STATEMENT ISSUE

This is my code for a trouble shooting system: The problem is that because there is two ifs with the same statement it won't work. However I know I could change it to a select case format however that's were I'm uncertain and how to proceed
This isn't the finished version I am working in Vb.net :
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim problem As String
        TextBox1.Focus()
        problem = TextBox1.Text
        If TextBox1.Text = "bad" Then
            Label2.Text = "Sorry but to start off with what make is your phone?"
        ElseIf TextBox1.Text = "good" Then
            Label2.Text = "Thats good to hear but to start off with what make is your phone?"
        ElseIf TextBox1.Text = " i dont know" Then
            Label2.Text = " Okay. To start off with what make is your phone?"
        End If
        TextBox1.Text = ""



        If problem = "iphone" Then
            Label2.Text = " What problems are you having with your iphone,?" + Environment.NewLine + "is your problem related to screen"
        ElseIf problem = "android" Then
            Label2.Text = " What problems are you having with your android device," + Environment.NewLine + "is your problem related to screen "
        ElseIf problem = "blackberry" Then
            Label2.Text = "What problems are you having with your blackberry device" + Environment.NewLine + "Is your problem related to screen" + Environment.NewLine + " Please enter yes or no to the following questions!"
        End If


        Dim count (music) As String
        count (o) = "Has the screen got wet in the last 24 hours?"
        count(1) = "Is the screen of the device cracked?"
        count(2) = "Is your screen slow and crashing?"
        count(3) = " Is your touch screen not responding"
        count(4) = "Do you have sufficent funds in your account  send text messages"
        count(5) = "Are you able to recieve text messages and send texts?"
        count (devil) = " Do you have suffiencent funds in your account?"
        count(7) = "Are you connected to wifi or have sufficient funds to use data"

        TextBox1.Focus()
        If problem = "yes" Then
            Label2.Text = count (o)
        If problem = "yes" Then
            Label2.Text = "Try removing the back casing and wiping the back of the phone"
            If problem = "no" Then
                Label2.Text = count(1)
                If problem = "yes" Then
                    Label2.Text = " You will need to get your device's screen fixed for continued usage"
                    If problem = "no" Then
                        Label2.Text = count(2)
                        If problem = "yes" Then
                            Label2.Text = " Close the apps that are not in use and also try and turn your phone off and back on again"
                            If problem = "no" Then
                                Label2.Text = count(3)
                                If problem = "yes" Then
                                    Label2.Text = "The best solution is to take your phone to the local care centre as your LCD may be broken if there is no response "
                                    If problem = "no" Then
                                        Label2.Text = "If you have any more screen related queries you will need to contact 03001234567"
                                    ElseIf problem = "no" Then
                                        Label2.Text = "Is your problem related to text messages?"
                                        If problem = "yes" Then
                                            Label2.Text = count(4)

                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If

                End If
            End If
        End If
        End If
    End Sub

    Private Sub Label2_Click(sender As System.Object, e As System.EventArgs) Handles Label2.Click
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Label2.Text = "Welcome to the trouble shooting system. How are you doing today?"
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label2.Text = "Welcome to the trouble shooting system. How are you doing today?"
    End Sub
End Class

Open in new window

0
Yasmin Rodriguez
Asked:
Yasmin Rodriguez
  • 6
  • 3
3 Solutions
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>two ifs with the same statement it won't work.

How do you expect the following logic to work?

if true do something or something else - which one you choose is up to you

Until you get the logic sorted out you won't get anywhere.

ps.  Do you know about something like the following?
if X and Y then....
else if X then ....
0
 
Yasmin RodriguezAuthor Commented:
Firstly thank you for your comment. However i dont understand. How would i lay it out would i write
if true yes
or something else of that sort
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You need to draw out on paper what happens when.
You can NOT do two different things based on checking just one value (assuming you really want two different alternatives, not one after the other).

First decide what should be done based on what condition.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Yasmin RodriguezAuthor Commented:
This is how i want the program to be run
if the user says yes the problem is screen related to displays count(0)
if its says yes to the question in count(0) the program gives the user a solution
alternatively if the users says no to count(0) it moves to count(1)
if it says no it isnt screen related it moves to the text message questions
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
OK.
So ask the question you want inside the if statement by displaying a dialog with the question on it.  (Or move to another screen like a 'wizard' style)
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Please post what you will be doing / what the advice was especially if different to what I suggested here
0
 
David Johnson, CD, MVPOwnerCommented:
Duplicated Code
 Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Label2.Text = "Welcome to the trouble shooting system. How are you doing today?"
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label2.Text = "Welcome to the trouble shooting system. How are you doing today?"
    End Sub

Open in new window


suggest you dim your text strings
i.e.
dim strWelcome as String = "Welcome to the trouble shooting system. How are you doing today?"
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Label2.Text = strWelcome
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label2.Text = strWelcome
    End Sub 

Open in new window


       Label2.Text = "Sorry but to start off with what make is your phone?"
        ElseIf TextBox1.Text = "good" Then
            Label2.Text = "Thats good to hear but to start off with what make is your phone?"
        ElseIf TextBox1.Text = " I don't know" Then
            Label2.Text = " Okay. To start off with what make is your phone?"
        End If
        TextBox1.Text = ""
		Label2.Text = What problems are you having with your" + problem + ",?" + Environment.NewLine + "is your problem related to the screen"
' sleep 3 seconds
        
        Label2.Text = " Please enter yes or no to the following questions!"
  

Open in new window


I would use radio buttons instead.. What if someone answers 'Blackberry', 'Samsung', 'LG', 'iPhone'.  'i-Phone'

you don't have a loop to display the problems?
same problem if user enters 'Y" 'N', Yes,YES,No,NO.. tolower() can help here,

As you ask a question store the answer in an array I'd use a boolean True,False now you can loop through your suggestions using a for/next loop, Again I'd have the proposed solutions in a Text Array

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim problem As String
        TextBox1.Focus()
        problem = TextBox1.Text.tolower()
        If TextBox1.Text = "bad" Then
            Label2.Text = "Sorry but to start off with what make is your phone?"
        ElseIf TextBox1.Text = "good" Then
            Label2.Text = "Thats good to hear but to start off with what make is your phone?"
        ElseIf TextBox1.Text = " i dont know" Then
            Label2.Text = " Okay. To start off with what make is your phone?"
        End If
        TextBox1.Text = ""
		Label2.Text = What problems are you having with your" + problem + ",?" + Environment.NewLine + "is your problem related to the screen"
' sleep 3 seconds
        
        Label2.Text = " Please enter yes or no to the following questions!"
  

        Dim count (music) As String
        count (0) = "Has the screen got wet in the last 24 hours?"
        count(1) = "Is the screen of the device cracked?"
        count(2) = "Is your screen slow and crashing?"
        count(3) = " Is your touch screen not responding"
        count(4) = "Do you have sufficent funds in your account  send text messages"
        count(5) = "Are you able to recieve text messages and send texts?"
        count (6) = " Do you have suffiencent funds in your account?"
        count(7) = "Are you connected to wifi or have sufficient funds to use data"

        TextBox1.Focus()
        If problem = "yes" Then
            Label2.Text = count (o)
        If problem = "yes" Then
            Label2.Text = "Try removing the back casing and wiping the back of the phone"
            If problem = "no" Then
                Label2.Text = count(1)
                If problem = "yes" Then
                    Label2.Text = " You will need to get your device's screen fixed for continued usage"
                    If problem = "no" Then
                        Label2.Text = count(2)
                        If problem = "yes" Then
                            Label2.Text = " Close the apps that are not in use and also try and turn your phone off and back on again"
                            If problem = "no" Then
                                Label2.Text = count(3)
                                If problem = "yes" Then
                                    Label2.Text = "The best solution is to take your phone to the local care centre as your LCD may be broken if there is no response "
                                    If problem = "no" Then
                                        Label2.Text = "If you have any more screen related queries you will need to contact 03001234567"
                                    ElseIf problem = "no" Then
                                        Label2.Text = "Is your problem related to text messages?"
                                        If problem = "yes" Then
                                            Label2.Text = count(4)

                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If

                End If
            End If
        End If
        End If
    End Sub

    Private Sub Label2_Click(sender As System.Object, e As System.EventArgs) Handles Label2.Click
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Label2.Text = "Welcome to the trouble shooting system. How are you doing today?"
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label2.Text = "Welcome to the trouble shooting system. How are you doing today?"
    End Sub
End Class

Open in new window

0
 
Yasmin RodriguezAuthor Commented:
I'm displaying my answers in a select case format which means I would like to delete this question know however I'm very grateful for the help
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>I'm displaying my answers in a select case format
OK, but how does that work with your original logic.  You had if the response is 'yes' then I want to do X but for another version of 'yes' instead do Y but for another version of 'yes' do Z.  
select
  case 'yes'
  case 'yes'
  case 'yes'
end select
doesn't work.

Note I first said you needed to get the logic of what is to be done when before you could start writing the code.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
The logic of what is to be done must be in place before attempting to write any code.  The code from David Johnson is an example of one possible way to do it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now