Jump to content

Wikipedia:Reference desk/Archives/Computing/2018 December 22

From Wikipedia, the free encyclopedia
Computing desk
< December 21 << Nov | December | Jan >> December 23 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


December 22

[edit]

Array in VBA

[edit]

Hello! I'm learning macro in Excel, but VB's array syntax is difficult for me. Can anyone rewrite the follow Lua code in VBScript?

-- No built-in reverse method in Lua, thus create a function
local tableReverse(tab)
    local tabRev = []
    for i, v in ipairs(tab) do
        table.insert(tabRev, 1, v)
    end
    return tabRev
end

local myArray = ["A1", "A2", "A3", "A4", "B1", "B2"] -- It's annoyed that we have to set a length in VB, count items manually is boring

table.insert(myArray, "B3")  -- VB doesn't have push method, again...

for i = 1 to 5 do -- Push five items
    table.insert(myArray, "C" .. i)
end

for i, v in ipairs(myArray) do -- For Each ... Next in VB?
    print(v)
end

local myArrayReverse = tableReverse(myArray)

for i, v in ipairs(myArrayReverse) do
    print(v)
end

--아리랑&아리랑 (talk) 13:47, 22 December 2018 (UTC)[reply]