Search notes:

VBA: property set and get functions

option explicit

dim someStrings() as string

sub main() ' {
    redim someStrings(0 to 0)

    val(4) = "four"
    val(2) = "two"
    val(1) = "one"
    val(6) = "six"

    dim i as long
    for i = 0 to 10
        debug.print i & ": " & val(i)
    next i

end sub ' }

property let val(byRef item as long, byVal value as string) ' {

    if item > uBound(someStrings) then
       reDim preserve someStrings(0 to item)
    end if

    someStrings(item) = value

end property ' }

property get val(byRef item as long) as string ' {
    if item > uBound(someStrings) then
       val = "n/a"
       exit property
    end if

    val = someStrings(item)
end property ' }
Github repository about-VBA, path: /language/subs-and-functions/property/set-get.bas

See also

Subs and functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759390775, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/language/subs-and-functions/property/index(74): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78