vb.net - Visual basic membership program using select case? -



vb.net - Visual basic membership program using select case? -

i writing programme asks user age , number of years have been member, trying through using select case. doesn't appear working, of ages fine if utilize checkbox veteran , should discount doesn't work. number of years have been fellow member doesn't alter price/ category, programme simple , i'm not sure why isn't working.

screen shot of program:http://gyazo.com/ebab66526068f4c81a30c624aada7f7c

code:

public class form1 private sub btncalc_click(byval sender system.object, byval e system.eventargs) handles btncalc.click dim x integer dim y integer x = val(txtage.text) y = val(txtyears.text) select case x case <= 18 lblprice.text = ("£60") lblcategory.text = ("junior") case 19 49 lblprice.text = ("£120") lblcategory.text = ("senior") case >= 50 lblprice.text = ("£80") lblcategory.text = ("over 50") case chkveteran.checked lblprice.text = ("£50") case <= 18 , y >= 2 lblprice.text = ("£40") lblcategory.text = ("2 year junior discount") case >= 50 , y >= 10 lblprice.text = ("£90") lblcategory.text = ("10 year senior discount") case chkveteran.checked , y >= 10 lblprice.text = ("£20") lblcategory.text = ("10 year veteran discount") end select end sub

end class

only 1 case block can run, seem expecting multiple blocks run. consider subset of clauses:

case <= 18 lblprice.text = ("£60") lblcategory.text = ("junior") case chkveteran.checked lblprice.text = ("£50") case <= 18 , y >= 2 lblprice.text = ("£40") lblcategory.text = ("2 year junior discount")

if x less or equal 18 first case block run. others ignored, regardless of state of chkveteran or y. series of case clauses needs mutually-exclusive in order logic create sense. example:

case <= 18 , y < 2 lblprice.text = ("£60") lblcategory.text = ("junior") case <= 18 , y >= 2 lblprice.text = ("£40") lblcategory.text = ("2 year junior discount")

these 2 clauses exclusive, 1 of them can apply @ time. each clause checked in order first lastly , first 1 matches execute. should set logic such first clause matches should only clause matches.

edit: in response separate comment thread...

you defined logic as:

a sports club has 3 categories of membership charge. juniors (ages 18) pay £60 per year, seniors (19-49) pay £120 , veterans (50 , over) pay £80. juniors have been fellow member 2 years or more £20 reduction. seniors , veterans have been members 10 years or more £30 reduction.

that sounds me 2 conditional sequences. first 1 define base of operations rate, this:

if age < 19 rate = 60 else if age < 50 rate = 120 else rate = 80 end if

the sec 1 define discount base of operations rate, this:

if age < 19 , tenure > 1 rate = rate - 20 else if age > 18 , tenure > 9 rate = rate - 30 end if

two separate conditional sequences, each checking exactly conditions explicitly defined in requirements. can farther refactor them create semantic meaning more clear. example, extract definitions of "junior, senior, , veteran" separate logic:

if isjunior(age) rate = 60 else if issenior(age) rate = 120 else if isveteran(age) rate = 80 end if

you can create functions each of those, like:

function isjunior(byval age integer) boolean homecoming age < 19 end function

this extracts details of implementation smaller helper functions , allows top-level logic expressed in semantic concepts rather implementation details, allowing overall look of logic match description given requirements much more clearly.

vb.net select

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -