Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IF STATEMENT ISSUE

Posted on 2016-10-28
13
Medium Priority
?
60 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 1000 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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 83

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

704 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