Visual Basic - Ayuda por favor con ejercicio

Life is soft - evento anual de software empresarial
 
Vista:

Ayuda por favor con ejercicio

Publicado por Jorge (1 intervención) el 30/05/2011 01:14:49
1- Ingrese por teclado en una caja de texto la hora en formato de 24 horas y en otra caja de texto la cantidad de minutos al hacer clic en un botón deberá salir la hora en formato de 12 horas por ejemplo si se ingresa 23 en una caja y en la otra 12 el resultado seria 11:12:PM




Pos Data : aqui les dejo el ejercicio que esta en visual 2008 ayuda porfavor esto es lo que eh avanzado decirme que tengo que agregar por favor gracias!

Public Class FrmEj1

Private Sub txth_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txth.TextChanged
If Not IsNumeric(txth.Text) Then
txth.Text = "0"
End If
If txth.Text <= 24 Then
Else
MessageBox.Show("INGRESE NUMERO DEL 1 - 24")
End If
End Sub

Private Sub txtm_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtm.TextChanged
If Not IsNumeric(txtm.Text) Then
txtm.Text = "0"
End If
If txtm.Text <= 60 Then
btnA.Enabled = True
Else
MessageBox.Show("Ingrese un Numero del 0 al 60", "Alerta")
btnA.Enabled = False
txtm.Clear()
End If
End Sub

Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click
Dim time = txth.Text, minuto = txtm.Text, min, acu
Dim tipo As String
If minuto >= 0 And minuto <= 9 Then
min = "0" & minuto
Else
min = minuto
End If
If txth.Text > 12 And txth.Text <= 24 Then
tipo = "PM"
Else
tipo = "AM"
End If
If time >= 13 And time <= 24 Then
acu = time

Else
acu = txth.Text
End If
txts.Text = acu & ":" & min & ":" & tipo
End Sub
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Ayuda por favor con ejercicio

Publicado por jcmg (518 intervenciones) el 30/05/2011 06:04:51
Esto es en visual basic 6.0 (solo sigue la idea e introducela a tu codigo de visual 2008)

inserta 1 boton(command1)
inserta 2 textbox(text1,text2)
inserta 2 labels(label1,label2)

en el text1 van las horas
en el text2 van los minutos

la salida de los datos sera en el label1,label2
en el label1 saldra la hora en 24 horas
en el label2 saldra la hora en 12 horas

ya insertado todo lo anterior pega este codigo en declaraciones y corre el programa:
=======================================================================
Private Sub Command1_Click()
Rem verificar que no pasen de 24 horas
If (Text1 > 24) Then MsgBox "Solo hay 24 horas", 4096, "Mensaje": Exit Sub

Rem verificar que no pasen de sesenta minutos
If (Text2 > 60) Then MsgBox "Solo hay 60 minutos", 4096, "Mensaje": Exit Sub

Rem verificar que no se tecleen mas de 2 caracteres
If (Len(Text1)) > 2 Or (Len(Text2) > 2) Then Exit Sub

Rem contar de 13 en adelante y cambiarlo de 1 en adelante
If Text1 < 13 Then aa = Text1
If Text1 > 12 Then aa = 1
If Text1 > 13 Then aa = 2
If Text1 > 14 Then aa = 3
If Text1 > 15 Then aa = 4
If Text1 > 16 Then aa = 5
If Text1 > 17 Then aa = 6
If Text1 > 18 Then aa = 7
If Text1 > 19 Then aa = 8
If Text1 > 20 Then aa = 9
If Text1 > 21 Then aa = 10
If Text1 > 22 Then aa = 11
If Text1 > 23 Then aa = 12

Rem si son antes de las 12 es AM
If aa < 12 Then
Label2 = aa & ":" & Text2 & " AM"
Rem si son despues de las 12 es PM
ElseIf aa > 11 Then
Label2 = aa & ":" & Text2 & " PM"
End If

If Text1 <= 12 Then
Label1 = Text1 & ":" & Text2 & " AM"
ElseIf Text1 > 12 Then
Label1 = Text1 & ":" & Text2 & " PM"
End If
End Sub

Private Sub Form_Load()
Text1.Text = 23
Text2.Text = 12
Command1.Caption = "Aceptar"
End Sub

Rem solo admitir 2 caracteres
Private Sub Text1_KeyPress(KeyAscii As Integer)
Text1.MaxLength = 2
End Sub

Rem solo admitir 2 caracteres
Private Sub Text2_KeyPress(KeyAscii As Integer)
Text2.MaxLength = 2
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar