VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3090 ScaleWidth = 4680 StartUpPosition = 3 'Windows Default End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Type Vector x As Single y As Single z As Single norma As Single End Type Const NumVectores = 3 Const PosicionVectorSuma = 4 Private Sub Form_Load() ReDim arrVect(1 To NumVectores) As Vector Dim i As Integer, mensaje As String Randomize mensaje = "Vectores generados aleatoriamente" & vbCrLf & vbCrLf For i = 1 To NumVectores 'La funcion Rnd retorna un numero aleatorio mayor o igual a cero y menor que uno ' Por lo tanto Round(Rnd * 10,1) retorna un numero real mayor o igual a 0 ' y menor que 10 With arrVect(i) .x = Round(Rnd * 10, 2) .y = Round(Rnd * 10, 2) .z = Round(Rnd * 10, 2) .norma = Sqr(.x * .x + .y * .y + .z * .z) mensaje = mensaje & "Vector " & Str(i) & " : " & _ Str(.x) & ", " & Str(.y) & ", " & Str(.z) & vbCrLf & _ "Norma : " & Str(Round(.norma, 2)) & vbCrLf End With Next i 'redimensiona el arreglo conservando su contenido ReDim Preserve arrVect(1 To PosicionVectorSuma) For i = 1 To NumVectores With arrVect(PosicionVectorSuma) .x = .x + arrVect(i).x .y = .y + arrVect(i).y .z = .z + arrVect(i).z End With Next i With arrVect(PosicionVectorSuma) .norma = Sqr(.x * .x + .y * .y + .z * .z) mensaje = mensaje & "Vector " & Str(i) & " : " & _ Str(.x) & ", " & Str(.y) & ", " & Str(.z) & vbCrLf & _ "Norma : " & Str(Round(.norma, 2)) End With MsgBox mensaje End Sub