Diferencias Entre SELECT CASE / IF...THEN


Objetivo: 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=

Perfil MP  
Objetivo: 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
if... then,
y luego dentro de el hay un

¿Te imaginas hacer los con 11
if..then,
,, 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

Objetivo: 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!!

Perfil MP  
Objetivo: Re: Diferencias Entre SELECT CASE / IF...THEN
Para gustos los colores...jajajajja


Un saludo

Ayortano
Objetivo: 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!!

Objetivo: 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!!

Perfil MP  

Página 1 de 1


  
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

   

Está utilizando la versión (Lo-Fi). Para ver la versión completa del foro, haga clic aquí.

Powered by Icy Phoenix based on phpBB
Design by DiDiDaDo

Página generada en:: 0.2377s (PHP: -38% SQL: 138%)
Consultas SQL: 29 - Debug off - GZIP Activado