gET AND seT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • knychtell
    New Member
    • Jan 2007
    • 66

    #1

    gET AND seT

    Hi, can somebody help me with this code, i tried to run it with F11 to see the flow but i just cant understand how does it changed.,


    Code:
    Sub main
    try
      dim cls as new mysample class
      dim var1,var2,var3,result as decimal
      dim counter as integer
      var1=convert.todecimal(inputbox("enter a number(0,1 or 2)"))
      for counter=0 to 1
        myarray(counter)=convert.todecimal(inputbox("Enter another number"))
      next
    
      var2=mayarray(0)
      cls.s=myarray(1)
      result=cls.compute(var1,var2)
      msgbox(result)
    catch ex as exceptiopn
      msgbox(ex.msg)
    end try
    end sub
    
    PUblic class mysampleclass
    private x as integer
    property s() as decimal
    get
      return x
    end get
    set(byval value as decimal)
      x=value
    end set 
    end property
    
    
    
    function compute(byval a as decimal, byval b as decimal) as decimal
    
    select case a
    case0
      return(s+b)
    case1
      return (s+b+b)
    case2
      return(s+s+b)
    end select 
    end function
    end class

    q:

    why after doing (byval a as decimal, byval b as decimal) as decimal?
    we type as decimal after we have declare that a and b as deciaml

    why everytime i input 1 firts ,2, , 2= 6
    whats the possible reason thanks....
    Last edited by Killer42; Mar 13 '07, 01:46 AM. Reason: Please use CODE.../CODE tags when posting code.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by knychtell
    ..
    why after doing (byval a as decimal, byval b as decimal) as decimal?
    we type as decimal after we have declare that a and b as deciaml
    a and b are the parameters which are accepted by this function. The As Decimal at the end indicates the value type that the function returns.

    Originally posted by knychtell
    why everytime i input 1 firts ,2, , 2= 6
    whats the possible reason thanks....
    Sorry, didn't understand that question - could you try to be more clear?

    Comment

    • knychtell
      New Member
      • Jan 2007
      • 66

      #3
      [when i run the program
      it will ask me to input a number from the choices either 0,1 or 2

      if i input 1,then i will ask me again to input another number, and i choose 2, it will direct me again to inputbox teling me to input another number, and i chose to input 2

      then i will generate a Result message 6

      the question is, how did it come to result 6,whereas i only input the total of 5
      which are 1,2,2 respectively?

      can you solve it for me pls.. i just cant figure it out... thanks again maa'm

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        If you trace through the code step by step, you will see that what is being executed here is return (s+b+b). This comes to 6 (2+2+2).

        Comment

        • knychtell
          New Member
          • Jan 2007
          • 66

          #5
          Yeah, but how about 1,1,2 then result is 5, thanks again....

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by knychtell
            Yeah, but how about 1,1,2 then result is 5, thanks again....
            Trace the code through, step by step. It's more important for you to understand it than me.

            I think it's critically important, as a programmer, to be able to follow and understand program code. Otherwise how will you ever know what you're writing? Just keep in mind that although a program may look overwhelming when viewed as a whole, the computer is completely dumb and only does one simple thing at a time. You just need to understand the result of each individual statement, to follow the execution.

            Comment

            • knychtell
              New Member
              • Jan 2007
              • 66

              #7
              Ok, thanks, but im not taking up programming, im taking up System engineering. so im quite dumb with this, thanks again maa'm....

              Comment

              Working...