problemas vb
Embed Size (px)
DESCRIPTION
Problemas resueltos visual basic 6TRANSCRIPT
Nombre: Prez Trujillo Karla Michelle Fecha: 21 de Enero 2016No. Cuenta :314012483 Grupo:82A
CUESTIONARIO
1. Qu es un objeto? Cmo lo identificas en el cdigo ejemplo?R=Unobjetoes una combinacin de cdigo y datos que puede tratarse como una unidad.Un objeto puede ser una porcin de una aplicacin, como un control o un formulario.Los objetos actan como bloques de creacin prefabricados para programas: permiten escribir una porcin de cdigo y utilizarla una y otra vez.
En el cdigo ejemplo el objeto es la etiqueta y el botn de comando que se asigno a travs del programa, lugar donde se escribi el cdigo 2. Qu es un evento? Cmo lo identificas en el cdigo ejemplo?R= Un evento es una seal que comunica a una aplicacin que ha sucedido algo importanteLos eventos tambin permiten que las tareas separadas se comuniquen.
En el cdigo ejemplo un evento se ejecuta a partir de la asignacin de un cdigo especfico para ese evento que en este caso fue el evento click
3. Qu es una propiedad o atributo? En el cdigo Cual es?R=Son etiquetas descriptivas aque proporcionan informacin adicional, con los atributos, puede especificar los metadatos casi del mismo modo en que utiliza palabras clave comoPublicyPrivatepara proporcionar informacin sobre niveles de acceso.
En el cdigo ejemplo se utiliza PRIVATE
PRACTICA 2
Definicin del problemaSumar dos nmeros enteros en visual basic.Anlisis del problema
Se necesita una 4 etiquetas , 3 cajas de texto y un botn de comando Asignar nombre a los objetos Label1.Caption=Suma de dos numerosLabel2.Caption=Num1Label3.Caption=Num2Label4.Caption=RESULTADOCommand1.Caption=SUMAR Para declarar una variable entera se escribe dentro de cada procedimiento:Dim Num1 As IntegerDim Num2 As Integer Para obtener valores se declaran:Num1 = Val(Text1)Num2 = Val(Text2)Text3 = str(Num1 + Num2)
Diseo de la solucin del problemaa) Algoritmo1. Inicio2. Leer Num13. Leer Num24. Suma=Num1+Num25. Mostrar suma6. Fin
b) Diagrama de flujo
INICIO
Num1
Num2
Suma=Num1+Num2
Mostrar suma
FIN
Desarrollo a la Solucin del Problema 'Nombre:Perez Trujillo Karla Michelle Grupo:82A NCuenta:314012483'Suma de dos numeros enterosPrivate Sub Command1_Click()Num1 = Val(Text1)Num2 = Val(Text2)Text3.Enabled = TrueText3 = Str(Num1 + Num2)Text3.Enabled = FalseEnd Sub
Private Sub Form_Load()Label1.Caption = "Suma de dos numeros"Label1.Alignment = 2Label1.FontSize = 18Label2.Caption = "Num1"Label2.Alignment = 2Label2.FontSize = 14Label3.Caption = "Num2"Label3.Alignment = 2Label3.FontSize = 14Label4.Caption = "Resultado"Label4.Alignment = 2Label4.FontSize = 14Command1.Caption = "Suma"Command1.FontSize = 14Text3.Enabled = FalseText1.FontSize = 16Text1.Alignment = 2Text2.FontSize = 16Text2.Alignment = 2Text3.Alignment = 2Text3.FontSize = 16
End SubPrivate Sub Text1_Change()Dim Num1 As IntegerEnd Sub
Private Sub Text2_Change()Dim Num2 As IntegerEnd Sub
'Nombre:Perez Trujillo Karla Michelle Grupo:82A NCuenta:314012483'Codigo del form. principalPrivate Sub Command1_Click()Form2.ShowEnd Sub
Private Sub Form_Load()Form1.Caption = "frmPrincipal"Command1.Caption = "Cargar Formulario"End Sub
'Codigo frm.SecundarioPrivate Sub Command1_Click()HideEnd Sub
Private Sub Command2_Click()Unload MeEnd Sub
Private Sub Command3_Click()HideSet Form2 = NothingEnd Sub
Private Sub Form_Activate()MsgBox ("Evento Activete")End Sub
Private Sub Form_Deactivate()MsgBox ("Evento Deactivete")End Sub
Private Sub Form_Initialize()MsgBox ("Evento Initialize")End Sub
Private Sub Form_Load()Form2.Caption = "frmSecundario"Command1.Caption = "Hide"Command2.Caption = "Unload"Command3.Caption = "Terminate"MsgBox ("Evento Load")End Sub
Private Sub Form_Paint()MsgBox ("Evento Paint")End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)MsgBox ("QuaryUnload")End Sub
Private Sub Form_Terminate()MsgBox ("Terminate")End Sub
Private Sub Form_Unload(Cancel As Integer)MsgBox ("Unload")End Sub1. Cules son los eventos que se cargan al iniciar un formulario?
2. Para qu sirve el evento "Initialize"?
3. Cundo se produce el evento "Unload"?
4. Qu actividades NO se pueden hacer sobre el evento "load"?
5. Explica que hace el mtodo "hide" y el mtodo "show".
6. Qu hace el evento Activate y cuando se realiza?
7. En qu parte del compilador de Visual Basic se colocan los Mens?
8. qu hace el evento "Terminate"?
9. en tu practica, para que se usa la instruccin MsgBox?
10. Para que sirve el evento Paint?
PRACTICA 4 Definicin del problema
Pedirle al usuario lo siguientes datos : nombre ,edad ,estatura y promedio escolar .-Despus el programa debe de decirnos si el usuario es "Mayor de Edad" o "Menor de edad".-Si mide mas de 1.60 metros, "Alto" en caso contrario "Bajo"-Si el promedio es mayor de 8.0 escribir "Buen aprovechamiento", si es menor "Regular aprovechamiento"
Anlisis del Problema -Se necesitaran 1 etiqueta, 7 cajas de texto y un botn de comando -Nombrar a los objetos Text1.Text = "Cul es tu nombre?"Text2.Text = "Qu edad tienes?"Text3.Text = "Cunto mides?"Text4.Text = "Cul es tu promedio escolar?"Label1.Caption = "Ingresa los siguientes datos y obten tu valoracin"Command1.Caption = "Valoracin"Text5.Text = ""Text6.Text = ""Text7.Text = ""-Asignar el tipo de dato adecuado para las cajas de texto con las que interactuara el usuarioDim Text1 As StringDim Text2 As IntegerDim Text3 As SingleDim Text4 As Single-Para que la maquina le de sus valoraciones se tendr que utilizar la sentencia ifthenelseIf Text2 > 18 ThenText5 = "Eres mayor de edad"ElseText5 = "Eres Menor de Edad"End IfIf Text3 > 1.6 ThenText6 = "Eres Alto"ElseText6 = "Eres Bajo"End IfIf Text4 > 8 ThenText7 = "Buen Aprovechamieto"ElseText7 = "Regular Aprovechamiento"End If
Diseo de la solucin del problema a) Algoritmo 1. Inicio2. Leer Text13. Leer Text24. Leer Text35. Leer Text46. Si (Text2>18) entoncesText5 = "Eres mayor de edad"Sino Text5 = "Eres Menor de Edad"Finalizar 7. Si (Text3>1.60) entonces Text6 = "Eres Alto"Si no Text6 = "Eres Bajo"Finalizar8. Si (Text4>8.0)entoncesText7 = "Buen Aprovechamiento"Text7 = "Regular Aprovechamiento"Finalizar9. FIN
b) Diagrama de flujo
Desarrollo de la solucin del problema
'Nombre: Perez Trujillo Karla Michelle NCuenta:314012483'Practica 4
Private Sub Command1_Click()Text1.Enabled = FalseText2.Enabled = FalseText3.Enabled = FalseText4.Enabled = FalseText5.Enabled = TrueIf Text2 > 18 ThenText5 = "Eres mayor de edad"ElseText5 = "Eres Menor de Edad"End IfIf Text3 > 1.6 ThenText6 = "Eres Alto"ElseText6 = "Eres Bajo"End IfIf Text4 > 8 ThenText7 = "Buen Aprovechamiento"ElseText7 = "Regular Aprovechamiento"End IfEnd SubText5.Enabled = FalseText6.Enabled = FalseText7.Enabled = FalsePrivate Sub Form_Load()Text1.Text = "Cul es tu nombre?"Text1.Alignment = 2Text1.FontSize = 14Text2.Text = "Qu edad tienes?"Text2.Alignment = 2Text2.FontSize = 14Text3.Text = "Cunto mides?"Text3.Alignment = 2Text3.FontSize = 14Text4.Text = "Cul es tu promedio escolar?"Text4.Alignment = 2Text4.FontSize = 14Label1.Caption = "Ingresa los siguientes datos y obten tu valoracin"Label1.Alignment = 2Label1.FontSize = 18Label1.ForeColor = vbBlueCommand1.Caption = "Valoracin"Command1.FontSize = 14Text5.Text = ""Text5.Alignment = 2Text5.FontSize = 14Text6.Text = ""Text6.Alignment = 2Text6.FontSize = 14Text7.Text = ""Text7.Alignment = 2Text7.FontSize = 14Form1.BackColor = vbBlackEnd SubPrivate Sub Salir_Click()MsgBox ("Salir")End SubPrivate Sub Text1_Change()Dim Text1 As StringEnd SubPrivate Sub Text1_Click()Text1.Enabled = TrueText1.Text = ""End SubPrivate Sub Text2_Change()Dim Text2 As IntegerEnd SubPrivate Sub Text2_Click()Text2.Enabled = TrueText2.Text = ""End Sub
Private Sub Text3_Change()Dim Text3 As SingleEnd Sub
Private Sub Text3_Click()Text3.Enabled = TrueText3.Text = ""End Sub
Private Sub Text4_Change()Dim Text4 As SingleEnd Sub
Private Sub Text4_Click()Text4.Enabled = TrueText4.Text = ""End SubPrivate Sub Form_Terminate()MsgBox ("Salir")End Sub
Practica 6 Mini-calculadoraDefinicin del problema Disear una calculadora que realice las operaciones bsicas (suma , resta, divisin, multiplicacin) agregando la exponenciacin y la raz en visual basic
Anlisis del problema
-Se necesitaran 3 etiquetas, 3 cajas de texto y 6 botones de comando -Asignar los nombres a los objetos :Label1.Caption = "MINICALCULADORA"Label2.Caption = ""Label3.Caption = "="Text1.Text = ""Text2.Text = ""Text3.Text = ""Command1.Caption = "+"Command2.Caption = "-"Command3.Caption = "/"Command4.Caption = "*"Command5.Caption = "^"Command6.Caption = "raiz"Command7.Caption=!(Factorial)-Considerar el tipo de operador que utilizara cada comando Command1----- Str(Num1 + Num2)Command2----- Str(Num1 - Num2)Command3----- Str(Num1 / Num2)Command4----- Str(Num1 * Num2)Command5----- Str(Num1 ^ Num2)Command6----- Sqr(Num1)Commanad7---fac = 1cont = 1While (cont a(s) Then p = a(i) a(i) = a(s) a(s) = p End If Next s Next i List1.Clear For i = 0 To n - 1List1.List(i) = a(i)Next iEnd Sub
Private Sub Command3_Click()Dim i, n, s, p, a() As Integern = List1.ListCountReDim a(n)For i = 0 To n - 1a(i) = List2.List(i)Next i For i = 0 To n - 2 For s = i + 1 To n - 1 If a(i) < a(s) Then p = a(i) a(i) = a(s) a(s) = p End If Next s Next i List2.Clear For i = 0 To n - 1List2.List(i) = a(i)Next iEnd SubPrivate Sub Command1_Click()Dim num, num1, num2, num3, raiz As Singlenum1 = Val(Text1)If num1 < 0 ThenMsgBox "No es valido"Elsenum2 = num1 / 2num = num1 / num2num3 = num + num2raiz = 1 / 2 * num3End If raiz = 1 / 2 * ((num1 / raiz) + raiz) resultado = raiz * raiz If resultado = num1 + 0.0001 Then text2 = raiz Else If resultado = num1 > num1 + 0.0001 < num1 + 0.005 Then raiz = 1 / 2 * ((num1 / raiz) + raiz) text2 = raiz End If End If End Sub
Private Sub Form_Load()Label1.Caption = "RAZ CUADRADA"Label1.Alignment = 2Label1.FontSize = 14Label2.Caption = "Ingresa un nmero real para obtener su raz cuadrada "Text1.Text = " "Text1.FontSize = 14Text1.Alignment = 2text2.Text = " "text2.FontSize = 14text2.Alignment = 2Command1.Caption = "Resultado"
End Sub
Private Sub Text1_Change()Dim Text1 As IntegerEnd Sub
Private Sub Text2_Change()Dim text2 As Single
End Sub