Solved

round is not working for Cstr in VBS

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

Independent Software Vendors: 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…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

724 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