4.1.10 Bubles: FOR, FOR EACH, WHILE, WEND, DO LOOP
4.1.10 Bubles: FOR, FOR EACH, WHILE, WEND, DO LOOP
Investiga y representa un ejemplo de un programa donde se ocupa cada sentencia.
FOR ... NEXT
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Tabla" T = Val(InputBox("¿Qué tabla quiere conocer?" & vbCrLf & _ "(Introduzca un número de 1 a 10)", "¿Número?")) LabelTabla.Font = New Font("Arial", 10, FontStyle.Bold) LabelTabla.TextAlign = ContentAlignment.MiddleCenter LabelTabla.Text = "TABLA DEL " & T & vbCrLf & vbCrLf For i = 1 To 10 LabelTabla.Text = LabelTabla.Text & T & " * " & i & " = " & T * i & vbCrLf Next i End Sub End Class |
FOR EACH...NEXT
Sub Reempl()
Dim celdaactual As Object Dim posicion As Integer For Each celdaactual In Selection posicion = InStr(celdaactual, "-") 'si el valor de posicion es mayor a cero significará que 'la celda estudiada tiene un guión como parte de sus caracteres. If posicion > 0 Then Cells(celdaactual.Row, celdaactual.Column + 1).Value_ = Cells(celdaactual.Row, celdaactual.Column).Value Cells(celdaactual.Row, celdaactual.Column).Value = "" Else Cells(celdaactual.Row, celdaactual.Column + 1).Value = "" Cells(celdaactual.Row, celdaactual.Column).Value_ = Cells(celdaactual.Row, celdaactual.Column).Value End If Next End Sub |
WHILE – WEND
Private Sub ej_1_Click()
a = 1 While a < 5 Print a a = a + 1 Wend End Sub
Private Sub ej_2_Click()
a = 4 While a > 0 Print a a = a - 1 Wend End Sub |
DO...LOOP
Dim entrada
entrada = ""
DO WHILE (entrada <> "migue")
entrada = inputbox ("Dime el nombre del autor","seguridad","migue",2,3)
if (entrada = "out") then
msgbox "salgo por la puerta de atras"
exit do
end if
LOOP
|



Comentarios
Publicar un comentario