none
What is an argument? RRS feed

  • Question

  • I hear that term being thrown around a lot and can someone tell me what an argument is? For example i have heard, this argument being passed through something...

    thanks!


    • Edited by FatRat27 Friday, December 13, 2013 7:49 PM
    Friday, December 13, 2013 7:39 PM

Answers

  • An argument is a variable that is passed into a subroutine or function.  There are no arguments in Small Basic subroutines.

    For another language, something like:

    sub function(angle)
    'do something with angle
    endsub

    where angle is an argument.

    x = Sin(theta), theta is an argument of the function Sin.

    see  here

    Many methods in SmallBasic have arguments:

    Shapes.AddEllipse(width, height)
    width and height are arguments to the method AddEllipse
    Friday, December 13, 2013 7:51 PM
    Moderator
  • My take on it:  :D

    Argument is the value that is passed to a function's parameter variable.

    Arguments can be literal values like -3 & 2.5. Or variables like num & list[3] or constants like Math.Pi.

    They can also be the result of an expression like `num/2` or `3*Math.Pi`.

    TextWindow.WriteLine(  Math.SquareRoot(2) )  ' Argument: `literal 2`
    
    num = 3
    TextWindow.WriteLine(  Math.SquareRoot(num) )  ' Argument: variable `num`
    
    TextWindow.WriteLine(  Math.SquareRoot(num+2) )  ' Argument: expression `num+2`

    At the example above, we see that both TextWindow.Writer() & Math.Square() are functions which demand 1 parameter.

    2, num & num + 2 are the arguments passed to an internal variable inside Math.Square() that we call parameter.

    Afterwards, Math.SquareRoot() returns the resultant value, which in turn is used as argument for the TextWindow.WriteLine()'s parameter!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Saturday, December 14, 2013 3:03 AM
    Answerer
  • There is another argument.  In command prompt, you can give arguments to your program.

    This is a sample code:

    ' pgm1.sb
    n = Program.ArgumentCount
    For i = 1 To n
      TextWindow.Write("argument " + i + " = ")
      TextWindow.WriteLine(Program.GetArgument(i))
    EndFor
    

    In command prompt:

    C:\Users\user> pgm1 arg1 arg2

    The result:

    argument 1 = arg1
    argument 2 = arg2
    Press any key to continue...


    Nonki Takahashi

    Monday, December 23, 2013 8:42 AM
    Moderator

All replies

  • An argument is a variable that is passed into a subroutine or function.  There are no arguments in Small Basic subroutines.

    For another language, something like:

    sub function(angle)
    'do something with angle
    endsub

    where angle is an argument.

    x = Sin(theta), theta is an argument of the function Sin.

    see  here

    Many methods in SmallBasic have arguments:

    Shapes.AddEllipse(width, height)
    width and height are arguments to the method AddEllipse
    Friday, December 13, 2013 7:51 PM
    Moderator
  • I can see why this is a bit confusing.

    var1 = "hello"

    var2 = "world"

    e.g. TextWindow.write(var1 , var2)

    Small Basic returns an error message like: TextW is supplied 2 arguments, but takes 1.

    But to the programmer var1 and var2 are variables not arguments.

    They must become arguments when they are supplied internally to the Function/routine that can receive them.

    Interesting.

    Friday, December 13, 2013 8:48 PM
    Moderator
  • Sorry to drop in on your thread fatrat, I'm pretty keen to understand this stuff too.

    So in the above sample, we supply the variable or string and Small basic is supplied/takes the info internally as an argument.

    Yeah?

    Friday, December 13, 2013 9:20 PM
    Moderator
  • Sorry to drop in on your thread fatrat, I'm pretty keen to understand this stuff too.

    So in the above sample, we supply the variable or string and Small basic is supplied/takes the info internally as an argument.

    Yeah?

    so an argument is just a variable or value that is assigned to something? is that correct?

    so

    a = 100

    a right now is just a variable right?

    GraphicsWindow.Height =  a

    Now a is an argument? Im still not 100%

    thanks for being patient

    • Edited by FatRat27 Friday, December 13, 2013 10:09 PM
    Friday, December 13, 2013 10:04 PM
  • a variable that is passed to a function or subroutine or method to be used within the function/sub/method like in examples above.
    Friday, December 13, 2013 10:11 PM
    Moderator
  • An analogy:

    Assume a programmer is baker, SB ide is the oven and the compiler is the cooling rack.

    The baker puts 2 balls of doe (variables) in the oven, the oven bakes them then supplies them to the cooling rack, but the rack only handle 1 loaf at a time. And if you try to give it 2, then it rejects both of them until it gets what it can handle.

    The definitions can be / become a bit abstract at times.

    We input into a SB editor (the ide) then when we run the code it is baked and supplied to a compiler.


    Friday, December 13, 2013 11:38 PM
    Moderator
  • So programmers write variables, the ide bakes the variables when you run the code, then gives them as arguments to the compiler. It's the compiler that gets the arguments not the ide. The compiler can't compile 2 arguments in this case so it returns an error message to the ide.

    Friday, December 13, 2013 11:54 PM
    Moderator
  • This is a Good question fatrat.

    I like to know exactly what stuff means. Then I read further material, that's in a different context, but I don't know that at the time, and it uses it differently and I get confused.

    litdev just resolved something for me that I used to know (event handlers) then I read up on EDP and it used the term in a different context and I was up in the air again. Whilst reading up got me confused a bit it ultimately led to deeper understanding of the term and some experience of how it's used.

    Saturday, December 14, 2013 12:09 AM
    Moderator
  • My take on it:  :D

    Argument is the value that is passed to a function's parameter variable.

    Arguments can be literal values like -3 & 2.5. Or variables like num & list[3] or constants like Math.Pi.

    They can also be the result of an expression like `num/2` or `3*Math.Pi`.

    TextWindow.WriteLine(  Math.SquareRoot(2) )  ' Argument: `literal 2`
    
    num = 3
    TextWindow.WriteLine(  Math.SquareRoot(num) )  ' Argument: variable `num`
    
    TextWindow.WriteLine(  Math.SquareRoot(num+2) )  ' Argument: expression `num+2`

    At the example above, we see that both TextWindow.Writer() & Math.Square() are functions which demand 1 parameter.

    2, num & num + 2 are the arguments passed to an internal variable inside Math.Square() that we call parameter.

    Afterwards, Math.SquareRoot() returns the resultant value, which in turn is used as argument for the TextWindow.WriteLine()'s parameter!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Saturday, December 14, 2013 3:03 AM
    Answerer
  • Cool, thanks everyone for your help! not just on this post either,, but on all of mine. expect many more to come! haha
    Saturday, December 14, 2013 3:30 AM
  • Here's a good article

    Small Basic: Grammar Basics

    Saturday, December 14, 2013 5:22 AM
    Moderator
  • There is another argument.  In command prompt, you can give arguments to your program.

    This is a sample code:

    ' pgm1.sb
    n = Program.ArgumentCount
    For i = 1 To n
      TextWindow.Write("argument " + i + " = ")
      TextWindow.WriteLine(Program.GetArgument(i))
    EndFor
    

    In command prompt:

    C:\Users\user> pgm1 arg1 arg2

    The result:

    argument 1 = arg1
    argument 2 = arg2
    Press any key to continue...


    Nonki Takahashi

    Monday, December 23, 2013 8:42 AM
    Moderator