Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Convert Bytes to Gigabytes

Reply
 
Old 07-27-2009   #1 (permalink)
SkySte


 
 

Convert Bytes to Gigabytes

Hi, I have a VBscript which I want to read data from an XML file
produced by a backup application and post it into an excel spreedsheet
for reference. At the moment we just write down the value and type it
in, I want to automate this. I've got the script to pretty much work
appart from the values it gets are in bytes and thus not really very
meaninful.

Then script reads the bytes from the XML file and then I tried to
convert it to a double but it didn't like it because of the very large
number. As such is there a way that I can convert the string to
gigabytes before I made it into a double or int? This is driving me
insane as I can't find anything useful anywhere online Any help/
advice would be appreciated. All I need is a way to convert the bytes
I have read to Gigabytes to be added to an excel spreedsheet.

Thanks
Steve

My System SpecsSystem Spec
Old 07-27-2009   #2 (permalink)
Tom Lavedas


 
 

Re: Convert Bytes to Gigabytes

On Jul 27, 6:55*am, SkySte <ste.is....@xxxxxx> wrote:
Quote:

> Hi, I have a VBscript which I want to read data from an XML file
> produced by a backup application and post it into an excel spreedsheet
> for reference. At the moment we just write down the value and type it
> in, I want to automate this. I've got the script to pretty much work
> appart from the values it gets are in bytes and thus not really very
> meaninful.
>
> Then script reads the bytes from the XML file and then I tried to
> convert it to a double but it didn't like it because of the very large
> number. As such is there a way that I can convert the string to
> gigabytes before I made it into a double or int? This is driving me
> insane as I can't find anything useful anywhere online Any help/
> advice would be appreciated. All I need is a way to convert the bytes
> I have read to Gigabytes to be added to an excel spreedsheet.
>
> Thanks
> Steve
Have you tried soemthing like this? ...

gbytes = Round(bytes / 1024^3, 3)

Tom Lavedas
***********
My System SpecsSystem Spec
Old 07-27-2009   #3 (permalink)
Pegasus [MVP]


 
 

Re: Convert Bytes to Gigabytes


"SkySte" <ste.is.gr8@xxxxxx> wrote in message
news:bed01341-9ff4-4a30-8101-ec1f7838ba55@xxxxxx
Quote:

> Hi, I have a VBscript which I want to read data from an XML file
> produced by a backup application and post it into an excel spreedsheet
> for reference. At the moment we just write down the value and type it
> in, I want to automate this. I've got the script to pretty much work
> appart from the values it gets are in bytes and thus not really very
> meaninful.
>
> Then script reads the bytes from the XML file and then I tried to
> convert it to a double but it didn't like it because of the very large
> number. As such is there a way that I can convert the string to
> gigabytes before I made it into a double or int? This is driving me
> insane as I can't find anything useful anywhere online Any help/
> advice would be appreciated. All I need is a way to convert the bytes
> I have read to Gigabytes to be added to an excel spreedsheet.
>
> Thanks
> Steve
You could lop off the three right-most characters in order to convert Bytes
to kBytes:
sCapacity = "1234567890"
if len(sCapacity) > 3 then skBytes = Left(sCapacity, Len(sCapacity) - 3)
if skBytes= "" then skBytes = 0


My System SpecsSystem Spec
Old 07-27-2009   #4 (permalink)
Tom Lavedas


 
 

Re: Convert Bytes to Gigabytes

On Jul 27, 8:18*am, "Pegasus [MVP]" <n...@xxxxxx> wrote:
Quote:

> "SkySte" <ste.is....@xxxxxx> wrote in message
>
> news:bed01341-9ff4-4a30-8101-ec1f7838ba55@xxxxxx
>
>
>
Quote:

> > Hi, I have a VBscript which I want to read data from an XML file
> > produced by a backup application and post it into an excel spreedsheet
> > for reference. At the moment we just write down the value and type it
> > in, I want to automate this. I've got the script to pretty much work
> > appart from the values it gets are in bytes and thus not really very
> > meaninful.
>
Quote:

> > Then script reads the bytes from the XML file and then I tried to
> > convert it to a double but it didn't like it because of the very large
> > number. As such is there a way that I can convert the string to
> > gigabytes before I made it into a double or int? This is driving me
> > insane as I can't find anything useful anywhere online Any help/
> > advice would be appreciated. All I need is a way to convert the bytes
> > I have read to Gigabytes to be added to an excel spreedsheet.
>
Quote:

> > Thanks
> > Steve
>
> You could lop off the three right-most characters in order to convert Bytes
> to kBytes:
> sCapacity = "1234567890"
> if len(sCapacity) > 3 then skBytes = Left(sCapacity, Len(sCapacity) - 3)
> if skBytes= "" then skBytes = 0
That's not the way it works, since bytes are the actual count and
GigaBytes are a count of 1024^3 byte blocks (2^30 bytes). You can see
the effect of this distinction if you look at the Properties of a
drive and note the difference between the bytes and GB properties for
any of the capacity parameters listed in the dialog.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
My System SpecsSystem Spec
Old 07-27-2009   #5 (permalink)


