I have recently started using the Select Case function instead of the If Then Else function when there are only two possible values. The reason for this is that I like being able to see what the value is being tested for instead of seeing what it isn't, if that makes sense. What I was wondering is if this is a bad idea. I don't think that it will break anything, but I didn't know if there would be a performance hit.
There's no performance hit that I know of. And even if there is one, it would be so slight as to not make a difference.
If I understand correctly, you like to explicitly see the values that match the condition for that branch of code. But there's no reason you can't do that with the if structure. Just change the else to an else if and explicitly define the condition.
But with both the if and select structures, I like to use the else option as a catch all. I will explicitly define all my scenarios, but I always include the else in case I miss something.
3 4682
There's no performance hit that I know of. And even if there is one, it would be so slight as to not make a difference.
If I understand correctly, you like to explicitly see the values that match the condition for that branch of code. But there's no reason you can't do that with the if structure. Just change the else to an else if and explicitly define the condition.
But with both the if and select structures, I like to use the else option as a catch all. I will explicitly define all my scenarios, but I always include the else in case I miss something.
I often provide the Case Else option when using the Select Case option, but not always (though I probably should). Well, that provides the information that I needed. Thanks Rabbit.
Technically it depends on how the compiler translates the commands but I guess the VBA compiler translates a SELECT CASE the same as IF-THEN-ELSE
Rabbit is correct that you will see no performance difference if the code is executed once, or even ten or hundred times, but if it is a function or in a loop that is executed a million time, it is another question. That is something you learn when programming for high performance environments, or heavy batch jobs, but then you should not use Access VBA
What does make difference on performance (but again not noticable) is how you construct the statement used in the IF-selection. A boolean check will be faster than a string compare.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Newbie |
last post by:
Dear friends,
I am having a hard time understanding how to use a SELECT CASE in ASP. I
have used it in VB but never in ASP scripting.
Scenerio:
I have 2 textboxes on a form that I have to...
|
by: ST |
last post by:
Hi, I'm trying to debug someone else's code, and I'm going thru this Select
Case statement. I'm having problems with the "OTHER" case...in that when the
first line of the case is false, it jumps...
|
by: Terencetrent |
last post by:
I having been using Access '97/2002 for about 4 years now and have
never really had the need or the time to learn visual basic. Well, I
think the time has finally come.
I need help with Visual...
|
by: MLH |
last post by:
Suppose the following...
Dim A as Date
A=#7/24/2005#
I wish to compare value of A against 2 other values:
1) 8/1/2005
2) 9/1/2005
Which is better and why...
First:
|
by: Lauren Quantrell |
last post by:
Is there any speed/resource advantage/disadvantage in using
Select Case x
Case 1
Case 2
etc. many more cases...
End Select
VS.
|
by: mark.irwin |
last post by:
Hello all,
Have an issue where a redirect pushes data to a page with a select case
which then redirects to another page. Problem is the redirect isnt
working in 1 case. Code below:
strURL =...
|
by: |
last post by:
Hello,
This is gonna sound real daft, but how do I test a Select Case statement for
variants of a theme?
Here's a snippet of my code...
Select Case sUsr
Case "Guest", "TsInternetUser",...
|
by: J-P-W |
last post by:
"Stock Value" Could be anything from 0 to a million or so, and might
include a decimal (12345.67)
I can't find how to do this:
Select Case StockValue
Case 0 To 30000
response.Write("Less...
|
by: scole954387 |
last post by:
Hi,
I have a problem. I have written a SQL statement that has a nested
select case statement on the 'where' clause to condition the results.
...
|
by: beacon |
last post by:
Hello to everybody,
I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |