Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: addition in vbscript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,56485
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: addition in vbscript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: addition in vbscript - 2/11/2008 4:04:09 AM   
  Camus

 

Posts: 12
Score: 0
Joined: 2/8/2008
Status: offline
Ill try that now...in response to your question though, i've retested that bit of code, and it doesn't add everything up a second time as i suggested. Instead it adds every line up correctly and it eventually reaches the correct total at somewhere around row 22, it then adds 0.60 to every remaining empty row up to row 50.

You have to specify within the program what the maximum row count will be (that what the 'For n = 1 To Amount.LineCount ' line refers to). I have it set to 50. It's a similar thing to the used row count in excel, even though excel recognises all the way down to row 60,000 or whatever.




EDIT - by the way, when i run that code you gave me in the previous post, i get the message "Type Mismatch ll"

< Message edited by Camus -- 2/11/2008 4:07:25 AM >

(in reply to ehvbs)
 
 
Post #: 21
 
 RE: addition in vbscript - 2/11/2008 4:21:41 AM  1 votes
  ehvbs

 

Posts: 2063
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Ok, the problem is caused by the empty trailing lines returning "". Let's try this:

dblSum = 0.0
For n = 1 To Amount.LineCount
   sTmp = Trim( Amount.Line(n) )
   If IsNumeric( sTmp ) Then
On Error Resume Next
       dblTmp = CDbl(sTmp)
      If 0 <> Err.Number Then
           MsgBox Err.Description & " |" & sTmp & "|"
           dblTmp = 0.0
      End If
On Error GoTo 0
      dblSum = dblSum + dblTmp
   End If
Next
MsgBox dblSum

(in reply to Camus)
 
 
Post #: 22
 
 RE: addition in vbscript - 2/11/2008 5:48:18 AM   
  Camus

 

Posts: 12
Score: 0
Joined: 2/8/2008
Status: offline
works perfectly, thats something ive been trying to do for a while...thanks for your help!

one question though, the number is outputting in the format "12.9", is there a way i can format it in the code to make it output as "12.90"?

(in reply to ehvbs)
 
 
Post #: 23
 
 RE: addition in vbscript - 2/11/2008 5:57:45 AM   
  ehvbs

 

Posts: 2063
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Camus,

you are welcome. I'm glad you solved the problem! Thank you for the interesting
problem and your patience/perseverance.

As to the "12.9" => "12.90" problem: see the FormatNumber function in the
VBScript Docs.

Regards

ehvbs

(in reply to Camus)
 
 
Post #: 24
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: addition in vbscript Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts