vba - Variable Not Passing Through Class -


i'm trying write simple program in visual basic passes variable through class, calculates it, returns it. form "pizza" has 2 groups 3 radio buttons each. when total button clicked pizza size price added pizza crust price. found through troubleshooting adding "createpizza.crust" + "createpizza.size". missing. thank help.

form "pizza" public class pizza  private sub btntotal_click(sender object, e eventargs) handles btntotal.click     if rthin.checked = true         createpizza.crust = 1     elseif rpan.checked = true         createpizza.crust = 2     elseif rstuff.checked = true         createpizza.crust = 3     end if      if rsm.checked = true         createpizza.size = 1     elseif rmm.checked = true         createpizza.size = 2     elseif rlg.checked = true         createpizza.size = 3     end if      lbltotal.text = "total: " + createpizza.piztotal.tostring()    end sub end class 

class "createpizza"

public class createpizza  public shared size double public shared crust double  public shared property pizzacrust double             return crust     end     set(byval crustpr double)         if crust = 1             crustpr = 1         elseif crust = 2             crustpr = 1.5         elseif crust = 3             crustpr = 3         end if         crust = crustpr     end set end property  public shared property pizzasize double             return size     end     set(byval sizepr double)         if size = 1             sizepr = 10.0         elseif size = 2             sizepr = 12.5         elseif size = 3             sizepr = 15         end if         size = sizepr     end set end property  public shared function piztotal() decimal     return pizzacrust + pizzasize end function  end class 

your piztotal function returning size + crust because pizzasize , pizzacrust properties return value of size , crust respectively. can see code have calculate costs in property settings never call setters pizzasize , pizzacrust cost never calculated.

your pizzasize , pizzacrust properties don't make whole lot of sense. example crust property setting takes input price, if crust 1, 2, or 3 resets price, , stores price in crust variable. if wrote following logic:

dim p new createpizza p.crust = 2 p.pizzacrust = 12345678 dim price1 double = p.pizzacrust p.pizzacrust = 12345678 dim price2 double = p.pizzacrust 

at price1 1.5 , price2 12345678 because pizzacrust both uses value of crust , modifies crust. using crust variable both crust type , crust price , not distinguishing between them. should store crust type in 1 variable , cust cost in different variable (or better write function returns curst cost based on crust type of 1,2, or 3).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -