Solved

IF STATEMENT ISSUE

Posted on 2016-10-28
13
48 Views
Last Modified: 2016-11-17
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
Comment
Question by:Yasmin Rodriguez
  • 6
  • 3
13 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 250 total points (awarded by participants)
Comment Utility
>>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
 

Author Comment

by:Yasmin Rodriguez
Comment Utility
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
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 250 total points (awarded by participants)
Comment Utility
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
 

Author Comment

by:Yasmin Rodriguez
Comment Utility
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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Please post what you will be doing / what the advice was especially if different to what I suggested here
0
 
LVL 78

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 250 total points (awarded by participants)
Comment Utility
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
 

Author Comment

by:Yasmin Rodriguez
Comment Utility
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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now