Jump to content

need help with visual basic

I need some help when it comes to using Ms visual basic program language and my task is to print 3 names and get them to be printed out in alphabetical order. here is my code soo far please if some one can help me that would be awesome !! 

 

Module Module1

Sub Main()

Dim name1, name2, name3 As String

Console.Write("enter name 1: ")

name1 = Console.ReadLine

Console.Write("enter name 2: ")

name2 = Console.ReadLine

Console.Write("enter name3: ")

name3 = Console.ReadLine

If name1 < name2 Then

If name1 < name3 Then

Console.Write(name1 & " ")

Else

If name2 < name1 Then

If name2 < name3 Then

Console.Write(name2 & " ")

Else

If name3 < name1 Then

If name3 < name2 Then

Console.Write(name3 & " ")

End If

End If

End If

End If

End If

End If

If name1 < name2 Then

If name1 > name3 Then

Console.WriteLine(name1 & " ")

Else

If name2 < name1 Then

If name2 > name3 Then

Console.Write(name2 & " ")

Else

If name3 < name1 Then

If name3 > name2 Then

Console.Write(name3 & " ")

End If

End If

End If

End If

End If

End If

If name1 > name2 Then

If name1 > name3 Then

Console.Write(name3)

Else

If name2 > name1 Then

If name2 > name3 Then

Console.Write(name2)

Else

If name3 > name1 Then

If name3 > name2 Then

Console.Write(name3)

End If

End If

End If

End If

End If

End If

 

 

 

 

 

 

 

Console.Read()

End Sub

End Module

Link to comment
Share on other sites

Link to post
Share on other sites

Please edit your post to use code tags and use proper spacing

 

For code tags use the blue < > symbol above where you write a post/edit, or manually add the tags around your code in the text like so

[code]// Add code between the tags like soPublic Class Example    // ...End Class[/code]

Also learn about logical operators. Using AndAlso will allow you to reduce nesting and have code that's easier to read. Also, adding comments always helps so get in the habit of using them now.

 

Here's an example that shows everything I just talked about.

// If name1 is the smallest, then write it firstIf name1 < name2 AndAlso name1 < name3 Then    Console.Write(name1 & " ")    // Check if names 2 or 3 comes next and write them in the correct order    If name2 < name3 Then        Console.WriteLine(name2 & " " & name3)    Else        Console.WriteLine(name3 & " " & name2)    End IfEnd If

Note: Remember VB.NET uses ' for comments not // so you'll need to change them if you copy/paste. I use them in the example because the apostrophe messes up the forums syntax highlighting.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×