October 30, 2025, 05:37:17 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Listview help

Started by Brian, February 11, 2012, 05:08:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Hi,

Run this program, select Get Source File... and load the supplied text file. If you look at the rows, you will see a column
called Broker Code. Each row has either ZK1 or ZK2 there

Now press the Zurich button, and the rows are adjusted to how I want them

My problem is: If there is a row with ZK2, that whole row should be duplicated under the original line, the first line with
ZK2 should be set as "ZK1" and the second, duplicated, line should remain as ZK2

Any help gratefully received

Brian

LarryMc

Your problem is in the logic used in this code:
rowCount=CONTROLCMD(win,6,@LVGETCOUNT)
rc=1
WHILE rc<rowCount
CONTROLCMD win,6,@LVGETTEXT,rc,15,policyID
IF policyID="ZK2"
CONTROLCMD win,6,@LVGETTEXT,rc,0,receiveText
CONTROLCMD win,6,@LVINSERTITEM,rc+1,receiveText
FOR copyRow=1 TO 16
CONTROLCMD win,6,@LVGETTEXT,rc,copyRow,receiveText
CONTROLCMD win,6,@LVSETTEXT,rc+1,copyRow,receiveText
NEXT copyrow
ENDIF
rc++
ENDWHILE

Where to start?
Right off the bat you get the CURRENT number of rows in the list - 6 for this file
In the section where you insert the new row you are increasing the ACTUAL row count by one but you are never increasing the rowCount variable so you need to add a rowCount++ right after the IF policyID="ZK2" statement.

you are missing a rc++ statement.
lets say line 2 in the lv is a ZK2 line
so rc=2
we add a new line @ rc+ 1 which makes it line 3 in the list view
after adding that line you have a rc++ right before the endwhile
rc++ make rc = 3
you go back to the top of the while loop and process line 3 which was just added and is a ZK2 line because you just added it.

With your existing code once you encounter a ZK2 line all remaining lines up to rowcount will be ZK2 lines.
Original lines after the 1st ZK2 are never even examined.

So, in addition to the fix already mentioned you need to add another rc++ just before the ENDIF that is after the NEXT copyrow.

And lastly you stated:
Quotethe first line with
ZK2 should be set as "ZK1"
There's no code to do that.

The following block of code does what I understand you to want.

rowCount=CONTROLCMD(win,6,@LVGETCOUNT)
rc=1
WHILE rc<rowCount
CONTROLCMD win,6,@LVGETTEXT,rc,15,policyID
IF policyID="ZK2"
rowCount
CONTROLCMD win,6,@LVGETTEXT,rc,0,receiveText
CONTROLCMD win,6,@LVINSERTITEM,rc+1,receiveText
FOR copyRow=1 TO 16
CONTROLCMD win,6,@LVGETTEXT,rc,copyRow,receiveText
CONTROLCMD win,6,@LVSETTEXT,rc+1,copyRow,receiveText
NEXT copyrow
CONTROLCMD win,6,@LVSETTEXT,rc,15,"ZK1"
rc++
ENDIF
rc++
ENDWHILE


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Larry,

You never cease to amaze me! Your logical thought processes for problems like these
are far better than mine. Looking at your code, it all fell into place, even to understanding
how to do a slight mod to one of the column's text as it processed the data

The files for "Zurich" are far larger than the sample I provided, and all the juggling around
that the sub does will save us a lot of time, doing in seconds what had become a rather
labour-intensive job for us

Thanks for your help (again),

Brian

LarryMc

Just glad it was something I could help with.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library