Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
chris1987
Creator
Creator

For ...next - Exiting after loop - don't know why

Afternoon,

I am trying to get used to creating macros in VBS in QV and I can't seem to figure out why the following is happening. I'm used to working with VBA but can't spot the issue here.

When I click the button to run the macro everything works fine up to the point of the loop. The loop initially works perfectly but then exits the sub, it never reaches the last message box for some reason.

Am I using the For ...next correctly?

Thanks in advance

Chris

Sub Test()

        dim chart,ColumnCount,b,found

        set chart = ActiveDocument.GetSheetObject("CH212")

       

        found = false

        ColumnCount = chart.getcolumncount

       

        if ColumnCount = 1 then

            msgbox "Count is Null"

            exit sub

        end if

       

        msgbox ColumnCount

   

        for b = 0 to ColumnCount

           

            if chart.getfield(b).name = "entity" then

                msgbox "Entity Already exists and is in position: " & b

                found = true

            else

                msgbox "Skipped: Column" & b   <------ I see this

            end if

           

            msgbox "Still going" <------ I also see this

                   

        next

       

        msgbox "Finished Loop and Found flag = " & found <------ I never see this

end sub

2 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Perhaps ColumnCount is 0 or undefined.


talk is cheap, supply exceeds demand
marcus_sommer

Try it with:

...

for b = 0 to ColumnCount - 1

...

- Marcus