Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 23, 2017 6:51 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: inserting row on last row
PostPosted: Tue Apr 16, 2013 1:32 am 
Offline

Joined: Tue Aug 29, 2006 4:04 am
Posts: 513
Location: Indonesia
Hi,

I want to add new row on last row in a listbox.

Listbox1.cell(Listbox1.LastIndex1,0)="Total"

this code is working, but its replacing the last row. What I need is just add new row on lastindex without replacing last row.
any helps.?


thanks

regards,
Rivo


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Tue Apr 16, 2013 2:33 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
Does this help?

ListBox1.AddRow "Col0"
ListBox1.Cell(ListBox1.LastIndex, 1) = "Col1"

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Tue Apr 16, 2013 3:42 am 
Offline

Joined: Tue Aug 29, 2006 4:04 am
Posts: 513
Location: Indonesia
Actually I want to add total on the last row every time the button was executed.
dim row as integer
dim dz as string
dim total as double
for row= 0 to ListBox1.ListCount-1
total = total + CDbl(ListBox1.Cell(row,5))
next
sDiskon.text=Format(total, "-###,##0")

if Listbox1.cell(Listbox1.LastIndex,0)<>"Total" then
ListBox1.AddRow "Total"
end if


this is work, but when I need to add new row, the Total should be removed and move to the lastindex again.

thanks
Rivo


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Tue Apr 16, 2013 4:22 am 
Offline

Joined: Wed Feb 27, 2013 6:40 am
Posts: 6
Inserting a row ....

Why not simply

Listbox1.InsertRow(Listbox1.LastIndex-1,"")


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Tue Apr 16, 2013 4:55 am 
Offline

Joined: Tue Aug 29, 2006 4:04 am
Posts: 513
Location: Indonesia
Inserting row does not work.

the result should be displayed like


1 apple 10000
2 orange 20000
1 apple 10000
Total < this should printed on last row everytime the button is executed to add new row.


thanks

Regards,
Rivo


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Tue Apr 16, 2013 5:37 am 
Offline

Joined: Wed Feb 27, 2013 6:40 am
Posts: 6
Supposed you have a list with 3 columns and 3 rows like

Listbox1.ColumnCount = 3
Listbox1.AddRow "1", "Apple","10000"
Listbox1.AddRow "2", "Orange","20000"
Listbox1.AddRow "#", "Total","30000"


In the Action-Event of the AddRow-Button:

dim i, x as Integer
dim sum As Double

x = Listbox1.ListCount // = 3
Listbox1.InsertRow(x-1,"3")

x = Listbox1.ListCount // now 4
Listbox1.Cell(x-2,1) = "Banana"
Listbox1.Cell(x-2,2) = "15000"

for i = 1 to x-1 // sum rows 1,2,3
sum = sum + CDbl(Listbox1.Cell(i-1,2))
next
Listbox1.Cell(x-1,2) = Str(sum) // put the sum in the Total-row 4


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Thu Apr 18, 2013 1:37 am 
Offline

Joined: Tue Aug 29, 2006 4:04 am
Posts: 513
Location: Indonesia
Yes,
This is worked nicely.
but what I need is, the same result with the different way.
I wanted to be like this code, but I cant use insert row method, Because I have written all code with add row method. Made some changes on it will take much more time for me.

Anyway, thanks for the helps.


Regards,
Rivo


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Thu Apr 18, 2013 3:29 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Quote:
I cant use insert row method, Because I have written all code with add row method.


Hmmm.
It is a useful programming and gambling skill to know when to hold, and know when to fold.

Anyway, if you must follow your current code, try this:

Your add button does this?:

//add a row
Mylist.addrow "Something"
//set some cells
Mylist.Cell(Mylist.lastindex,5) = 5000


Try this:

//add a row
Mylist.addrow "Something"
//set some cells
Mylist.Cell(Mylist.lastindex,5) = 5000

dim nLastindex as integer
dim nPreviousRow as integer
dim x as integer
dim nTotal as integer
//record the row numbers

nLastindex =Mylist.lastindex
nPreviousRow =nLastindex -1

//now move what you added up by one row, because it was a total
//(Im assuming you always have a total row as the last row..
//..if not, make sure you have one before this step)

for x = 0 to 5
Mylist.Cell(nPreviousRow,x) = Mylist.Cell(nLastindex ,x)
next

//now recalculate the total
for x = 0 to nPreviousRow
nTotal = nTotal + val(Mylist.Cell(x,5))
next

//finally, update the last row with the total
Mylist.Cell(nLastindex ,0) = "Total"
Mylist.Cell(nLastindex ,1) = str(nTotal)
Mylist.Cell(nLastindex ,2) = ""
Mylist.Cell(nLastindex ,3) = ""
Mylist.Cell(nLastindex ,4) = ""
Mylist.Cell(nLastindex ,5) = ""


Top
 Profile  
Reply with quote  
 Post subject: Re: inserting row on last row
PostPosted: Thu Apr 18, 2013 10:49 pm 
Offline

Joined: Tue Aug 29, 2006 4:04 am
Posts: 513
Location: Indonesia
Cool..!

The same result ina different way.
Thanks alot Lavalle and kermit.
Its really save my time..


Regards,
Rivo


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group