You are on page 1of 12

Public Class Form1

Dim NOTAS(6) As Integer


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SUMA, PROMEDIO As Integer
SUMA = 0
PROMEDIO = 0
'ASIGNAMOS CADA UNO DE LOS VALORES DIGITADOS A UNA POSICION DEL VECTOR NOTAS
NOTAS(1) = TextBox1.Text
NOTAS(2) = TextBox2.Text
NOTAS(3) = TextBox3.Text
NOTAS(4) = TextBox4.Text
NOTAS(5) = TextBox5.Text
NOTAS(6) = TextBox6.Text
'RECORREMOS EL VECTOR Y VAMOS SUMANDO LOS VALORES QUE CONTIENEN CADA
POSICION DE MEMORIA
For I = 0 To 6
SUMA = SUMA + NOTAS(I)
Next
'CALCULAMOS EL PROMEDIO
PROMEDIO = SUMA / 6
'MOSTRAMOS LOS RESULTADOS EN LOS RESPECTIVOS CUADROS DE TEXTO
TextBox7.Text = SUMA
TextBox8.Text = PROMEDIO
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
For I = 1 To 6
NOTAS(I) = 0
Next I
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
End
End Sub
End Class

Public Class Form1


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Cargo() As String = {"Administrador", "Secretaria", "Contador", "Director",
"Almacenero"}
ComboBox1.Items.AddRange(Cargo)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
With ListView1.Items.Add(TextBox1.Text).SubItems.Add(ComboBox1.SelectedItem)
End With
End Sub
End Class

Public Class Form1


Dim Deportes() As String = {"basquet", "futbol", "voley"}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnReDim.Click
For Each Item As String In Deportes
ListBox1.Items.Add("[ " & Item & " ]")
Next
ReDim Preserve Deportes(5)
Deportes(3) = "natacion"
Deportes(4) = "kunfu"
For Each Item As String In Deportes
ListBox2.Items.Add("[ " & Item & " ]")
Next
End Sub
End Class

Public Class Form1


Dim a(,) As Integer 'declaramos arreglo dinamico
Dim c As Integer
Dim b As Integer
Dim suma As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.Text = ""
b = Val(TextBox1.Text) 'asignamos valos tb1 a la variable "b" para redimensionar fila
c = Val(TextBox2.Text) 'asignamos valos tb2 a la variable "c" para redimensionar columna
ReDim a(b, c) 'redimensionamos el arreglo
'llenamos y mostramos el arreglo en el richtextbox
For i = 0 To b 'contador
For j = 0 To c
a(i, j) = Val(InputBox("ingresa elemento: " & i & " " & j)) 'Rellenar arreglo
RichTextBox1.Text = RichTextBox1.Text & a(i, j) & "
" 'mostrar arreglo
Next
RichTextBox1.Text = RichTextBox1.Text & vbCr ' para saltar linea
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
suma = 0
For i = 0 To b
For j = 0 To c
If i = j Then
suma = suma + a(i, j)
End If
Next
Next
TextBox3.Text = suma
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim suma2 As Integer
suma2 = 0
For i = 0 To b
For j = 0 To c
If (i + j) = c Then
suma2 = suma2 + a(i, j)
End If
Next
Next
Label1.Text = suma2
End Sub
End Class

Public Class ejercicios_1_and_2


Dim Numero(15, 4) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
For I = 0 To 14
For j = 0 To 3
Numero(I, j) = InputBox("INGRESAR NUMEROS", I & "," & j)
Next
ListBox1.Items.Add(Numero(I, 0))
ListBox2.Items.Add(Numero(I, 1))
ListBox3.Items.Add(Numero(I, 2))
ListBox4.Items.Add(Numero(I, 3))
Next
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For j = 0 To 3
ListBox5.Items.Add(Numero(0, j))
ListBox6.Items.Add(Numero(1, j))
ListBox7.Items.Add(Numero(2, j))
ListBox8.Items.Add(Numero(3, j))
ListBox9.Items.Add(Numero(4, j))
ListBox10.Items.Add(Numero(5, j))
ListBox11.Items.Add(Numero(6, j))
ListBox12.Items.Add(Numero(7, j))
ListBox13.Items.Add(Numero(8, j))
ListBox14.Items.Add(Numero(9, j))
ListBox15.Items.Add(Numero(10, j))
ListBox16.Items.Add(Numero(11, j))
ListBox17.Items.Add(Numero(12, j))
ListBox18.Items.Add(Numero(13, j))
ListBox19.Items.Add(Numero(14, j))
Next
End Sub
Private Sub ejercicios_1_and_2_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
End Class

