|
|
 |
|
|
|
|
Visual Basic 2008 9.0 .NET Examples and Ebook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Accepting or Reading Input
| Module Example accepts some input ( name and age ) from the user. |
Up
An Example
| Module Example
Sub Main()
Dim name As String
Dim age As Integer
Console.WriteLine("Name ?")
name = Console.ReadLine()
Console.WriteLine("Age ?")
age = Console.ReadLine()
Console.WriteLine("Your name is " & name & ".")
Console.WriteLine("Your age is " & age & ".")
Console.ReadLine()
End Sub
End Module Download Broncode |
| Output : Name ?
<i>John</i>
Age ?
<i>50</i>
Your name is John.
Your age is 50. |
Up
Console ReadLine
| Console.ReadLine() will read a line from the console. A line consists of zero or more characters ended with an endline character. When the input is coming from the user, the endline is formed by pressing the "Enter" key.
Console.ReadLine() also forms an expression that will evaluate to the value ( the text ) before the endline ( entered before the "Enter" key is pressed ). This value is assigned to the variables. |
Up
Exercises
| Task :
Make a program based on the following output ( input is in italic ). |
| Output : Number ?
<i>5</i>
Square of 5 is 25. |
| Module Exercise1Solution
Sub Main()
Dim number, square As Integer
Console.WriteLine("Number ?")
number = Console.ReadLine()
square = number ^ 2
Console.WriteLine("Square of " & number & " is " & square & ".")
Console.ReadLine()
End Sub
End Module Download Broncode |
| Make a program based on the following output ( input is in italic ). |
| Output : Name ?
<i>John</i>
Length ?
<i>185</i>
John you're 1 meter and 85 centimetres. |
| Module Exercise2Solution
Sub Main()
Dim name As String
Dim length As Integer
Console.WriteLine("Name ?")
name = Console.ReadLine()
Console.WriteLine("Length ?")
length = Console.ReadLine()
Console.WriteLine(name & " you're " & _
(length \ 100) & " meter and " & _
(length Mod 100) & " centimetres.")
Console.ReadLine()
End Sub
End Module Download Broncode |
This version ( published on 2008-06-24 ) is printed from http://www.studyvb.com, visit the website for more recent information.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|