How to used Console Application in Visual Basic.Net? Actually, console application are most common command from old programming style because they used command line to run program or the basic command to tell computer what they are going to do and manipulates those command to be processed.
Furthermore, VB.Net console application allows us to read characters from the console, write characters to the console and executed in the DOS version. In the development of modern technology, instead the used of console application they used GUI or Graphical User Interface, because you can look and feel what you are doing, includes: scroll bars, pull-down menus, icon and images, wizard, mouse, etc.
Fortunately, Console Application reign before the GUI and it’s more power in executing commands in computers terminal. Anyway, what’s the point is, we are going to write a simple code in Visual Basic.Net using console application or Command Line Interface or CLI.
Furthermore, VB.Net console application allows us to read characters from the console, write characters to the console and executed in the DOS version. In the development of modern technology, instead the used of console application they used GUI or Graphical User Interface, because you can look and feel what you are doing, includes: scroll bars, pull-down menus, icon and images, wizard, mouse, etc.
Fortunately, Console Application reign before the GUI and it’s more power in executing commands in computers terminal. Anyway, what’s the point is, we are going to write a simple code in Visual Basic.Net using console application or Command Line Interface or CLI.
Module Module1
Sub Main()
'Write the code here!
End Sub
End Module
The newly created module, when you notice there’s Sub procedure call Sub Main() declaring inside the startup object of your console application and you can start writing program code.
Module Module1
Sub Main()
Console.WriteLine("Hello Philippines")
End Sub
End Module
The problem when you run the program is, the output is autmatically colapsed. What we did is we are going to put Console.ReadLine().
Here are the complete code:
Module Module1
Sub Main()
Console.WriteLine("Hello Philippines")
Console.ReadLine()
End Sub
End Module
However, I’ll give you some points the difference between WriteLine and Write, and ReadLine and Read. In Console.WriteLine() method appends a new blank lines while Console.Write() method appends anything after what you write.
Console.Read() method returns a single character as int. Actually, when you need to read a single character from the input you can use Console.Read().Console.ReadLine() methods returns a string containing a line of text, use Console.ReadLine() when you need to read a string from the user.
Here are the sample codes that add two numbers:
Module Module1
Sub Main()
Dim x As Integer
Dim y As Integer
Dim ans As Integer
Console.Write("Enter the 1st number ")
x = Console.ReadLine()
Console.Write("Enter the 2nd number ")
y = Console.ReadLine()
Console.WriteLine() 'next line with a new blank lines
ans = x + y
Console.WriteLine("The sum of two number is to " & ans)
Console.ReadLine()
End Sub
End Module
Here is the sample code for simple guessing game in Visual Basic.Net using Console Application.
Module Module1
Sub Main()
Dim b As Char
For i As Integer = 0 To 100
h: Console.Write("Enter the number: ")
i = Val(Console.ReadLine())
Console.WriteLine(i)
If i = 50 Then
Console.Write("You guessed the number?" & vbCrLf & "Press Enter")
Console.ReadLine()
c: Console.WriteLine("Press e to exit... to continue press c")
b = Console.ReadLine
Select Case b
Case "e"
Console.Write("The system will automatically closed")
Exit Sub
Case "c"
GoTo h
Case Else
Console.Write("Please press the approriate key" & vbCrLf & "Press Enter")
GoTo c
End Select
Else
Console.Write("Please try again" & vbCrLf & "Press Enter")
Console.ReadLine()
End If
Next
End Sub
End Module
0 comments:
Post a Comment