Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Making a Array a range

This is a discussion on Making a Array a range within the Microsoft .NET forums, part of the Programming Talk category; I am using an the following function in a piece of code MyArr = Array("10","20","30") Yet i would like to ...

  1. #1
    Clubber is offline Junior Member Array
    Join Date
    Aug 2008
    Answers
    1

    Making a Array a range

    I am using an the following function in a piece of code

    MyArr = Array("10","20","30")

    Yet i would like to make the values a range, say 10-100 and all inclusive, but it seems very long winded to type each individual number out. Is it possible to just have a "10 to 100"?

    Thanks


  2. #2
    techvinny is offline Moderator Array
    Join Date
    Dec 2010
    Answers
    57
    It doesn't allow you do so but that's not limiting you to define your function that would return you an array with a range.

    Something like this:
    Code:
    Function InitArray(startValue as Integer, endValue as Integer, incrementBy as integer) as Integer()
        Dim intRange as Integer
        intRange = ((endVal - startVal)/incrementBy) 
        Dim retArr as Integer(intRange)
        Dim currentArrValue as Integer = startValue
    
        For intIndex as Integer = LBound(retArr) to UBound(retArr)
            retArr(intIndex) = currentArrValue
            currentArrValue = currentArrValue + incrementBy
        Next
       
        Return retArr
    End Function
    Haven't tried running the above code, but that should give you an idea...

    HTH!!!


Latest Article

Network Security Risk Assessment and Measurement

Read More...