473,770 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the switch statement has got me a little confused..can someone clear this up for me please

extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742, 1)

I look at this and say ok
if race = black and sex = female then extracalc = 1.952
if race = black then extracalc = 1.21
if sex = female then extracalc = .742

else

extracalc = 1
but of course this gives an error because to work it has to have
another value
such as 999

extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742,999, 1)

what does the 999 place represent?

if all test are false then it would be null would it not?

not sure what I am missing here but can someone explain what the
places for 999 and 1 repesent

it just looks like it has one more value than it needs
thanks big time

Jerry
Dec 7 '05 #1
6 1553
As you said, if all tests are false, the switch function returns null.
Therefore, it doesn't take an extra "else" value at the end. It only takes
pairs of (test), (value if true).
"sparks" <js******@swbel l.net> wrote in message
news:kn******** *************** *********@4ax.c om...
extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742, 1)

I look at this and say ok
if race = black and sex = female then extracalc = 1.952
if race = black then extracalc = 1.21
if sex = female then extracalc = .742

else

extracalc = 1
but of course this gives an error because to work it has to have
another value
such as 999

extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742,999, 1)

what does the 999 place represent?

if all test are false then it would be null would it not?

not sure what I am missing here but can someone explain what the
places for 999 and 1 repesent

it just looks like it has one more value than it needs
thanks big time

Jerry

Dec 7 '05 #2
thats what I thought but it doesn't work.
the first statement will give you an error until you add something
like the 999 I did in the second statement.

I can't understand what it expects to see and why.
it like
else 999
else 1
or something like that
Jerry

On Wed, 7 Dec 2005 09:43:31 -0800, "John Welch"
<j+ohnw+elch@ca l+central.com (remove +'s)> wrote:
As you said, if all tests are false, the switch function returns null.
Therefore, it doesn't take an extra "else" value at the end. It only takes
pairs of (test), (value if true).
"sparks" <js******@swbel l.net> wrote in message
news:kn******* *************** **********@4ax. com...
extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742, 1)

I look at this and say ok
if race = black and sex = female then extracalc = 1.952
if race = black then extracalc = 1.21
if sex = female then extracalc = .742

else

extracalc = 1
but of course this gives an error because to work it has to have
another value
such as 999

extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742,999, 1)

what does the 999 place represent?

if all test are false then it would be null would it not?

not sure what I am missing here but can someone explain what the
places for 999 and 1 repesent

it just looks like it has one more value than it needs
thanks big time

Jerry


Dec 7 '05 #3
It is thinking that your 999 and 1 are just another pair like "black = -1,
1.21". Take out both the 999 and the 1, so that you just have the three
pairs.

"sparks" <js******@swbel l.net> wrote in message
news:oj******** *************** *********@4ax.c om...
thats what I thought but it doesn't work.
the first statement will give you an error until you add something
like the 999 I did in the second statement.

I can't understand what it expects to see and why.
it like
else 999
else 1
or something like that
Jerry

On Wed, 7 Dec 2005 09:43:31 -0800, "John Welch"
<j+ohnw+elch@ca l+central.com (remove +'s)> wrote:
As you said, if all tests are false, the switch function returns null.
Therefore, it doesn't take an extra "else" value at the end. It only takes
pairs of (test), (value if true).
"sparks" <js******@swbel l.net> wrote in message
news:kn****** *************** ***********@4ax .com...
extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742, 1)

I look at this and say ok
if race = black and sex = female then extracalc = 1.952
if race = black then extracalc = 1.21
if sex = female then extracalc = .742

else

extracalc = 1
but of course this gives an error because to work it has to have
another value
such as 999

extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742,999, 1)

what does the 999 place represent?

if all test are false then it would be null would it not?

not sure what I am missing here but can someone explain what the
places for 999 and 1 repesent

it just looks like it has one more value than it needs
thanks big time

Jerry

Dec 7 '05 #4
well if you do that you have no else for the other 16 combos that are
not these three...they are all = 1.

On Wed, 7 Dec 2005 10:27:13 -0800, "John Welch"
<j+ohnw+elch@ca l+central.com (remove +'s)> wrote:
It is thinking that your 999 and 1 are just another pair like "black = -1,
1.21". Take out both the 999 and the 1, so that you just have the three
pairs.

"sparks" <js******@swbel l.net> wrote in message
news:oj******* *************** **********@4ax. com...
thats what I thought but it doesn't work.
the first statement will give you an error until you add something
like the 999 I did in the second statement.

I can't understand what it expects to see and why.
it like
else 999
else 1
or something like that
Jerry

On Wed, 7 Dec 2005 09:43:31 -0800, "John Welch"
<j+ohnw+elch@ca l+central.com (remove +'s)> wrote:
As you said, if all tests are false, the switch function returns null.
Therefore, it doesn't take an extra "else" value at the end. It only takes
pairs of (test), (value if true).
"sparks" <js******@swbel l.net> wrote in message
news:kn***** *************** ************@4a x.com...
extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742, 1)

I look at this and say ok
if race = black and sex = female then extracalc = 1.952
if race = black then extracalc = 1.21
if sex = female then extracalc = .742

else

extracalc = 1
but of course this gives an error because to work it has to have
another value
such as 999

extracalc = Switch(Me.Paren t.Race_Black = -1 And Me.Parent.Sex =
"Female", 1.952, Me.Parent.Race_ Black = -1, 1.21, Me.Parent.Sex =
"Female", 0.742,999, 1)

what does the 999 place represent?

if all test are false then it would be null would it not?

not sure what I am missing here but can someone explain what the
places for 999 and 1 repesent

it just looks like it has one more value than it needs
thanks big time

Jerry


Dec 7 '05 #5
You can use 999,1 if you want and it will give you an 'else' of 1, because
999 will evaluate to "true" and so the switch will get a value of 1.
It would be more clear to say it more directly, like: black = -1,1.2,
sex='female', 1.3, true, 1
"sparks" <js******@swbel l.net> wrote in message
news:sq******** *************** *********@4ax.c om...
well if you do that you have no else for the other 16 combos that are
not these three...they are all = 1.

On Wed, 7 Dec 2005 10:27:13 -0800, "John Welch"
<j+ohnw+elch@ca l+central.com (remove +'s)> wrote:
It is thinking that your 999 and 1 are just another pair like "black = -1,
1.21". Take out both the 999 and the 1, so that you just have the three
pairs.

"sparks" <js******@swbel l.net> wrote in message
news:oj****** *************** ***********@4ax .com...
thats what I thought but it doesn't work.
the first statement will give you an error until you add something
like the 999 I did in the second statement.

I can't understand what it expects to see and why.
it like
else 999
else 1
or something like that

Dec 7 '05 #6
thanks that clears that up.
it was the 999 that was throwing me
Jerry

On Wed, 7 Dec 2005 12:31:29 -0800, "John Welch"
<j+ohnw+elch@ca l+central.com (remove +'s)> wrote:
You can use 999,1 if you want and it will give you an 'else' of 1, because
999 will evaluate to "true" and so the switch will get a value of 1.
It would be more clear to say it more directly, like: black = -1,1.2,
sex='female' , 1.3, true, 1
"sparks" <js******@swbel l.net> wrote in message
news:sq******* *************** **********@4ax. com...
well if you do that you have no else for the other 16 combos that are
not these three...they are all = 1.

On Wed, 7 Dec 2005 10:27:13 -0800, "John Welch"
<j+ohnw+elch@ca l+central.com (remove +'s)> wrote:
It is thinking that your 999 and 1 are just another pair like "black = -1,
1.21". Take out both the 999 and the 1, so that you just have the three
pairs.

"sparks" <js******@swbel l.net> wrote in message
news:oj***** *************** ************@4a x.com...
thats what I thought but it doesn't work.
the first statement will give you an error until you add something
like the 999 I did in the second statement.

I can't understand what it expects to see and why.
it like
else 999
else 1
or something like that


Dec 8 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2825
by: prafulla | last post by:
Hi all, I don't have a copy of C standard at hand and so anyone of you can help me. I have always wondered how switch statements are so efficient in jumping to the right case (if any)? Can anybody point me to the innards of it please? Sorry if this is OT on clc and more relevant to comp.compilers. I am confused here too.
13
3073
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default: to catch unhandled cases, but of course this is only at run-time. Example: public enum MyEnum { one, two, three, four }
15
3517
by: Benny Raymond | last post by:
I'm confused as to how fallthrough is limited in switch. For example the following works: string switch_test = "a"; switch (switch_test) { case "a": case "b": case "c": doSomething(a);
35
3623
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is to management theses :-((( I must to declare and use all variable with this scheme :
14
6259
by: serrand | last post by:
Could someone tell me a beautiful way to exit from a switch and a loop in one statement ... without using a goto... and if possible without using an auxiliary variable as i did... int res; while (1) { res = 0; if ((i = msgrcv (msqid, &rq_resa, SZ_MsgSrcResa, pid(), 0) == -1) { aff_erreurs ("msgrcv", "Error when recieving message : %d", errno);
9
1610
by: Raj | last post by:
public static void HandleException(ref Exception io_exException, bool i_blnPropagateException) { switch (true) { case io_exException is ApplicationHandledException: { if (i_blnPropagateException) {
22
3175
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point numbers then added support for putting in lat/lon coordinates. I tried this little piece of code inside the OnChar function but compiler complained about missing ';' after "case _T('W'):"
2
2882
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of various module that I found it useful. Here is the 1st problem I encounter: I had a function to edit a event row form the database which is fine with me, than I pass on the code to a function that save(update) the data to the database.
9
6281
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who only has read access to the users table so that users can log in. Once a user has been logged in successfully I want to escalate that user's access level to one appropriate to their role, which will include switching the postgres user they are...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.