codigos visual basic

Upload: don-mao

Post on 19-Feb-2018

241 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 Codigos Visual Basic

    1/7

    Hola!!

    Estos son los cdigos de los ejercicios mas comunes y faciles de Visual Basic

    6.0

    EJERCICIO DE LA CALCULADORA

    El botn Nuevo ClculoPrivate Sub Command5_Click()

    Text1 = ""

    Text2 = ""

    Text3 = ""

    Text1.SetFocus

    End Sub

    El botn Sumar

    Private Sub Command1_Click()

    Text3 = Val(Text1) + Val(Text2)

    End Sub

    El botn Restar

    Private Sub Command2_Click()

    Text3 = Val(Text1) - Val(Text2)

    End Sub

    El botn Multiplicar

    Private Sub Command3_Click()Text3 = Val(Text1) * Val(Text2)

    End Sub

    El botn Dividir

    Private Sub Command4_Click()

    Text3 = Val(Text1) / Val(Text2)

  • 7/23/2019 Codigos Visual Basic

    2/7

    End Sub

    El botn Salir

    Private Sub Command6_Click()

    Unload Me

    End

    End Sub

    EJERCICIO CALCULADORA 2

    El botn Calcular

    Private Sub Command1_Click()

    If Option1 = True Then

    Text3 = Val(Text1) / Val(Text2)ElseIf Option2 = True Then

    Text3 = Val(Text1) * Val(Text2)

    ElseIf Option3 = True Then

    Text3 = Val(Text1) - Val(Text2)

    ElseIf Option4 = True Then

    Text3 = Val(Text1) + Val(Text2)

    End If

    End Sub

    El botn Otra Operacin

    Private Sub Command2_Click()

    Text1 = ""

    Text2 = ""

    Text3 = ""

    Text1.SetFocus

    End Sub

    EJERCICIO CONVERSIONES

    El botn Convertir

    Private Sub Command1_Click()

    If Option1 = True Then

    Text2 = Val(Text1) * 1000

    ElseIf Option2 = True Then

  • 7/23/2019 Codigos Visual Basic

    3/7

    Text2 = Val(Text1) * 100

    ElseIf Option3 = True Then

    Text2 = Val(Text1) * 10

    ElseIf Option4 = True Then

    Text2 = Val(Text1) / 1000

    End If

    End Sub

    EJERCICIO TABLAS

    El botn Ver Tabla

    Private Sub Command1_Click()

    Dim res As Long, retorno

    For n = 1 To 10

    res = Text1 * nretorno = Chr(13) & Chr(10)

    Text2 = Text2 & Text1 & " x " & n & " = " & res & retorno

    Next n

    End Sub

    El botn Salir

    DimDim se utiliza para declarar variables. Existen varios tipos de variables: String (cadena), Variant(variante), Boolean (booleana, de valor True o alse), !ong (larga) Double (doble),... " sedeclara del siguiente modo:

    Dim Variable#s String Variable $ Valor

    %&!a estructura %& es m's conocida como %&TenElse por su estructura. %& compara todo lo *ue leindi*uemos, como variables, constantes, nombres, ubicaciones,... +uede comparar de variosmodos: (menor *ue), - (maor *ue), - (di&erente de), $ (igual), $ (menor o igual), -$(maor o igual)/ se declara como:

    %&Variable $ 0 Ten DimVar Var $ 0 Else Dim Var Var $ 1 End %&

  • 7/23/2019 Codigos Visual Basic

    4/7

    2sgBox!os 2sgBox o cuadros de mensa3e son cuadros donde se puede seleccionar un texto avisualizar, un t4tulo unos botones, as4 como un estilo (vb5ritical para cr4ticos, vbExclamationpara exclamaci6n, vb%n&ormation para in&ormaci6n, vb7uestion para preguntas, vb"es8nl

    para solo bot6n de 9S49, vb"eso para s4 no, vb"eso5ancel para s4, no cancelar,vb#bort;etr%gnore para cancelar, reintentar ignorar. 2odo de uso:

    2sgBox

  • 7/23/2019 Codigos Visual Basic

    5/7

    5lose Gumero#rcivo

  • 7/23/2019 Codigos Visual Basic

    6/7

  • 7/23/2019 Codigos Visual Basic

    7/7

    The

    End

    ElseCance

    = 1E

    I EJER ICIO TERM

    TROBoton

    lirPrivate Sub cmbSalir_Cl

    ck()

    Bee

    EndEn

    ubPrivate Sub mnuFileExit_Cl

    ck(

    EndEn

    Sub

    rraPrivate Sub vsbTemp_Cha

    ge()txtCent.Text = vsbTemp.

    aluetxtFahr.Text = 32 + 1.8 * vsbTemp.

    alueEn