Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
vvvvvvizard
Contributor III

vba to populate an array

am trying to populate an array , i can do it manually like this

sitearray=Array(varsplit(1),varsplit(2) ,varsplit(3),varsplit(4) ...........)

and it works

How do i populate the array using a loop statement

i tried

for z=1 to 10

     sitearray=Array(varsplit(z))

Next z

and i get an expected end of statement error

Please assist me with the correct syntax

1 Solution

Accepted Solutions

Re: vba to populate an array

Try:

dim sitearray(), varsplit, vara, arrCount, i

vara= ActiveDocument.Variables("vAlias").getcontent.string

varsplit=Split(vara,",")

arrCount = ubound(varsplit)

redim sitearray(arrCount)

for i = 0 to arrCount - 1

     sitearray(i) = varsplit(i)

next ' without i

But why sitearray if varsplit contained the same?

- Marcus

10 Replies

Re: vba to populate an array

Try something like this:

for z=1 to 10

     sitearray(z) = varsplit(z)

Next z

Understanding VBScript: Arrays | Scripting content from Windows IT Pro

- Marcus

vvvvvvizard
Contributor III

Re: vba to populate an array

even if i try a

dim sitearray

  sitearray(0)=Array('aaaa') or a sitearray(1)=Array('aaaa')   i get a type mismatch error

vba sucks

Re: vba to populate an array

You need to declare sitearray as ARRAY and sometimes to dimension it:

dim sitearray(), z 'another ...

redim sitearray(9) 'started with 0

- Marcus

vvvvvvizard
Contributor III

Re: vba to populate an array

Hi Marcus , i marked your  response as helpful as the url gave me insight into static vs dynamic arrays , i can now populate arrays but not with a loop , for now il  copy and paste 324 time and fill in the numbers to populate the array .

Im certain theres an easier way to do it with a loop , i think my for statement might be the issue now .

Dim sitearray(324)

'Dim z

  sitearray(0)=varsplit(1)

  sitearray(1)=varsplit(2)

  sitearray(2)=varsplit(3)

........................

until sitearray(323)=varsplit(323)

Re: vba to populate an array

How will be varsplit filled - is this an array, too? Maybe you posted a little more from your code.

- Marcus

vvvvvvizard
Contributor III

Re: vba to populate an array

Option Explicit

Dim vara

vara= ActiveDocument.Variables("vAlias").getcontent.string

'Split the variable int its parts

Dim varsplit

varsplit=Split(vara,",")

'Dim sitearray(3)

'Dim z

  'sitearray(0)=varsplit(1)

  'sitearray(1)=varsplit(2)

  'sitearray(2)=varsplit(3)

  'sitearray(3)=varsplit(4)

  'sitearray(3)=varsplit(4)

  'sitearray(3)=varsplit(4)

  'sitearray(3)=varsplit(4)

'Msgbox(sitearray(0))

Sub GenerateBarChart()

i can populate the array this way but not with a for loop statement as stated

vvvvvvizard
Contributor III

Re: vba to populate an array

first time am trying a loop statement in vba

even if i try

For i=1 to 10

msgbox("aaaaaa")

Next i

i get an expected end of statement error on the next i line

vvvvvvizard
Contributor III

Re: vba to populate an array

I figured it out  , its

For z=1 to 10

  statements

next

its just next , not next Z which gives an error , seems that vba used in those excel sites is different from the vba used in  Qlikview ,not sure why .

Re: vba to populate an array

Try:

dim sitearray(), varsplit, vara, arrCount, i

vara= ActiveDocument.Variables("vAlias").getcontent.string

varsplit=Split(vara,",")

arrCount = ubound(varsplit)

redim sitearray(arrCount)

for i = 0 to arrCount - 1

     sitearray(i) = varsplit(i)

next ' without i

But why sitearray if varsplit contained the same?

- Marcus

Community Browser