VB.Net/Development/Console

Материал из VB Эксперт
Перейти к: навигация, поиск

Console Output

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
      Console.WriteLine("Welcome to Visual Basic!")
    End Sub
    
End Class


Console Read and Compare Integer

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
      Dim number1, number2 As Integer
      " read first number from user
      Console.Write("Please enter first integer: ")
      number1 = Console.ReadLine()
      " read second number from user
      Console.Write("Please enter second integer: ")
      number2 = Console.ReadLine()
      If number1 = number2 Then
         Console.WriteLine("{0} = {1}", number1, number2)
      End If
      If number1 <> number2 Then
         Console.WriteLine("{0} <> {1}", number1, number2)
      End If
      If number1 < number2 Then
         Console.WriteLine("{0} < {1}", number1, number2)
      End If
      If number1 > number2 Then
         Console.WriteLine("{0} > {1}", number1, number2)
      End If
      If number1 <= number2 Then
         Console.WriteLine("{0} <= {1}", number1, number2)
      End If
      If number1 >= number2 Then
         Console.WriteLine("{0} >= {1}", number1, number2)
      End If
    End Sub
    
End Class


Do calculation in Console.WriteLine

Imports System
public class MainClass
    Shared Sub Main()
         Dim twelve As Integer = 12
         Dim five As Integer = 5
         Console.WriteLine("{0} + {1} = {2}", _
             twelve, five, twelve + five)
         Console.WriteLine("{0} - {1} = {2}", _
             twelve, five, twelve - five)
         Console.WriteLine("{0} * {1} = {2}", _
             twelve, five, twelve * five)
    End Sub
End Class


Output Format for Integer

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Dim myInt As Integer = 7
       Console.WriteLine("Initialized myInt: {0}", myInt)
       myInt = 5
       Console.WriteLine("After assignment myInt: {0}", myInt)
    End Sub
End Class