Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

  1. Home >
  2. All Categories >
  3. Computers & Internet >
  4. Programming & Design >
  5. Resolved Question
diesel727_501 diesel72...
Member since:
September 04, 2007
Total points:
792 (Level 2)

Resolved Question

Show me another »

Ayuda con el codigo fuente de Visual BASIC 6?

Necesito un programa que determine si la letra ingresada es una vocal o una consonante

este es el codigo que hice pero dice ilegal else without if

Private Sub Command1_Click()
If Text1.Text = "a" Then
Label2 = "Es una vocal"
End If

If Text1.Text = "e" Then
Label2 = "Es una vocal"
End If
If Text1.Text = "i" Then
Label2 = "Es una vocal"
End If
If Text1.Text = "o" Then
Label2 = "Es una vocal"
End If
If Text1.Text = "u" Then
Label2 = "Es una vocal"
End If
Else
Label2 = "es una consonante"
End If


End Sub
P@C0 - famc by P@C0 - famc
Member since:
January 09, 2008
Total points:
2,643 (Level 4)

Best Answer - Chosen by Asker

prueba asi:

If Text1.Text = "a" or Text1.Text = "e" or Text1.Text = "i" or Text1.Text = "o" or Text1.Text = "u" then
Label2= "vacal"
Else
Label2="Consonante"
endif

en tu programa solo te imprime que es vocal, y si no es u te imprimira consonante, puedes anidar el if.

una tercera opcion es usar la funcion InStr que funcionaria asi

if InStr("aeiou", Text1.Text) > 0 then
Label2= "Es vocal"
else
Label2="No es vocal
end if
Asker's Rating:
4 out of 5
Asker's Comment:
Gracias, el que mencionas al ultimo funciona perfecto

There are currently no comments for this question.

This question about "Ayuda con el codigo … " was originally asked on Yahoo! Answers Mexico

Other Answers (3)

  • bushin20mx by bushin20...
    Member since:
    September 03, 2007
    Total points:
    1,780 (Level 3)
    Checa bien la estructura de tus if... el ultimo else no esta dentro de un if por que todos los anteriores los cerraste. Eso te provoca el error

    Pienso que seria mucho mas sencillo realizarlo con un select case y ademas mas legible

    Esta bien... te dare el codigo completito para que cada letra que presiones te diga si es o no consonante

    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    Select Case UCase(Chr(KeyCode))
    Case "A", "E", "I", "O", "U"
    Label1.Caption = "Es una vocal"
    Case Else
    Label1.Caption = "Es una consonante"
    End Select

    End Sub

    Este codigo te dira por cada letra que presiones, sin importar si es o no mayuscula

    RECUERDA que este codigo debe ir en el evento keyup de la caja de texto, asi no tendras que usar un boton de comando
  • Tanddy by Tanddy
    Member since:
    February 12, 2008
    Total points:
    1,369 (Level 3)
    Tu codigo arregladito:

    Private Sub Command1_Click()
    vmivar=0
    If Text1.Text = "a" Then
    Label2 = "Es una vocal"
    vmivar=1
    End If

    If Text1.Text = "e" Then
    Label2 = "Es una vocal"
    vmivar=1
    End If
    If Text1.Text = "i" Then
    Label2 = "Es una vocal"
    vmivar=1
    End If
    If Text1.Text = "o" Then
    Label2 = "Es una vocal"
    vmivar=1
    End If
    If Text1.Text = "u" Then
    Label2 = "Es una vocal"
    vmivar=1
    End If
    if mivar=1
    Label2 = "es una consonante"
    end if
    End sub

    Espero te ayude, ahh por si acaso debes compara tambien las mayusculas!!!!!
  • Sheccid by Sheccid
    Member since:
    February 28, 2008
    Total points:
    539 (Level 2)
    Creo no se esta utilizando bien el bucle a ver intentalo de este modo a ver q pasa...

    Private Sub Command1_Click()
    If Text1.Text = "a" Then
    Label2 = "Es una vocal"
    Else If Text1.Text = "e" Then
    Label2 = "Es una vocal"
    Else If Text1.Text = "i" Then
    Label2 = "Es una vocal"
    Else If Text1.Text = "o" Then
    Label2 = "Es una vocal"
    Else If Text1.Text = "u" Then
    Label2 = "Es una vocal"
    Else
    Label2 = "es una consonante"

    End If

    End sub

    La vdd no tengo un compilador a la mano y no se si si este bien. Bueno...espero q te sirva...BYE

Answers International

Yahoo! does not evaluate or guarantee the accuracy of any Yahoo! Answers content. Click here for the Full Disclaimer.

Help us improve Yahoo! Answers. Send Feedback