-
Apr 8th, 2012, 04:07 PM
#1
Thread Starter
Junior Member
How Do I Close a Console Application?
I have a console application that asks the user to press number 5 to close the application. but i don't know what code to put so when the users press 5 the console application just closes???? any idea
-
Apr 8th, 2012, 04:35 PM
#2
Addicted Member
Re: How Do I Close a Console Application?
Put this code in a timer
vb Code:
If GetAsyncKeyState(Keys.D5) Then Me.Close() End If
and this outside a sub:
vb Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer
-
Apr 8th, 2012, 04:45 PM
#3
Thread Starter
Junior Member
Re: How Do I Close a Console Application?
in psudocode it says
while menuSelection != 5
so when the user press 5 it ends the program how do i write this in VB?
-
Apr 8th, 2012, 04:51 PM
#4
Addicted Member
Re: How Do I Close a Console Application?
my post was written in vb ? I don't know what you mean, I'm sorry
-
Apr 8th, 2012, 05:34 PM
#5
Thread Starter
Junior Member
Re: How Do I Close a Console Application?
This is the program am trying to run its a console application, I present the user with a menu and I want them when they click 5 it closes the program, what code should I use to allow the user to close the program by pressing 5???
Code:
Module Module1
Sub Main()
Dim menuSelection As Integer
DisplayMenu(menuSelection)
Select Case menuSelection
Case 1
Mercury()
Case 2
Venus()
Case 3
Earth()
Case 4
Mars()
End Select
End Sub
Private Sub Mercury()
Console.WriteLine(" ------------------------------- ")
Console.WriteLine("Mercury:")
Console.WriteLine("Average Distance from the Sun: 57.9 million kilometers")
Console.WriteLine("Mass: 3.31 x 10^23 kg")
Console.WriteLine("Surface Temperture: -173 to 430 degrees Celsius")
End Sub
Private Sub Venus()
Console.WriteLine(" ------------------------------- ")
Console.WriteLine("Venus:")
Console.WriteLine("Average Distance from the Sun: 108.2 million kilometers")
Console.WriteLine("Mass: 4.87 x 10^24 kg")
Console.WriteLine("Surface Temperture: 472 degreees Celsius")
End Sub
Private Sub Earth()
Console.WriteLine("Earth:")
Console.WriteLine("Average Distance from the Sun: 149.6 million kilometers")
Console.WriteLine("Mass: 5.967 x 10^24 kg")
Console.WriteLine("Surface Temperture: -50 to 50 degrees Celsius")
End Sub
Private Sub Mars()
Console.WriteLine("Mars:")
Console.WriteLine("Average Distance from the Sun: 227.9 million kilometers")
Console.WriteLine("Mass: 0.6424 x 10^24 kg")
Console.WriteLine("Surface Temperture: -140 to 20 degrees Celsius")
End Sub
Private Sub DisplayMenu(ByRef menuSelection As Integer)
Console.WriteLine(" Select a Planet")
Console.WriteLine("1. Mercury")
Console.WriteLine("2. Venus")
Console.WriteLine("3. Earth")
Console.WriteLine("4. Mars")
Console.WriteLine("5. End The Program")
Console.WriteLine()
Console.WriteLine("Enter your selection: ")
menuSelection = CInt(Console.ReadLine())
Do While menuSelection < 1 Or menuSelection > 5
Console.WriteLine("Invalid Selection.")
Console.Write("Please Enter 1 2, 3, or 4: ")
menuSelection = CInt(Console.ReadLine())
Loop
End Sub
End Module
-
Apr 9th, 2012, 09:51 AM
#6
Re: How Do I Close a Console Application?
Originally Posted by QuestionPlease
I have a console application that asks the user to press number 5 to close the application. but i don't know what code to put so when the users press 5 the console application just closes???? any idea
Just let the program fall to the End Sub line of Sub Main().
Or if you're feeling particularly brutal towards your own program you can use Application.Exit() which will do a hard-break of the app's thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|