Solved

How to convert bytes to long...

Posted on 1999-01-18
5
186 Views
Last Modified: 2010-05-03
I think it would be easer to explain what it is I am trying to do rather than just ask a question. I would like to write a program that compresses files and then saves them into a temp. file. This file would contain all the compressed data. I have started to do this as follows:

1)Load the file to be compressed into a byte array
2)compress the byte array with zlib
3)find the origanal and new size of the byte array*
4)get the file name of the compressed file
5)now I start saveing the data into one file
    first I save one byte telling how many bytes are in the compressed files name, next I save that file name. Then I save the origanal and the new size of the byte array as longs(4 bytes each) Then I save save the actual byte array. This is the easy part. (The part I have done) Now I need to read back the file...

First I get the entire file and put it into a byte array. I then use the first byte to tell me how many bytes to read for the file name. Then next 8 bytes(heres the problem) contain the origanal and new(compressed) sizes of the byte array. They are both longs I get these 8 bytes and I don't know how to convert them back into the long long format. To simplafy the problem. Use the put command to put a long number to a file then load that same file into a byte array. This byte array should only be 4 bytes long. I then need to convert those 4 bytes into the origanl long. Wow big... Hope some one can help! Thanks in advance!!!!
0
Comment
Question by:testing38
[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
5 Comments
 
LVL 3

Accepted Solution

by:
idt earned 200 total points
ID: 1469265
Testing38,

The lset function is great for converting datatypes in VB, lets you fill in from the left between two user defined types, in the example I used bytes 1 - 8  for the file sizes, understanding that byte zero was for filename length.

Type a
    'bytes a-d are long int #1
    a As Byte
    b As Byte
    c As Byte
    d As Byte
    'bytes a-d are long int #2
    e As Byte
    f As Byte
    g As Byte
    h As Byte
End Type

Type b
    'for long int #1
    a As Long
    'for long int #2
    b As Long
End Type

Global t1 As a
Global t2 As b

...


t1.a = yourbytearray(1)
t1.b = yourbytearray(2)
t1.c = yourbytearray(3)
t1.d = yourbytearray(4)
t1.e = yourbytearray(5)
t1.f = yourbytearray(6)
t1.g = yourbytearray(7)
t1.h = yourbytearray(8)
LSet t2 = t1
MsgBox Format$(t2.a) + " " + Format$(t2.b)

This is only one method, but quite robust and solves other data conversion problems aswell.

-iDT
0
 
LVL 1

Expert Comment

by:Johnn
ID: 1469266
if you unlock the question i've got a function for you that will make it a piece of cake. (depending on how your building the 4 byte block, if you want I've got a function for that too)

John
0
 

Author Comment

by:testing38
ID: 1469267
idt: good job! I guess it's not the best way of doing this (as I hear) but It does work and that's what counts.  A+ work
Johnn: nice to hear you have a function. Too bad you did not post it... Then I could at least of considered who to give the points to. Now I only have one choice....
0
 
LVL 1

Expert Comment

by:Johnn
ID: 1469268
I couldn't post it until I had a chance to provide an answer/
0
 

Expert Comment

by:paulwelter
ID: 2304830
John, I'll give you points for that funtion.  
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 4 75
VB6 ListBox Question 4 61
RUNRMTCMD from AS/400 13 126
VBA: Insert New column with specific format type 12 56
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

739 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