Vous êtes sur la page 1sur 8

VISUAL BASIC .

NET

Laboratorio N 01
VB .NET: INTRODUCCIN Y FUNDAMENTOS

Visual Basic .NET

LABORATORIO

Objetivos:

Revisar el Framework .NET.


Crear proyectos con Visual Studio .NET.
Trabajar en un proyecto de consola.
Escribir la sintaxis del lenguaje.
Realizar ejercicios con algoritmos.

Equipos, Materiales, Programas y Recursos:

Sistema Operativo Windows.


.NET Framework 3.5
Visual Studio 2008

Introduccin:
En esta unidad se detalla la programacin con el lenguaje Visual Basic .NET.
Procedimiento y Resultados:

1.

Crear nuevo proyecto en la opcin archivo.

2.

Sintaxis del lenguaje


Trabajaremos en una aplicacin en Consola.

Pg. 1

Visual Basic .NET

2.1.

Declaracin y uso de variables

Digitamos el siguiente cdigo en el mtodo main del modulo1

Pg. 2

Visual Basic .NET

2.2.

Para ejecutar presionamos el f5 o el icono que se muestra en la figura

El resultado se muestra a continuacin,

Comentario de cdigo

Sub Main()
Declare the Temperature variable
Dim Temperature As Integer
Temperature = 60 Assign a value of 60 to Temperature
Display the value in the Temperature variable
Console.WriteLine(Temperature)
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub

Pg. 3

Visual Basic .NET

2.3.

Conversiones de datos

Module Module1
Sub Main()
Dim dblValue As Double
Dim intValue As Integer
dblValue = 1.2345678
intValue = dblValue
Console.WriteLine(intValue)
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
End Module
Funciones de conversin

2.4.

CBoolConverts to Bool data type


CByteConverts to Byte data type
CCharConverts to Char data type
CDateConverts to Date data type
CDblConverts to Double data type
CDecConverts to Decimal data type
CIntConverts to Int data type
CLngConverts to Long data type
CObjConverts to Object type
CShortConverts to Short data type
CSngConverts to Single data type
CStrConverts to String type

Constantes

Module Module1
Sub Main()
Const Pi = 3.1415926535
Console.WriteLine(Pi)
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
End Module
2.5.

Enumerations

Module Module1
Enum Days
Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
Saturday = 6
Pg. 4

Visual Basic .NET

End Enum
Sub Main()
Console.WriteLine(Saturday is day & Days.Saturday & .)
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
END MODULE
2.6.

Declarando arreglos estticos

Dim Scores(20) As Integer


Scores(0) = 25
Scores(1) = 75
Scores(2) = 95
Console.WriteLine(Student 1 scored & Scores(1))
Console.WriteLine(Press Enter to continue...)
CONSOLE.READLINE()
2.7.

Declarando arreglos dinmicos

Module Module1
Sub Main()
Dim Scores() As Integer
ReDim Scores(2)
Scores(0) = 25
Scores(1) = 75
ReDim Preserve Scores(5)
Scores(2) = 95
Scores(3) = 35
Scores(4) = 65
Scores(5) = 85
Console.WriteLine(Scores(3) = & Scores(3))
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
End Module
2.8.

Sentencia IF

Module Module1
Sub Main()
Dim intInput As Integer
Console.WriteLine(Enter a temperature...)
intInput = Val(Console.ReadLine())
If intInput > 75 Then
Console.WriteLine(Too hot!)
ElseIf intInput < 55 Then
Console.WriteLine(Too cold!)
Else
Console.WriteLine(Just right!)
End If
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
Pg. 5

Visual Basic .NET

End Sub
END MODULE
2.9.

Sentencia SELECT

Module Module1
Sub Main()
Dim intInput As Integer
Console.WriteLine(Enter an integer...)
intInput = Val(Console.ReadLine())
Select Case intInput
Case 1
Console.WriteLine(Thank you for the 1.)
Case 2 To 5
Console.WriteLine(Your value was 2, 3, 4, or 5)
Case Is > 5
Console.WriteLine(That was greater than 5.)
Case Else
Console.WriteLine(Sorry, I cant deal with that.)
End Select
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
End Module
2.10. Bucle FOR
Module Module1
Sub Main()
Dim Scores(2) As Integer
Scores(0) = 45
Scores(1) = 55
Scores(2) = 65
For intLoopIndex As Integer = 0 To UBound(Scores)
Console.WriteLine(Score( & intLoopIndex & ) = _
& Scores(intLoopIndex))
Next intLoopIndex
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
End Module
2.11. Bucle FOR EACH
Module Module1
Sub Main()
Dim Scores(2) As Integer
Scores(0) = 45
Scores(1) = 55
Scores(2) = 65
For Each Score As Integer In Scores
Console.WriteLine(Score = & Score)
Next Score
Pg. 6

Visual Basic .NET

Console.WriteLine(Press Enter to continue...)


Console.ReadLine()
End Sub
End Module
2.12. Bucle WHILE

Module Module1
Sub Main()
Console.WriteLine(Please enter q to quit...)
Dim strInput As String = Console.ReadLine()
While (strInput <> q)
Console.WriteLine(You typed & strInput)
Console.WriteLine(Please enter q to quit...)
strInput = Console.ReadLine()
End While
Console.WriteLine(Quitting now.)
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
End Module
2.13. Using DO LOOP
Module Module1
Sub Main()
Dim strInput As String
Do
Console.WriteLine(Please enter q to quit...)
strInput = Console.ReadLine()
Console.WriteLine(You typed & strInput)
Loop While (strInput <> q)
Console.WriteLine(Quitting now.)
Console.WriteLine(Press Enter to continue...)
Console.ReadLine()
End Sub
End Module

Pg. 7

Vous aimerez peut-être aussi