frequent assignments

  • Thread starter Thread starter max
  • Start date Start date
M

max

Hi all,
if in a procedure that is executed very often, like the OnCurrent event
(moving back and forth accross the recordset), I have to set a property for
a control, like me.cmdDelete.visible = false, just to make sure that the
button is not visible moving to another record, the result will be that most
of the times I will be setting to false a property that it is already false.
My question is the following:
in the above mentioned scenario, is it better to use:

1) me.cmdDelete.visible = false
and doing so setting a property to the same value it has already

or

2) if me.cmdDelete.visible = true then me.cmdDelete.visible = false
avoiding so a useless assignment but asking the application to verify a
condition.

The reason why I am asking is that I have to do this kind of assigments for
a lot of controls in the OnCurrent event, and I don't wont to deteriorate
the performance...

I hope the questiuon is clear .. :)

Thank you for your help.

Max
 
I would prefer 1 as IF statement may take longer to
execute since VBA will have to evaluate the condition.
Also, this sort of assigment statement probably takes
micro-secs to execute so I don't think it will noticeable.

HTH
Van T. Dinh
MVP (Access)
 
The difference would be negligible.

Confirm it yourself:

dim x as single, n as long
x = timer
for n = 1 to 50 squintillion
me![cmdDelete].visible = false
' if not me![CmdDelete].visible then me![cmdDelete].visible =
false
next
debug.print (timer - x); "secs"

HTH,
TC
 
Hi TC,
many many thanks for your answer and also for the brilliant idea to use this
code to measure the performance :))

Cheers,
Massimo


TC said:
The difference would be negligible.

Confirm it yourself:

dim x as single, n as long
x = timer
for n = 1 to 50 squintillion
me![cmdDelete].visible = false
' if not me![CmdDelete].visible then me![cmdDelete].visible =
false
next
debug.print (timer - x); "secs"

HTH,
TC


max said:
Hi all,
if in a procedure that is executed very often, like the OnCurrent event
(moving back and forth accross the recordset), I have to set a property for
a control, like me.cmdDelete.visible = false, just to make sure that the
button is not visible moving to another record, the result will be that most
of the times I will be setting to false a property that it is already false.
My question is the following:
in the above mentioned scenario, is it better to use:

1) me.cmdDelete.visible = false
and doing so setting a property to the same value it has already

or

2) if me.cmdDelete.visible = true then me.cmdDelete.visible = false
avoiding so a useless assignment but asking the application to verify a
condition.

The reason why I am asking is that I have to do this kind of assigments for
a lot of controls in the OnCurrent event, and I don't wont to deteriorate
the performance...

I hope the questiuon is clear .. :)

Thank you for your help.

Max
 
No probs :-)

TC


max said:
Hi TC,
many many thanks for your answer and also for the brilliant idea to use this
code to measure the performance :))

Cheers,
Massimo


TC said:
The difference would be negligible.

Confirm it yourself:

dim x as single, n as long
x = timer
for n = 1 to 50 squintillion
me![cmdDelete].visible = false
' if not me![CmdDelete].visible then me![cmdDelete].visible =
false
next
debug.print (timer - x); "secs"

HTH,
TC


max said:
Hi all,
if in a procedure that is executed very often, like the OnCurrent event
(moving back and forth accross the recordset), I have to set a
property
for
a control, like me.cmdDelete.visible = false, just to make sure that the
button is not visible moving to another record, the result will be
that
most
of the times I will be setting to false a property that it is already false.
My question is the following:
in the above mentioned scenario, is it better to use:

1) me.cmdDelete.visible = false
and doing so setting a property to the same value it has already

or

2) if me.cmdDelete.visible = true then me.cmdDelete.visible = false
avoiding so a useless assignment but asking the application to verify a
condition.

The reason why I am asking is that I have to do this kind of
assigments
for
a lot of controls in the OnCurrent event, and I don't wont to deteriorate
the performance...

I hope the questiuon is clear .. :)

Thank you for your help.

Max
 
Back
Top