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
Printable View
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
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
in psudocode it says
while menuSelection != 5
so when the user press 5 it ends the program how do i write this in VB?
my post was written in vb ? I don't know what you mean, I'm sorry
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