Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Shorthand to Create an Array of Integers n1-n2

Consider the following intuitive VBA command, which selects the first 10 slides of a PPT presentation:

ActivePresentation.Slides.Range(Array(1,2,3,4,5,6,7,8,9,10)).Select

I would like to express this in more succinct form. For example

-- psuedo-code
ActivePresentation.Slides.Range(CreateRange(1,10)).Select

How can you do this with the VBA available in Powerponit?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No such build-in function in VBA, but it’s quite simple to create your own:

Function createRange(fromVal As Long, toVal As Long) As Long()
    ReDim a(fromVal To toVal) As Long
    Dim i As Long
    For i = fromVal To toVal: a(i) = i: Next
    createRange = a
End Function

… and voilà, your pseudo-code is no longer a pseudo-code

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading