Академический Документы
Профессиональный Документы
Культура Документы
NET
1.- Variables
Module Module1
Sub Main()
Console.ReadLine()
End Sub
End Module
2.- Operadores
Module Module1
Sub Main()
'Operadores
Dim suma As Integer
Dim resta As Integer
Dim producto As Integer
Dim division As Double
Dim div_entera As Integer
Dim div_residuo As Integer
Dim num2_cuadrado As Integer
'Resultado
Console.WriteLine("Igualdad: " & (num1 = num2))
Console.WriteLine("Diferente: " & (num1 <> num2))
Console.WriteLine("Suma: " & suma)
Console.WriteLine("Resta: " & resta)
Console.WriteLine("Producto: " & producto)
Console.WriteLine("División: " & division)
Console.WriteLine("División parte entera: " & div_entera)
Console.WriteLine("División parte residuo: " & div_residuo)
Console.WriteLine("Número " & num2 & " al cuadrado: " & num2_cuadrado)
Console.ReadLine()
End Sub
End Module
Sub Main()
'Variables
Dim edad As Integer
Dim mensaje As String
'Inicio
Console.Write("Ingrese edad: ") 'Ingreso por teclado
edad = Console.ReadLine() 'Lectura por teclado
'Hacer
If (edad >= 18) Then
mensaje = "Mayor de edad."
'Salida
Console.WriteLine(mensaje)
Console.ReadLine()
End Sub
End Module
Sub Main()
'Variables
Dim mesEntero As Integer
Dim mesCadena As String = ""
Dim bandera As Boolean = False
'Inicio
Console.Write("Ingrese mes en número: ")
mesEntero = Console.ReadLine()
'Hacer
Select Case (mesEntero)
Case 1
mesCadena = "Enero"
Case 2
mesCadena = "Febrero"
Case 3
mesCadena = "Marzo"
Case 4
mesCadena = "Abril"
Case 5
mesCadena = "Mayo"
Case 6
mesCadena = "Junio"
Case 7
mesCadena = "Julio"
Case 8
mesCadena = "Agosto"
Case 9
mesCadena = "Septiembre"
Case 10
mesCadena = "Octubre"
Case 11
mesCadena = "Noviembre"
Case 12
'Salida
If (bandera = True) Then
Console.WriteLine("Error... Mes incorrecto.")
Else
Console.WriteLine("Mes es: " & mesCadena)
End If
Console.ReadLine()
End Sub
End Module
Sub Main()
'Variables
Dim numero As Integer
Dim factorial As Long = 1
Dim bandera As Integer = 0
'Inicio
Console.Write("Ingrese un número: ")
numero = Console.ReadLine()
'Hacer
If (numero > 0) Then
While (numero > 0)
factorial = factorial * numero
numero = numero - 1
End While
ElseIf (numero < 0) Then
bandera = 1
End If
'Salida
If (bandera = 1) Then
Console.WriteLine("Error... Número es negativo.")
Else
Console.WriteLine("Factorial es: " & factorial)
End If
Console.ReadLine()
End Sub
End Module
Sub Main()
'Variables
Dim num1, numx As Integer
Dim mayor, menor As Integer
Dim acum As Integer = 0
Dim promedio As Double
'Inicio
Console.Write("Ingrese #1: ")
num1 = Console.ReadLine()
mayor = num1
menor = num1
'Hacer
For i = 2 To 5 Step 1
Console.Write("Ingrese #" & i & ": ")
numx = Console.ReadLine()
'Salida
Console.WriteLine("Mayor: " & mayor)
Console.WriteLine("Menor: " & menor)
Console.WriteLine("Promedio: " & promedio)
Console.ReadLine()
End Sub
End Module
Sub Main()
'Variables
Dim A(4) As Integer 'Vector A de tamaño 5
'Inicio
A(0) = 14
A(1) = 12
A(2) = 11
A(3) = 15
A(4) = 10
'Hacer
Dim tamA As Integer = A.Length() 'Longitud o tamaño del vector A
'Salida
For i = 0 To (tamA - 1) Step 1
Console.Write(A(i) & " ")
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main()
'Variables
Dim B() As String = {"David", "Vilma", "Rosa", "Paul"}
'Inicio
'Hacer
'Salida
For i = 0 To (B.Length() - 1) Step 1
Console.Write(B(i) & " ")
Next
Console.ReadLine()
End Sub
End Module
Sub Main()
'Variables
Dim A(1, 2) As Integer
Dim totalFilas As Integer
Dim totalColumnas As Integer
'Inicio
A(0, 0) = 7
A(0, 1) = 8
A(0, 2) = 9
A(1, 0) = 4
A(1, 1) = 5
A(1, 2) = 6
'Hacer
totalFilas = UBound(A, 1) + 1
totalColumnas = UBound(A, 2) + 1
'Salida
For f = 0 To (totalFilas - 1) Step 1
For c = 0 To (totalColumnas - 1) Step 1
Console.Write(A(f, c) & " ")
Next
Console.WriteLine() 'Salto de línea
Next
Console.ReadLine()
End Sub
End Module
9.- Otros
Sub Main()
'Conversión a Minúscula
Dim cadena1 As String = "Hola mundo"
Dim cadena_min As String = LCase(cadena1)
'Conversión a Mayúscula
Dim cadena2 As String = "Arriba Perú"
Dim cadena_may As String = UCase(cadena2)
Console.WriteLine("Longitud de " & nombre & " es: " & longitud_cadena)
Console.WriteLine("Primer caracter de " & nombre & " es: " & primer_caracter)
Console.WriteLine("Último caracter de " & nombre & " es: " & ultimo_caracter)
Console.WriteLine("Fracción de la cadena " & nombre & ": " & fraccion_cadena1)
Console.WriteLine("Ubicación del caracter v de la cadena " & nombre & ": " & fraccion_cadena2)
Console.WriteLine()
Console.ReadLine()
End Sub
End Module
…….