Solved

round is not working for Cstr in VBS

Posted on 2014-11-26
3
270 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

733 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