Menu

Integer arrays?

Help
2016-05-13
2016-05-13
  • Jim Gregory

    Jim Gregory - 2016-05-13

    It appears that only bytes can be stored in arrays and not integers. Is that correct? The (otherwise excellent) help files don't make that clear.

    If this is the case, do you have any suggestions on how I could store integers in an array-like structure? Thanks,

    -Jim

     
  • Anobium

    Anobium - 2016-05-13

    Second person to ask in a week.

    I just revised the Help! Sorry.

    Integers... relatively easy until we add integer support.

    Create an array twice as big as your integer needs.

    Integer array = 8 elements, dimension a byte array of 16.
    dim myIntarray(16)

    Create a sub that uses the array, addressing two bytes per integer element, where MyIntarray(1) = upperByte of Integer,MyIntarray(2) = lowerByte of Integer. Then, develop the sub to read and write elements.

    Something like:
    MyIntHanderSet( 2, -100 )
    Print MyIntHanderRead(2)

    Sub MyIntHanderSet( in intelement as byte, in intVar as integer )
    [byte]myIntarray(intelement) = intVar_h
    myIntarray(intelement+1) = intVar
    end sub

    Function MyIntHanderRead( in intelement as byte ) as integer
    [byte]MyIntHanderRead_h = myIntarray(intelement)
    MyIntHanderRead = myIntarray(intelement+1)
    end sub

    Not tested - please adapt, correct and publish back here for others, please.

     
  • Jim Gregory

    Jim Gregory - 2016-05-13

    Thanks for the quick reply and your excellent answer.

    Sorry I had to make you answer a second time. I did a quick search in the forum earlier but didn't see it mentioned.

     

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.