Menu

problem parsing array to function

Help
Santiago
2015-09-24
2015-09-24
  • Santiago

    Santiago - 2015-09-24

    Hello.
    There is something weird here, compiling this code:

    :::basic
    #chip mega328p, 16
    
    Dim input( 10 )
    Dim sum_input as byte
    
    for num=1 to 10
        input( num ) = num
    next
    
    sum_input = SumInputs( input() )
    
    
    Function SumInputs( inp() )
        SumInputs = 0
        for num=1 to num_inputs
            SumInputs += inp(num)
        next
    End Function
    

    I get an array not declared error:

    Great Cow BASIC (0.94 2015-08-05)
    Compiling kk.gcb ...
    An error has been found:
    kk.gcb (16): Error: Array/Function INP has not been declared
    The message has been logged to the file Errors.txt.

    But this way it works ok:

    :::basic
    #chip mega328p, 16
    
    Dim input( 10 )
    Dim sum_input as byte
    
    for num=1 to 10
        input( num ) = num
    next
    
    sum_input = SumInputs( input() )
    
    
    Function SumInputs( inp() )
        tempbyte = 0
        for num=1 to num_inputs
            tempbyte += inp(num)
        next
        SumInputs = tempbyte
    End Function
    

    What am i doing wrong in the first case?

    Thank you in advance.

    ......
    Edited:
    Just playing with text formatting

     

    Last edit: Santiago 2015-09-24
  • Anobium

    Anobium - 2015-09-24

    What version of Great Cow Basic are you using?

    And, can you post your code as attachment\zip?

     
  • Santiago

    Santiago - 2015-09-24

    Hi Anobium.

    I'm using GCB 0.94 at linut Lubuntu 15.04

    Attached the code not working for me: kk.gcb

    Sorry for the big bold line in the last post.. i don't know how i did...

     
  • Anobium

    Anobium - 2015-09-24

    Try,

    Function SumInputs( in inpx() as byte )
    

    inp is reserved. Use inpx.

     
  • Anobium

    Anobium - 2015-09-24

    Please make sure you define your function to respond as you expect. You want to return a word or long.

    Function SumInputs( in inpx() as byte ) as long
    
     
  • Santiago

    Santiago - 2015-09-24

    Yes, with inpx i
    t works perfectly.
    And yes... forgot to declare the return type.

    Thank you very much.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.