Visual Basic - Error 13 en tiempo de ejecucion, los tipos

Life is soft - evento anual de software empresarial
 
Vista:

Error 13 en tiempo de ejecucion, los tipos

Publicado por Mariany (2 intervenciones) el 31/10/2011 15:17:24
Buenas, tengo un problema con este error, que me sale en la primera linea de codigo de este que ahora que les presentare, la verdad no se como resolverlo, y tampoco que lo causa, si me podrian ayudar le agradeceria.
es un programa que calcula el resultado de pruebas ecritas, y este codigo se supone calcula las respues PC, o Baremos de las respuestas de las personas.


If Text1(9).Text > 22 Then
Text1(1).Text = 99
ElseIf Text1(9).Text = 22 Then
Text1(1).Text = 98
ElseIf Text1(9).Text = 21 Then
Text1(1).Text = 97
ElseIf Text1(9).Text = 20 Then
Text1(1).Text = 96
ElseIf Text1(9).Text = 19 Then
Text1(1).Text = 95
ElseIf Text1(9).Text > 16 And Text1(9).Text < 19 Then
Text1(1).Text = 90
ElseIf Text1(9).Text = 16 Then
Text1(1).Text = 85
ElseIf Text1(9).Text = 15 Then
Text1(1).Text = 75
ElseIf Text1(9).Text = 14 Then
Text1(1).Text = 70
ElseIf Text1(9).Text = 13 Then
Text1(1).Text = 65
ElseIf Text1(9).Text = 12 Then
Text1(1).Text = 55
ElseIf Text1(9).Text = 11 Then
Text1(1).Text = 45
ElseIf Text1(9).Text = 10 Then
Text1(1).Text = 40
ElseIf Text1(9).Text = 9 Then
Text1(1).Text = 35
ElseIf Text1(9).Text = 8 Then
Text1(1).Text = 30
ElseIf Text1(9).Text = 7 Then
Text1(1).Text = 25
ElseIf Text1(9).Text = 6 Then
Text1(1).Text = 15
ElseIf Text1(9).Text = 5 Then
Text1(1).Text = 10
ElseIf Text1(9).Text = 4 Then
Text1(1).Text = 5
ElseIf Text1(9).Text = 3 Then
Text1(1).Text = 3
ElseIf Text1(9).Text < 3 Then
Text1(1).Text = 1
End If

'***********************************
'PC VR+NR
'***********************************

With Text1(15)
If .Text > 48 Then
Text1(7).Text = 99
ElseIf .Text > 46 And .Text < 48 Then
Text1(7).Text = 98
ElseIf .Text = 46 Then
Text1(7).Text = 97
ElseIf .Text > 43 And .Text < 46 Then
Text1(7).Text = 96
ElseIf .Text = 43 Then
Text1(7).Text = 95
ElseIf .Text > 36 And .Text < 43 Then
Text1(7).Text = 90
ElseIf .Text > 34 And .Text < 37 Then
Text1(7).Text = 85
ElseIf .Text = 34 Then
Text1(7).Text = 80
ElseIf .Text = 33 Then
Text1(7).Text = 75
ElseIf .Text > 30 And .Text < 33 Then
Text1(7).Text = 70
ElseIf .Text = 30 Then
Text1(7).Text = 65
ElseIf .Text > 27 And .Text < 30 Then
Text1(7).Text = 60
ElseIf .Text = 27 Then
Text1(7).Text = 55
ElseIf .Text = 26 Then
Text1(7).Text = 45
ElseIf .Text > 23 And .Text < 26 Then
Text1(7).Text = 40
ElseIf .Text = 23 Then
Text1(7).Text = 30
ElseIf .Text > 19 And .Text < 23 Then
Text1(7).Text = 25
ElseIf .Text > 17 And .Text < 20 Then
Text1(7).Text = 20
ElseIf .Text = 17 Then
Text1(7).Text = 15
ElseIf .Text > 14 And .Text < 17 Then
Text1(7).Text = 10
ElseIf .Text > 10 And .Text < 15 Then
Text1(7).Text = 5
ElseIf .Text = 10 Then
Text1(7).Text = 3
ElseIf .Text > 7 And .Text < 10 Then
Text1(7).Text = 2
ElseIf .Text < 8 Then
Text1(7).Text = 1
End If
End With
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

Error 13 en tiempo de ejecucion, los tipos

Publicado por Guido (71 intervenciones) el 08/02/2012 22:00:15
Curioso ejemplo de código el tuyo. Si no lo resolviste todavía, te comento: lo que te dice el compilador es que los tipos de datos están mezclados.

la propiedad .text de un textbox es una cadena de caracteres, y estás comparando una cadena de caracteres con un número.
En realidad VB, para hacerle más "fácil" la vida al programador (al programador desatento), hace la conversión de tipo por si mismo cuando se asigna la propiedad.
Ej: Text1(7).Text = 2
Allí el compilador debería advertirte que estas mezclando el tipo de datos, pero hace la conversión y la propiedad .text comienza a tener el valor "2" (no el nro 2, sino el valor "2").
En cambio cuando se intenta el condicional, ejemplo: "ElseIf .Text = 10 Then " produce error porque no puede comparar el Nro. 10 (valor numérico) contra una propiedad de texto.
Lo correcto sería:

If val(Text1(9).Text) > 22 Then
Text1(1).Text = Format(99)
ElseIf val(Text1(9).Text) = 22 Then
Text1(1).Text = format(98)
... etc

saludos, y ... suerte! :)
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