New topic: 

how to use replaceall function

<http://forums.realsoftware.com/viewtopic.php?t=30471>

       Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic         Author  
Message       Rivo           Post subject: how to use replaceall 
functionPosted: Tue Oct 13, 2009 10:36 pm                               
Joined: Tue Aug 29, 2006 4:04 am
Posts: 254
Location: Indonesia              I'm tried to calculate the value in a column 
of listbox.
The result is showing me the first digit before comma, therefore, I want to 
replace the comma by using replaceall

Code:dim row as integer
dim dz as string
dim total as double
for row= 0 to ListBox1.ListCount-1
  total = total + str(val(ReplaceAll((ListBox1.Cell(row, 11),",","")))
next
sTotalRevenue.text="Total Revenue : "+str(dz)


That code still show me an error, I have tested into single editfield its 
running but not in multi item in a listbox.

Note : all value in cell 11 is using format Method "###,##0")

any help.?

thanks
Regards,

Rivo   
                            Top               dglass           Post subject: 
Re: how to use replaceall functionPosted: Tue Oct 13, 2009 10:53 pm             
           
Joined: Fri Sep 30, 2005 9:29 am
Posts: 607
Location: California              You are adding each row to the variable 
'total', but you are putting the variable 'dz' (which isn't used in the code 
you provided) into your total revenue field.

And you are converting a string (the cell contents) to a double with val() then 
converting it back to a string with str() so you can add it to a double 
(total)???   
                            Top               Rivo           Post subject: Re: 
how to use replaceall functionPosted: Wed Oct 14, 2009 2:28 am                  
             
Joined: Tue Aug 29, 2006 4:04 am
Posts: 254
Location: Indonesia              sorry it was my mistake,
Quote:You are adding each row to the variable 'total', but you are putting the 
variable 'dz' (which isn't used in the code you provided) into your total 
revenue field.

Code:dim row as integer
dim dz as string
dim total as double
for row= 0 to ListBox1.ListCount-1
  total = total + str(val(ReplaceAll((ListBox1.Cell(row, 11),",","")))
next
sTotalRevenue.text="Total Revenue : "+str(total)


but an error shows in this line below,
Code:total = total + str(val(ReplaceAll((ListBox1.Cell(row, 11),",","")))

regards,
Rivo   
                            Top               thommcgrath           Post 
subject: Re: how to use replaceall functionPosted: Wed Oct 14, 2009 2:52 am     
                 Site Admin                
Joined: Tue May 06, 2008 1:07 pm
Posts: 292
Location: Greater Hartford Area, CT              The problem I see is that 
you're trying to add a string to a double. Try adding the CDbl value of the 
cell and see where that gets you:

Code:total = total + cdbl(listbox1.cell(row,1))     
_________________
--
Thom McGrath
IT Developer, REAL Software  
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to