Manual de Visual Basic Intermedio

 

  Lección: 2

 

Capítulo: Ejercicio 2: Ordenar los Números

 

 

Crea un formulario con nueve etiquetas, dos de ellas serán las instrucciones y a las que contendrán los números (seis) cámbiales su Propiedad Alignment

a 2-Center, BackColor blanco, BorderStyle a 1-Fixed Single y tres botones, ahora

 

Introduce las siguientes declaraciones

Haz doble clic en el formulario En la caja de combo de la esquina superior izquierda selecciona (General) Y escribe: Dim n1, n2, n3 As Integer (presiona

Enter al terminar)

 

Ahora crea un procedimiento:

Haz doble clic en el formulario. Haz clic en Herramientas (Tools)/Agregar Procedimiento (Add Procedure). En Agregar Procedimiento escribe el nombre del

Procedimiento (en este caso azar) y haz clic en Aceptar. Ahora escribe el siguiente código:

Public Sub azar()

n1 = Int(Rnd * 10) + 1

n2 = Int(Rnd * 10) + 1

n3 = Int(Rnd * 10) + 1

If n1 <> n2 And n2 <> n3 And n1 <> n3 Then

Label1.Caption = n1

Label2.Caption = n2

Label3.Caption = n3

Else

Exit Sub

End If

End Sub

 

La etiqueta 4

 

Private Sub Label4_DragDrop(Source As Control, X As Single, Y As Single)

 

Label4.Caption = Source

 

Source.Visible = False

 

End Sub

 

La etiqueta 5

 

Private Sub Label5_DragDrop(Source As Control, X As Single, Y As Single)

 

Label5.Caption = Source

 

Source.Visible = False

 

End Sub

 

La etiqueta 6

 

Private Sub Label6_DragDrop(Source As Control, X As Single, Y As Single)

 

Label6.Caption = Source

 

Source.Visible = False

 

End Sub

 

El botón Iniciar

 

Private Sub Command1_Click()

 

Label4.Caption = ""

 

Label5.Caption = ""

 

Label6.Caption = ""

 

Label7.Caption = ""

 

Label1.Visible = True

 

Label2.Visible = True

 

Label3.Visible = True

 

Call azar

 

End Sub

 

El botón Resultado

 

Private Sub Command2_Click()

 

If Val(Label4.Caption) < Val(Label5.Caption) And Val(Label5.Caption) < Val(Label6.Caption) Then

 

Label7.Caption = "Bien"

 

Else

 

Label7.Caption = "Mal"

 

End If

 

End Sub

 

El botón Salir

 

Private Sub Command3_Click()

 

Unload Me

 

End

 

End Sub

 

El formulario

 

Private Sub Form_Load()

 

Randomize

 

Call azar

 

End Sub

 

 

     Volver al índice!