Visual Basic 2008 9.0 .NET Examples and Ebook

Introduction to Visual Basic

Vorig Onderwerp

New in Visual Basic 2008 - 9.0

|

Arrays

Volgend Onderwerp

Reading Input from the User

Vorig Onderwerp

Some Operators

|

Introduction to Selections

Volgend Onderwerp
Accepting or Reading Input

Accepting or Reading Input

An Example

An Example

Console ReadLine

Console ReadLine

Exercises

Exercises



Accepting or Reading Input


Module Example accepts some input ( name and age ) from the user.


Klik hier om terug naar boven te gaan.  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.

Klik hier om terug naar boven te gaan.  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.


Klik hier om terug naar boven te gaan.  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.

Solution :


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

Task :


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.

Solution :


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.

Updated On : 2008-01-24

Download Broncode

Published On : 2008-06-24

Reading Input from the User

Vorig Onderwerp

Some Operators

|

Introduction to Selections

Volgend Onderwerp

Introduction to Visual Basic

Vorig Onderwerp

New in Visual Basic 2008 - 9.0

|

Arrays

Volgend Onderwerp
Nederlands  Nederlands

Add to favorites (IE).