Vista home premium 32bit
 
 

Re: Convert Bytes to Gigabytes

Quote  Quote: Originally Posted by Pegasus [MVP] View Post
"SkySte" <ste.is.gr8@xxxxxx> wrote in message
news:bed01341-9ff4-4a30-8101-ec1f7838ba55@xxxxxx
Quote:
> Hi, I have a VBscript which I want to read data from an XML file
> produced by a backup application and post it into an excel spreedsheet
> for reference. At the moment we just write down the value and type it
> in, I want to automate this. I've got the script to pretty much work
> appart from the values it gets are in bytes and thus not really very
> meaninful.
>
> Then script reads the bytes from the XML file and then I tried to
> convert it to a double but it didn't like it because of the very large
> number. As such is there a way that I can convert the string to
> gigabytes before I made it into a double or int? This is driving me
> insane as I can't find anything useful anywhere online Any help/
> advice would be appreciated. All I need is a way to convert the bytes
> I have read to Gigabytes to be added to an excel spreedsheet.
>
> Thanks
> Steve
You could lop off the three right-most characters in order to convert Bytes
to kBytes:
sCapacity = "1234567890"
if len(sCapacity) > 3 then skBytes = Left(sCapacity, Len(sCapacity) - 3)
if skBytes= "" then skBytes = 0

That would produce a 7% larger number.
My System SpecsSystem Spec
Old 07-27-2009   #6 (permalink)
Pegasus [MVP]


 
 

Re: Convert Bytes to Gigabytes


"Tom Lavedas" <tglbatch@xxxxxx> wrote in message
news:1a5b9a4d-e27d-4ab8-8f17-1123e466bb10@xxxxxx
On Jul 27, 8:18 am, "Pegasus [MVP]" <n...@xxxxxx> wrote:
Quote:

> "SkySte" <ste.is....@xxxxxx> wrote in message
>
> news:bed01341-9ff4-4a30-8101-ec1f7838ba55@xxxxxx
>
>
>
Quote:

> > Hi, I have a VBscript which I want to read data from an XML file
> > produced by a backup application and post it into an excel spreedsheet
> > for reference. At the moment we just write down the value and type it
> > in, I want to automate this. I've got the script to pretty much work
> > appart from the values it gets are in bytes and thus not really very
> > meaninful.
>
Quote:

> > Then script reads the bytes from the XML file and then I tried to
> > convert it to a double but it didn't like it because of the very large
> > number. As such is there a way that I can convert the string to
> > gigabytes before I made it into a double or int? This is driving me
> > insane as I can't find anything useful anywhere online Any help/
> > advice would be appreciated. All I need is a way to convert the bytes
> > I have read to Gigabytes to be added to an excel spreedsheet.
>
Quote:

> > Thanks
> > Steve
>
> You could lop off the three right-most characters in order to convert
> Bytes
> to kBytes:
> sCapacity = "1234567890"
> if len(sCapacity) > 3 then skBytes = Left(sCapacity, Len(sCapacity) - 3)
> if skBytes= "" then skBytes = 0
That's not the way it works, since bytes are the actual count and
GigaBytes are a count of 1024^3 byte blocks (2^30 bytes). You can see
the effect of this distinction if you look at the Properties of a
drive and note the difference between the bytes and GB properties for
any of the capacity parameters listed in the dialog.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/

================

I'm quite aware of this difference. If it matters for the OP then it's a
trivial thing to make the appropriate adjustment after lopping off the three
trailing characters. With a little more effort he could even implement a
rounding function.


My System SpecsSystem Spec
Old 07-27-2009   #7 (permalink)
Pegasus [MVP]


 
 

Re: Convert Bytes to Gigabytes


"whs" <guest@xxxxxx-email.com> wrote in message
news:1eeec82dc44b27bcb8fcd8b8fda4fa70@xxxxxx-gateway.com...
Quote:

>
> 'Pegasus [MVP Wrote:
Quote:

>> ;1099857']"SkySte" <ste.is.gr8@xxxxxx> wrote in message
>> news:bed01341-9ff4-4a30-8101-ec1f7838ba55@xxxxxx> > >
Quote:

>> > > Hi, I have a VBscript which I want to read data from an XML file
>> > > produced by a backup application and post it into an excel
>> > spreedsheet
>> > > for reference. At the moment we just write down the value and type it
>> > > in, I want to automate this. I've got the script to pretty much work
>> > > appart from the values it gets are in bytes and thus not really very
>> > > meaninful.
>> > >
>> > > Then script reads the bytes from the XML file and then I tried to
>> > > convert it to a double but it didn't like it because of the very
>> > large
>> > > number. As such is there a way that I can convert the string to
>> > > gigabytes before I made it into a double or int? This is driving me
>> > > insane as I can't find anything useful anywhere online Any help/
>> > > advice would be appreciated. All I need is a way to convert the bytes
>> > > I have read to Gigabytes to be added to an excel spreedsheet.
>> > >
>> > > Thanks
>> > > Steve > >
>>
>> You could lop off the three right-most characters in order to convert
>> Bytes
>> to kBytes:
>> sCapacity = "1234567890"
>> if len(sCapacity) > 3 then skBytes = Left(sCapacity, Len(sCapacity) -
>> 3)
>> if skBytes= "" then skBytes = 0
>
>
> That would produce a 7% larger number.
>
>
> --
> whs
7%? More like 2.4%! And as I said - the cure is trivial, well within reach
of a beginner in VB Script programming.


My System SpecsSystem Spec
Old 07-27-2009   #8 (permalink)


Vista home premium 32bit
 
 

Re: Convert Bytes to Gigabytes

Quote  Quote: Originally Posted by Pegasus [MVP] View Post
"whs" <guest@xxxxxx-email.com> wrote in message
news:1eeec82dc44b27bcb8fcd8b8fda4fa70@xxxxxx-gateway.com...
Quote:
>
> 'Pegasus [MVP Wrote:
Quote:
>> ;1099857']"SkySte" <ste.is.gr8@xxxxxx> wrote in message
>> news:bed01341-9ff4-4a30-8101-ec1f7838ba55@xxxxxx> > >
>>
>> You could lop off the three right-most characters in order to convert
>> Bytes
>> to kBytes:
>> sCapacity = "1234567890"
>> if len(sCapacity) > 3 then skBytes = Left(sCapacity, Len(sCapacity) -
>> 3)
>> if skBytes= "" then skBytes = 0
>
>
> That would produce a 7% larger number.
>
>
> --
> whs
7%? More like 2.4%! And as I said - the cure is trivial, well within reach
of a beginner in VB Script programming.

2.4% for Megabytes and 7% for Giga bytes. Multiply 1024x1024x1024 and see what the result is.
My System SpecsSystem Spec
Old 07-27-2009   #9 (permalink)
Pegasus [MVP]


 
 

Re: Convert Bytes to Gigabytes


"whs" <guest@xxxxxx-email.com> wrote in message
news:5a2bf51e64d770cb0c17cf0c81f26981@xxxxxx-gateway.com...
Quote:

>
> 'Pegasus [MVP Wrote:
Quote:

>> ;1100000']"whs" <guest@xxxxxx-email.com> wrote in message
>> news:1eeec82dc44b27bcb8fcd8b8fda4fa70@xxxxxx-gateway.com...> > >
Quote:

>> > >
>> > > 'Pegasus [MVP Wrote:> > > > >
>> > > >> ;1099857']"SkySte" <ste.is.gr8@xxxxxx> wrote in message
>> > > >> news:bed01341-9ff4-4a30-8101-ec1f7838ba55@xxxxxx> > >
>> > > >>
>> > > >> You could lop off the three right-most characters in order to
>> > > convert
>> > > >> Bytes
>> > > >> to kBytes:
>> > > >> sCapacity = "1234567890"
>> > > >> if len(sCapacity) > 3 then skBytes = Left(sCapacity,
>> > > >> Len(sCapacity)
>> > > -
>> > > >> 3)
>> > > >> if skBytes= "" then skBytes = 0> > > >
>> > >
>> > >
>> > > That would produce a 7% larger number.
>> > >
>> > >
>> > > --
>> > > whs > >
>>
>> 7%? More like 2.4%! And as I said - the cure is trivial, well within
>> reach
>> of a beginner in VB Script programming.
>
>
> 2.4% for Megabytes and 7% for Giga bytes. Multiply 1024x1024x1024 and
> see what the result is.
>
>
> --
> whs
Please do not misquote me. I wrote "You could lop off the three right-most
characters in order to convert Bytes to kBytes". Your figure of 7% (7.37%)
applies to a triple conversion (Bytes to GBytes), which would be ridiculous
because the OP would lose most of the information he is after. A conversion
to kBytes is probably sufficient for his purpose, hence the uncompensated
error is 2.4%.


My System SpecsSystem Spec
Old 07-27-2009   #10 (permalink)
Todd Vargo


 
 

Re: Convert Bytes to Gigabytes

Pegasus [MVP] wrote:
Quote:

> "Tom Lavedas" <tglbatch@xxxxxx> wrote in message
> That's not the way it works, since bytes are the actual count and
> GigaBytes are a count of 1024^3 byte blocks (2^30 bytes). You can see
> the effect of this distinction if you look at the Properties of a
> drive and note the difference between the bytes and GB properties for
> any of the capacity parameters listed in the dialog.
>
> Tom Lavedas
> ***********
> http://there.is.no.more/tglbatch/
>
> ================
>
> I'm quite aware of this difference. If it matters for the OP then
> it's a trivial thing to make the appropriate adjustment after lopping
> off the three trailing characters. With a little more effort he could
> even implement a rounding function.
For some unknown reason, hard drive manufacturers seem to be oblivious to
the correct way to count BYTEs and have been getting away with it for years.
Perhaps they should be required to indicate their unit of measure is
actually characters and not BYTEs.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? .NET General
Does Vista Actually Want 18 Gigabytes Of Disc Space? Vista General
Re: Does Vista Actually Want 18 Gigabytes Of Disc Space? Vista General
Re: Does Vista Actually Want 18 Gigabytes Of Disc Space? Vista General
ISO only 712 bytes? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46