1,105,197 Community Members

Absolute Beginner - Test Application Help!

Member Avatar
aaronoafc
Newbie Poster
2 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I'm a programming beginner and currently learning VB.net as a starting language. I have just been making a little test console application using visual studio asking about favourite football teams, please could someone tell me what I'm doing wrong? Below is the code, now I want the user to be able to type in their team "Oldham, Man city etc" Then it to come up with the message I have put there "Good lad, BOOOO" however At the minute it lets the user type in say "oldham" then when we hit enter it just closes the application down with out coming up with the corresponding message.

Dim uservalue As String = Console.ReadLine()

Console.WriteLine("What football team do you support? Oldham, Manchester City, or Manchester United?")
Console.ReadLine()

If uservalue = "oldham" Then
Console.WriteLine("Good lad latics!")
Console.ReadLine()
ElseIf uservalue = "Manchester City" Then
Console.WriteLine("BOOOOOOOOOOOOOOOOO!!!!")
Console.ReadLine()
ElseIf uservalue = "Manchester United" Then
Console.WriteLine("BOOOOOOOOOOOOOOOOO!!!!")
Console.ReadLine()
End If

Thanks
Aaron

Member Avatar
aaronoafc
Newbie Poster
2 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Anyone???

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
0
 

I think that you need to change

Console.ReadLine()

to

uservalue = Console.ReadLine()

,

Member Avatar
Begginnerdev
Veteran Poster
1,141 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

The above suggestion is correct, The program might also be terminating to fast for you to see.


Try wrapping the program with a while.

Like this:

Sub Main()
        Dim uservalue As String
        Dim ex As String = ""
        While ex <> "exit"
            Console.WriteLine("What football team do you support? Oldham, Manchester City, or Manchester United?")
            uservalue = Console.ReadLine()
            If uservalue = "oldham" Then
                Console.WriteLine("Good lad latics!")
            ElseIf uservalue = "Manchester City" Then
                Console.WriteLine("BOOOOOOOOOOOOOOOOO!!!!")
            ElseIf uservalue = "Manchester United" Then
                Console.WriteLine("BOOOOOOOOOOOOOOOOO!!!!")
            Else
                Console.WriteLine("I DONT KNOW WHO YOU ARE!")
            End If
            Console.WriteLine("Type exit to exit the application")
            ex = Console.ReadLine()
        End While
    End Sub

This allows you to loop through the program until you want to exit.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: