This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C52707.3F3947A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

How to I format the output of a number in VBS, eg:

if the output is 1794, I want it to be 1790
if the output is 1795, I want it to be 1800

I was looking at FormatNumber and Round function, but neither seem to do =
what I want.

Here is the script to query CPU speed:

Set objWMIService =3D GetObject("winmgmts:" & =
"{impersonationLevel=3Dimpersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessors =3D objWMIService.ExecQuery("SELECT * FROM =
Win32_Processor", "WQL", _
wbemFlagReturnImmediately + =
wbemFlagForwardOnly)
For Each objProcessor In colProcessors
strProcessorName =3D objProcessor.Name
strCurrentClockSpeed =3D objProcessor.CurrentClockSpeed
Next

Wscript.Echo "CPU speed: " & strCurrentClockSpeed & "Mhz"


Thanks
Frank


------=_NextPart_000_0026_01C52707.3F3947A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1491" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>How to I format the output of a number =
in VBS,=20
eg:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>if the output is 1794, I want it to be=20
1790</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if the output is 1795, I want it to be=20
1800</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>I was looking at FormatNumber and Round function, but neither seem =
to do=20
what I want.</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is the script to query CPU =
speed:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;Set objWMIService =3D =
GetObject("winmgmts:"=20
&amp; "{impersonationLevel=3Dimpersonate}!\\" _<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&amp; strComputer &amp; "\root\cimv2")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;Set colProcessors =3D=20
objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL",=20
_<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
wbemFlagReturnImmediately + wbemFlagForwardOnly)<BR>&nbsp;For Each =
objProcessor=20
In colProcessors<BR>&nbsp;&nbsp;&nbsp; &nbsp;strProcessorName =3D=20
objProcessor.Name<BR>&nbsp;&nbsp;&nbsp; &nbsp;strCurrentClockSpeed =3D=20
objProcessor.CurrentClockSpeed<BR>&nbsp;Next<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;Wscript.Echo "CPU speed: " &amp;=20
strCurrentClockSpeed &amp; "Mhz"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Frank</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV></FONT></BODY></HTML>

------=_NextPart_000_0026_01C52707.3F3947A0--

Re: round a number in vbs by Brian

Brian
Sat Mar 12 00:01:31 CST 2005

Frank wrote:
> Hi,
>
> How to I format the output of a number in VBS, eg:
>
> if the output is 1794, I want it to be 1790
> if the output is 1795, I want it to be 1800
>
> I was looking at FormatNumber and Round function, but neither seem to do
> what I want.

Divide number by 10, cast as an integer, multiply by 10.

Re: round a number in vbs by de

de
Sat Mar 12 09:19:17 CST 2005

Divide by 10, add 0.5, cast as integer, then multiply by 10.



Re: round a number in vbs by Dr

Dr
Sun Mar 13 12:30:21 CST 2005

JRS: In article <O0$zvjsJFHA.2956@TK2MSFTNGP12.phx.gbl>, dated Sat, 12
Mar 2005 01:01:31, seen in news:microsoft.public.scripting.vbscript,
Brian Wolven <brian.wolven@domain.invalid> posted :
>Frank wrote:

>> How to I format the output of a number in VBS, eg:
>>
>> if the output is 1794, I want it to be 1790
>> if the output is 1795, I want it to be 1800
>>
>> I was looking at FormatNumber and Round function, but neither seem to do
>> what I want.
>
>Divide number by 10, cast as an integer, multiply by 10.

The term "cast" is generally used to mean taking a bit pattern which
would otherwise be considered as being one type of variable and treating
it as another type, no run-time instructions being needed. One may cast
between signed and unsigned 16-bit quantities, for example, or between
those and an array of two bytes or of two characters.


In this case a conversion function is required, one which converts the
actual bit pattern to another bit pattern.

Ans = 10 * Round(Input/10)

satisfies the examples. Int does not; CInt does.


But, in general and in this case, examples are inadequate, and a
complete description is needed. It may be that the input will never be
negative; but it seems likely that it may be 1785 or 1805. Both of
those will be rounded down, not up like 1795.

In rounding, one must always consider whether Bankers' Rounding, i.e. to
nearest even for the half-way case, will be wanted or not; in technical
work, it is frequently not wanted.

If rounding is always to be towards plus infinity, then consider
Q = Input mod 10 : Ans = Input - Q : if Q>=5 then Ans = Ans+10
but there may well be some better way.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.