?
Solved

round is not working for Cstr in VBS

Posted on 2014-11-26
3
Medium Priority
?
291 Views
Last Modified: 2014-11-26
Hi;

Following vbs snippet is not working which I want to round a file size:

 strWrite.WriteLine(oF.Name + "," + CStr(Round(oF.Size/1048576),2) + "," + CStr(oF.Files.Count) + "," + CStr(oF.Subfolders.Count))

Open in new window


whereas this is working which is not rounded:

 strWrite.WriteLine(oF.Name + "," + CStr(oF.Size/1048576) + "," + CStr(oF.Files.Count) + "," + CStr(oF.Subfolders.Count))

Open in new window


And I want to round the value. What to do?

Regards.
0
Comment
Question by:jazzIIIlove
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40466796
Try this:
 strWrite.WriteLine(oF.Name & "," & CStr(Round(oF.Size/1048576),2) & "," & CStr(oF.Files.Count) & "," & CStr(oF.Subfolders.Count))

Open in new window

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40466825
I also like using & instead of + in VB languages. But in this case possibly more important is to make the 2 an argument of Round instead of CStr:
 strWrite.WriteLine(oF.Name & "," & CStr(Round(oF.Size/1048576,2)) & "," & CStr(oF.Files.Count) & "," & CStr(oF.Subfolders.Count))

Open in new window

0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40466844
First one failed, second one worked
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question