Announcement

Collapse
No announcement yet.

Variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variables

    I am having trouble accessing a variable from one subroutine
    to another. It looks like this:

    Dim m as shared integer

    Time:
    t=t+1
    m=t
    return

    Print:
    locate 10,20
    print m"Minutes."

    However all it prints is a zero. I have also tried setting m
    to 100 and it still prints zero. What am I doing wrong?

  • #2
    Your code is not very clear but, you should also declare the variable t like shared.



    ------------------
    Gustavo Asplanatti
    [email protected]
    Gustavo Asplanatti
    gustavoa at computecsrl.com.ar

    Comment


    • #3
      Originally posted by j musielewicz:

      Dim m as shared integer

      Time:
      t=t+1
      m=t
      return

      Print:
      locate 10,20
      print m"Minutes."

      First, I'm not sure but you don't need to SHARE a variable in
      a sub-routine with RETURN. If it was a SUB or FUNCTION you would
      need to share. Try deleting the 1st line.

      Second, try this:

      Print:
      gosub time ' < == You need to access the sub-routine.
      locate 10,20
      print;m;"Minutes"

      Be sure to separate m and minutes.

      One other thing caught my eye. TIME may be a reserved word. Try
      replacing TIME with CalcTime or something along that line.

      Hope this helps.
      Cheers


      ------------------


      [This message has been edited by Mel Bishop (edited May 10, 2002).]
      There are no atheists in a fox hole or the morning of a math test.
      If my flag offends you, I'll help you pack.

      Comment


      • #4
        Originally posted by Mel Bishop:
        First, I'm not sure but you don't need to SHARE a variable in
        a sub-routine with RETURN. If it was a SUB or FUNCTION you would
        need to share. Try deleting the 1st line.

        Second, try this:

        Print:
        gosub time ' < == You need to access the sub-routine.
        locate 10,20
        print;m;"Minutes"

        Be sure to separate m and minutes.

        One other thing caught my eye. TIME may be a reserved word. Try
        replacing TIME with CalcTime or something along that line.

        Hope this helps.
        Cheers

        Thanks!!! Using a subroutine to access it did it.

        ------------------

        Comment


        • #5
          Not a problem J. Been-there-done-that.

          If you would like to "clean up" your code, try substituting the
          SUB/RETURN with a FUNCTION like the following:

          Function CalcTime(t)
          t = t + 1
          function = t
          end function

          Then in the main body, or other function(s) of your program,
          simply call it with:

          ct = CalcTime(t)
          print;ct;

          or simply

          print;CalcTime(t)


          ------------------




          [This message has been edited by Mel Bishop (edited May 10, 2002).]
          There are no atheists in a fox hole or the morning of a math test.
          If my flag offends you, I'll help you pack.

          Comment

          Working...
          X