1) Ingresar 4 conjuntos de 15 nmeros enteros cada uno en un arreglo bidimensional. Guardar cada conjunto en
una fila y luego mostrar los datos por filas.
2) Realizar el ejercicio anterior pero hacerlo por columnas.

Public Class jercicios_4


Dim Numero(3, 1) As Integer
Private Sub jercicios_4_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Sf1, Sf2, Sf3, Sf4, Sc1, Sc2 As Integer
For I = 0 To 3
For j = 0 To 1
Numero(I, j) = InputBox("Ingresar numeros")
Next
ListBox1.Items.Add(Numero(I, 0))
ListBox2.Items.Add(Numero(I, 1))
Next
For I = 0 To 1
Sf1 += Numero(0, I)
Next
Label1.Text = Sf1
For I = 0 To 1
Sf2 += Numero(1, I)
Next
Label2.Text = Sf2
For I = 0 To 1
Sf3 += Numero(2, I)
Next
Label3.Text = Sf3
For I = 0 To 1
Sf4 += Numero(3, I)
Next
Label4.Text = Sf4
For I = 0 To 3
Sc1 += Numero(I, 0)
Next
Label5.Text = Sc1
For I = 0 To 3
Sc2 += Numero(I, 1)
Next
Label6.Text = Sc2
ReDim Numero(3, 2)
End Sub
End Class

Ingresar 2 conjuntos de 4 nmeros reales cada uno en un arreglo bidimensional. Calcular la


suma de sus filas, por otro lado calcular la suma de sus columnas.

Public Class suma


Dim x As Integer
Dim NUM(4) As Integer

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If x < 4 Then ' limite de numero del arreglo
ListBox1.Items.Add(TextBox1.Text) 'lista de numeros
NUM(x) = Val(TextBox1.Text)
x=x+1
TextBox1.Clear() 'limpieza de textbox1
Else
Button1.Enabled = False
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim s As Integer
For i = 0 To 4
s = s + NUM(i)
Next
Label1.Text = s
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles
TextBox1.TextChanged
End Sub
End Class

Public Class Form1

Dim A(10), B(5) As Decimal : Dim C(10) As Decimal


Dim x, y As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
A(x) = TextBox1.Text
ListBox1.Items.Add(A(x))
x=x+1
If x = 10 Then Button1.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
B(y) = TextBox1.Text
ListBox2.Items.Add(B(y))
y=y+1
If y = 10 Then Button2.Enabled = False
End Sub
'SUMA**************************************************
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
For i = 0 To 9
If i <= (B.Length) - 1 Then
C(i) = A(i) + B(i)
ListBox3.Items.Add(C(i))
Else
C(i) = A(i)
ListBox3.Items.Add(C(i))
End If
Next
End Sub
'RESTA************************************************
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
For i = 0 To 9
If i <= (B.Length) - 1 Then
C(i) = A(i) - B(i)
ListBox4.Items.Add(C(i))
Else
C(i) = A(i)
ListBox4.Items.Add(C(i))
End If
Next
End Sub
'Multiplicacion********************************************
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click
For i = 0 To 9
If i <= (B.Length) - 1 Then
C(i) = A(i) * B(i)
ListBox5.Items.Add(C(i))
Else
C(i) = A(i)
ListBox5.Items.Add(C(i))

End If
Next
End Sub
'Division ****************************************************
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button6.Click
For i = 0 To 9
If i <= (B.Length) - 1 Then
C(i) = A(i) / B(i)
ListBox6.Items.Add(C(i))
Else
C(i) = A(i)
ListBox6.Items.Add(C(i))
End If
Next
End Sub
End Class

3) Ingresar elementos reales en un arreglo bidimensional de 8 filas por 6 columnas.


Luego ingresar un dato entero que corresponde al nmero de fila (validar que sea
consistente) cuyos elementos se desean sumar. Exhibir dicha suma.

Public Class Form2


Dim a(7, 5)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
For i = 0 To 7
For b = 0 To 5
a(i, b) = InputBox("ingresa elemento: " & (i + 1) & " " & (b + 1))
Next
Next
For i = 0 To 7
ListBox1.Items.Add(a(i, 0))
ListBox2.Items.Add(a(i, 1))
ListBox3.Items.Add(a(i, 2))
ListBox4.Items.Add(a(i, 3))
ListBox5.Items.Add(a(i, 4))
ListBox6.Items.Add(a(i, 5))
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Dim C = Val(TextBox1.Text)
Dim suma = 0
For i = 0 To 5
suma = suma + a((C - 1), i)
Next
Label3.Text = suma
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class

) Ingresar 4 conjuntos de 5 elementos enteros cada uno en un arreglo bidimensional. Calcular


y exhibir la suma de su diagonal principal y de su diagonal secundaria.
Public Class Form4
Dim a(4, 4) As Integer
Dim s1, s2 As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
For i = 0 To 4
For b = 0 To 4
a(i, b) = InputBox("ingresa elemento: " & (i + 1) & "," & (b + 1))
Next
Next
For i = 0 To 4
ListBox1.Items.Add(a(i, 0))
ListBox2.Items.Add(a(i, 1))
ListBox3.Items.Add(a(i, 2))
ListBox4.Items.Add(a(i, 3))
ListBox5.Items.Add(a(i, 4))
Next
For i = 0 To 4
For b = 0 To 4
If i = b Then
s1 = s1 + a(i, b)
End If
Next
Next
For i = 0 To 4
For b = 0 To 4
If i + b = 4 Then
s2 = s2 + a(i, b)
End If
Next
Next
Label1.Text = s1
Label2.Text = s2
End Sub
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class

8) Ingresar nmeros enteros en un arreglo bidimensional A de 5 filas por 5 columnas; luego


en otro arreglo B de igual dimensin, ingresar nmeros enteros. Obtener un arreglo C,
siendo C = A + B (cada elemento de C se obtiene como la suma de los elementos
homlogos de Ay B. mostrar A, B y C una al lado de la otra. Este es el concepto de suma de
matrices.
Public Class Form7
Dim a(4, 4), c(4, 4), d(4, 4) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
For i = 0 To 4
For b = 0 To 4
a(i, b) = InputBox("ingresa elemento: " & (b + 1) & " del conjunto: " & (i + 1))
Next
Next
For i = 0 To 4
ListBox1.Items.Add(a(i, 0))
ListBox2.Items.Add(a(i, 1))
ListBox3.Items.Add(a(i, 2))
ListBox4.Items.Add(a(i, 3))
ListBox5.Items.Add(a(i, 4))
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
For i = 0 To 4
For b = 0 To 4
c(i, b) = InputBox("ingresa elemento: " & (b + 1) & " del conjunto: " & (i + 1))
Next
Next
For i = 0 To 4
ListBox6.Items.Add(c(i, 0))
ListBox7.Items.Add(c(i, 1))
ListBox8.Items.Add(c(i, 2))
ListBox9.Items.Add(c(i, 3))
ListBox10.Items.Add(c(i, 4))
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
For i = 0 To 4
For b = 0 To 4
d(i, b) = a(i, b) + c(i, b)
Next
Next
For i = 0 To 4
ListBox11.Items.Add(d(i, 0))
ListBox12.Items.Add(d(i, 1))
ListBox13.Items.Add(d(i, 2))
ListBox14.Items.Add(d(i, 3))
ListBox15.Items.Add(d(i, 4))
Next
End Sub
End Class

You might also like