ejercicios de clase en vb
DESCRIPTION
Ejercitación en MSVB pra 4to AI.TRANSCRIPT
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
1-Nombre y apellidoEjercicio 1 Armar un formulario donde se deba ingresar el apellido.La respuesta deberá salir a través de una label donde diga “Bienvenido”…..Esta es tu primera actividad”
Colocar los siguientes controles1 Textbox2 label2 cmd
ProgramaciónPrivate Sub cmdahora_Click()lblmensaje.Caption = "Bienvenido " & txtnombre.Text & " Esta es tu primera actividad"End Sub-----------------------------------------------------Private Sub cmdfin_Click()EndEnd Sub
2-Colores
Option ExplicitPrivate Sub Form_Load() txtCaja = 0End Sub
Private Sub Option1_Click()txtCaja.BackColor = vbGreenEnd Sub
Private Sub Option2_Click()txtCaja.BackColor = vbBlueEnd Sub
Private Sub Option3_Click()txtCaja.BackColor = vbYellowEnd Sub
Private Sub rojo_Click()txtCaja.BackColor = vbRedEnd Sub
1
Colocar los siguientes controles4 Option Botton – 1 Text
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
3-Balanza
Private Sub cmdresultado_Click()Dim peso, altura As DoubleIf IsNumeric(txtpeso) Thenpeso = CDbl(txtpeso.Text)ElseMsgBox "Ingrese un valor numérico"End IfIf IsNumeric(txtalt) Thenaltura = CDbl(txtalt.Text)ElseMsgBox "Ingrese un valor numérico > a 0"End Iflblmensaje = peso / altura ^ 2If lblmensaje < 25 ThenMsgBox "Comé sin problemas"ElseIf lblmensaje >= 30 ThenMsgBox "Suspendeme los postres"ElseMsgBox "Hace dieta, gorrrrda"End IfEnd Sub
Control Propiedad Valor
textbox Name txtpeso
Text textbox Name txtalt
Text textbox Name txtpeso
Text Command Botton
Name: cmdresultado
Caption: resultado
Label Name: lblmensajeCaption:
2
Colocar los siguientes controles4 label – 2 text
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
4-Edad
Private Sub cmdedad_Click()Dim b As Date, edad As Integerb = CDate(txtfecha.Text)edad = CInt(Year(Now) - Year(txtfecha))lblresultado.Caption = txtnombre.Text & " " & "usted tiene" & " " & edad & "" & "años"lblresultado.BackColor = vbMagentaEnd Sub
----------------------------------------------------------------------------------------------------------
5-Ruleta
Private Sub cmdcalcular_Click()Dim x As Integer, y As IntegerRandomize Timerx = Rnd * 10y = Rnd * 10lblx.Caption = xlbly.Caption = ylblproducto = x - ylblsumar = x + yEnd Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------6-Calculadora
Option ExplicitPrivate Sub cmdDiv_Click()txtResult.Text = Val(txtOper1.Text) / Val(txtOper2.Text)lblOp.Caption = "/"End Sub
Control Propiedad Valor
1 textbox Name txtfecha
Text 1 textbox Name txtalt
Text 1 textbox Name txtpeso
Text 1 Command
BottonName: cmdedad
Caption: resultado
1 Label Name: lblresultado
Caption: 1 Label Name: Lbl1
Caption Ingrese su nombre1 Label Name: Lbl2
Caption: Ingrese su fecha de nacimiento 00/00/00
3
Colocar los siguientes controles3 label- 1 text – 1 Command Button
Colocar los siguientes controles3 text – 2 label – 4 command button
Colocar los siguientes controles 6 label 1 command button
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
Private Sub cmdProd_Click()txtResult.Text = Val(txtOper1.Text) * Val(txtOper2.Text)lblOp.Caption = "*"End Sub
Private Sub cmdResta_Click()txtResult.Text = Val(txtOper1.Text) - Val(txtOper2.Text)lblOp.Caption = "-"End Sub
Private Sub cmdSuma_Click()txtResult.Text = Val(txtOper1.Text) + Val(txtOper2.Text)lblOp.Caption = "+"End Sub
-----------------------------------------------------------------------------------------------------------------------7-Ordenar Numeros
Option ExplicitDim n1, n2, n3 As IntegerPrivate Sub Command1_Click()Label5.Caption = ""Label6.Caption = ""Label4.Caption = ""Label1.Visible = TrueLabel2.Visible = TrueLabel3.Visible = TrueCall azarEnd Sub
Private Sub azar()n1 = Int(Rnd * 10) + 1n2 = Int(Rnd * 10) + 1n3 = Int(Rnd * 10) + 1If n1 <> n2 And n2 <> n3 And n1 <> n3 ThenLabel1.Caption = n1Label2.Caption = n2Label3.Caption = n3ElseExit SubEnd IfEnd Sub
Private Sub Command2_Click()If Val(Label4.Caption) < Val(Label5.Caption) And Val(Label5.Caption) < Val(Label6.Caption) ThenLabel7.Caption = "Bien"ElseLabel7.Caption = "Mal"End IfEnd Sub
Private Sub Form_Load()RandomizeCall azarEnd Sub
4
Colocar los siguientes controles7 label 2command button. Las 3 sup mod
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
Private Sub Label4_DragDrop(Source As Control, X As Single, Y As Single)Label4.Caption = SourceSource.Visible = FalseEnd Sub
Private Sub Label5_DragDrop(Source As Control, X As Single, Y As Single)Label5.Caption = SourceSource.Visible = FalseEnd Sub
Private Sub Label6_DragDrop(Source As Control, X As Single, Y As Single)Label6.Caption = SourceSource.Visible = FalseEnd Sub
-----------------------------------------------------------------------------------------------------------------------8-Modificaciones en la fuenteDim valor As IntegerDim tipo As StringPrivate Sub Command1_Click()Label1.FontBold = TrueEnd Sub
Private Sub Command2_Click()Label1.FontItalic = TrueEnd Sub
Private Sub Command3_Click()Label1.FontUnderline = TrueEnd Sub
Private Sub Command4_Click()Label1.FontStrikethru = TrueEnd Sub
Private Sub Command5_Click()On Error Resume Nextvalor = InputBox("Introduzca el tamaño de la letra", "tamaño de la letra")Label1.FontSize = valorEnd Sub
Private Sub Command6_Click()On Error Resume Nexttipo = InputBox("introduzca el tipo de letra", "tipo de letra")Label1.FontName = tipoEnd Sub
Private Sub Command7_Click()Label1.FontBold = FalseLabel1.FontItalic = FalseLabel1.FontUnderline = FalseLabel1.FontStrikethru = FalseLabel1.FontSize = 10End Sub
Private Sub Command8_Click()Label1.FontItalic = TrueLabel1.FontUnderline = TrueLabel1.FontStrikethru = TrueEnd Sub
5
Colocar los siguientes controles1- label - 8 command button
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
-----------------------------------------------------------------------------------------------------------------------
9-CARITA FELIZ
Private Sub Picture2_DragOver(Source As Control, X As Single, Y As Single, State As Integer)Picture2.Visible = FalseEnd Sub
Private Sub Picture3_DragOver(Source As Control, X As Single, Y As Single, State As Integer)Picture1.Visible = TrueEnd Sub
Colocar los siguientes controles3 picture y una Label- Modif Propiedad de las Pictures Drag Mode a Automatic
-----------------------------------------------------------------------------------------------------------------------10-CARRITO DE COMPRA
Dim total As Integer------Private Sub Command1_Click()Text1.Text = "" ' vaciámos la caja de texto.total = 0 ' reiniciamos la variable a 0.End Sub
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)If Source = Picture1 Thentotal = total + 260ElseIf Source = Picture2 Thentotal = total + 300ElseIf Source = Picture3 Thentotal = total + 1400End IfText1.Text = totalEnd Sub
Private Sub Picture2_DragDrop(Source As Control, X As Single, Y As Single)If Source = Picture2 Thentotal = total + 300ElseIf Source = Picture1 Thentotal = total + 260ElseIf Source = Picture3 Thentotal = total + 1400End IfText1.Text = totalEnd Sub
Private Sub Picture3_DragDrop(Source As Control, X As Single, Y As Single)If Source = Picture3 Thentotal = total + 1400ElseIf Source = Picture1 Thentotal = total + 260ElseIf Source = Picture2 Thentotal = total + 300End If
6
Colocar los siguientes controles3 Picture 1 label 1 Text 1 Command Button Modif Propiedad de las Pictures Drag Mode a Automatic
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
Text1.Text = totalEnd Sub
--------------------------------------------------------------------------------11-COHETE
Private Sub Command1_Click()Timer1.Enabled = TrueEnd Sub
Private Sub Command2_Click()EndEnd SubPrivate Sub Label1_Click()Label1.Caption = Format("hh:mm:ss")End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Timer1.Enabled = FalseEnd Sub
Private Sub Timer1_Timer()Picture1.Move Picture1.Left, Picture1.Top - 100Label1.Caption = Format(Now, "hh:mm:ss")End Sub
--------------------------------------------------------------------------------12-CRUCIGRAMA
Private Sub Check1_Click() (programar c/u de los check)If Text1.Text = "R" And Text2.Text = "E" And Text3.Text = "P" And Text4.Text = "T" And Text5.Text = "I" And Text6.Text = "L" ThenLabel2.Caption = "Correcto"ElseLabel2.Caption = "InCorrecto"End IfEnd Sub
Private Sub Command1_Click()EndEnd Sub
----------------------------------------------------
13-Virus
Private Sub Command1_Click()For A = 0 To 10If A = 1 ThenMsgBox ("Se esta formateando el rígido")ElseIf A = 2 Then
7
Colocar los siguientes controles1 timer -2 command button 1 label- 1 pictureModificar: Timer:Prod: enabled = False Interval: 200Modificar PicturePropiedad DragMode= automatic
Colocar los siguientes controlesText (los necesarios) 3 checkbox3 label 1 command button
Material de la Asignatura Programación 4to AI – Inst. San RafaelMarisa E. Conde .Especialista en Informática Educativa – UBA-
MsgBox ("Se esta formateando el rigido")ElseIf A = 3 ThenMsgBox ("Se esta formateando el rigido")ElseIf A = 4 ThenMsgBox ("Se esta formateando el rigido")ElseIf A = 5 ThenMsgBox ("Se esta formateando el rigido")ElseIf A = 6 ThenMsgBox ("Se esta formateando el rigido")ElseIf A = 7 ThenMsgBox ("Se esta formateando el rigido")ElseIf A = 8 ThenMsgBox ("Se esta formateando el rigido")ElseIf A = 9 ThenMsgBox ("A punto de estallar")ElseIf A = 10 ThenMsgBox ("A punto de estallar")ElseIf A = 11 ThenMsgBox ("A punto de estallar")ElseIf A = 12 ThenMsgBox ("A punto de estallar")ElseIf A = 33 ThenMsgBox ("A punto de estallar")End IfNext Albl1.Visible = Truelbl1.Caption = "JA,JA.JA"lbl1.BackColor = vbRedForm1.BackColor = &H0&End SubPrivate Sub Form_Load()Form1.BorderStyle = 0Randomize TimerEnd Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) ' NO PERMITE CERRAR LA BARRA DE TITULO HASTA QUE LLEGUE AL NUMERO DESEADOStatic contador As IntegerIf UnloadMode = vbFormControlMenu Thencontador = contador + 1If contador < 10 Then Beep: Cancel = TrueEnd IfEnd Sub
8
Colocar los siguientes controles2 label 1 command button