|
Página 1 de 1
|
Diferencias Entre SELECT CASE / IF...THEN
Autor |
Mensaje |
AnSnarkista
Programador
Registrado: Junio 2010
Mensajes: 118
Edad: 33
|
Diferencias Entre SELECT CASE / IF...THEN
¿Que diferencias hay entre uno y otro?¿Consume mas recursos uno?
Seguimos con el tema comenzado en http://foro.gambas-es.org/viewtopic.php?f=1&t=822&highlight=
|
#1 Domingo, 01 Agosto 2010, 21:00 |
|
|
jsbsan
Analista Programador
Registrado: Septiembre 2009
Mensajes: 4175
Edad: 51 Ubicación: dos hermanas, sevilla
|
Re: Diferencias Entre SELECT CASE / IF...THEN
Pues mira cuando hay muchas comparaciones a realizar....
Fijate en este ejemplo que te pongo, primero hay un y luego dentro de el hay un
¿Te imaginas hacer los con 11 ,, con sus ,,, y que se te olvide alguno,, que lio,no?,, ¿¿¿por donde empezar a buscar el error????
Sin embargo con el Select Case queda todo mas claro...
FOR c = 0 TO FMain.TableViewdatos.rows.count - 1
tipo = Left(FMain.TableViewdatos[c, 0].text, 3)
restotipo = Right(FMain.TableViewdatos[c, 0].text, 2)
IF restotipo <> "01" THEN
SELECT CASE tipo
CASE "01."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalingreso)
CASE "02."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalgastobasicosAli)
CASE "03."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalgastobasicosRopa)
CASE "04."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalgastobasicosOtroGastos)
CASE "05."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalvehiculos)
CASE "06."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalocio)
CASE "07."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalformacion)
CASE "08."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalvivienda)
CASE "09."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalmascotas)
CASE "10."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalvarios)
CASE "11."
FMain.TableViewdatos[c, 4].text = f3(Val(f2(FMain.TableViewdatos[c, 3].text)) / var.sumatotalahorro)
END SELECT
ENDIF
NEXT
Espero que te sirva el ejemplo...
Un saludo
Julio
|
#2 Domingo, 01 Agosto 2010, 21:12 |
|
|
AnSnarkista
Programador
Registrado: Junio 2010
Mensajes: 118
Edad: 33
|
Re: Diferencias Entre SELECT CASE / IF...THEN
Ya, por eso mismo...jajajajajaja
Si queda mas claro en tu ejemplo, ¿porque no con lo demas?
A mi personalmente, me gusta mas, me es mas comodo leerlo y demas.
Si tiene algun porqué que lo haga peor que usar que el IF, pues lo usare, pero si es mera estetica, seguire prefiriendo el SELECT CASE.
Salud y graciaas!!
|
#3 Domingo, 01 Agosto 2010, 21:41 |
|
|
jsbsan
Analista Programador
Registrado: Septiembre 2009
Mensajes: 4175
Edad: 51 Ubicación: dos hermanas, sevilla
|
Re: Diferencias Entre SELECT CASE / IF...THEN
Para gustos los colores...jajajajja
Un saludo
|
#4 Lunes, 02 Agosto 2010, 20:33 |
|
|
Ayortano
|
Re: Diferencias Entre SELECT CASE / IF...THEN
Pues tienen usos diferentes. Yo uso IF cuando hay que comprobar algo y si existe, ejecutar determinada función. Select lo uso más bien cuando hago muchas condiciones según el valor de una variable y anidar IFs es bastante molesto (y sucio). Pero puedes usar cualquiera, ambos sirven.
Saludos!!
|
#5 Lunes, 02 Agosto 2010, 23:17 |
|
|
AnSnarkista
Programador
Registrado: Junio 2010
Mensajes: 118
Edad: 33
|
Re: Diferencias Entre SELECT CASE / IF...THEN
Yo la verdad es que estoy haciendo lo mismo que tu, si son para elegir entre opciones posibles, uso el SELECT CASE, pero si tengo que comprobar una cosa, uso el IF ... THEN.
Salud!!
|
#6 Lunes, 02 Agosto 2010, 23:21 |
|
|
|
Temas parecidos
Temas parecidos
|
Página 1 de 1
|
Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado Usuarios registrados conectados: Ninguno
|
No puede crear mensajes No puede responder temas No puede editar sus mensajes No puede borrar sus mensajes No puede votar en encuestas No puede adjuntar archivos Puede descargar archivos No puede publicar eventos en el calendario
|
|
|
|
|