Académique Documents
Professionnel Documents
Culture Documents
NET
Laboratorio N 01
VB .NET: INTRODUCCIN Y FUNDAMENTOS
LABORATORIO
Objetivos:
Introduccin:
En esta unidad se detalla la programacin con el lenguaje Visual Basic .NET.
Procedimiento y Resultados:
1.
2.
Pg. 1
2.1.
Pg. 2
2.2.
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
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.
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
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.
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
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
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