Solved

IF STATEMENT ISSUE

Posted on 2016-10-28
13
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
13 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 250 total points (awarded by participants)
ID: 41864958
>>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
ID: 41865085
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)
ID: 41865104
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:Yasmin Rodriguez
ID: 41865111
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
ID: 41865124
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41865135
Please post what you will be doing / what the advice was especially if different to what I suggested here
0
 
LVL 82

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 250 total points (awarded by participants)
ID: 41865328
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
ID: 41865374
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
ID: 41865402
>>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
ID: 41891153
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

617 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