Page 1 of 1

Bsave-Bload II

Posted: Fri Feb 18, 2005 4:27 pm
by Mitth'raw'nuruodo
I have a question, How will the array that you Bload a .gfx file into in your program know how big the array needs to be, do I have to do that manualy, or does it do it itself? Or if manuly can I find out how big it is?

Posted: Fri Feb 18, 2005 4:50 pm
by Rattrapmax6
:shock: You do it manualy,. and you go by when you originaly saved it.. go look at the original BSAVE BLOAD thread, I got a source code you can look over, has REMs that tell whats doing what.. :wink:

Posted: Fri Feb 18, 2005 5:06 pm
by Mitth'raw'nuruodo
*Stare*...*Sniff*...Nooooo!!!!! NOOO!!!!! WHY!!!!! Why must it be like this?!

What if you want to have the amount of crap in your file to be a non-constant that you don't want to keep changing in your prog? Is there a way? Nek do you know? To find how big your array needs to be by getting the size of the .gfx file?

Please somebody let me know! Please this will make my prog from 64KB to about 20KB! Please! I need to know! :cry:

BTW...This is one of my examples that I sacrifice optimization for elasticisty. But if there is a way to get the size of the array, then I can have both in this instance.

Posted: Fri Feb 18, 2005 5:54 pm
by Nodtveidt
It's quite easy: get the size of the file using the LOF function and subtract 7. Then, divide that in half (round fractions up, always) and subtract 1 to get the size of the array in integers, starting from 0.

For example:

You have a file that's 12611 bytes. Subtract 7 (this is for the BSAVE header) and you got 12604. Chop that in half. You got 6302. Subtract 1 from that. You got 6301. Make your array something like this:

Code: Select all

DIM array(6301) AS INTEGER
BLOAD as usual. :D

Posted: Fri Feb 18, 2005 6:13 pm
by Mitth'raw'nuruodo
*Mit bows* Many thanks and many days of happiness to you!

Posted: Fri Feb 18, 2005 6:23 pm
by Mitth'raw'nuruodo
BTW is there a command to round up, I never found one in QB, just Trunkcating: INT().

I always had to do: RoundedVar = INT(Var + .5)

To round always UP just do: RoundedVar = INT(Var + 1) assuming that Var is not a whole number.

To round down just: RoundedVar = INT(Var) when (Var != INT(Var) a.k.a. Var is not a whole number, of course it would still work)

So do I have this correct that there is no way to round in QB?

Posted: Fri Feb 18, 2005 8:11 pm
by {Nathan}
Dunno

Posted: Sat Feb 19, 2005 5:29 am
by Z!re
By round up means that:
4.1 -> 5
4.9 -> 5
4.01 -> 5

Although, it doesent matter much as you can only get 0.5 here.

A simple accurate way is:
size% = INT(value!+1)

Which will give you the amount of bytes you need.

As, 4.01 only fits in 5 bytes (yes, hypothetical, let go off my boobs)

Posted: Sat Feb 19, 2005 7:43 am
by Nodtveidt
You could always use the "cheap bastard's method":

Code: Select all

'i1 is an Integer, i2 is a Single, i3 is a String
'i2 holds the value after doing the math, so it may contain a .5
i3 = LTRIM$(STR$(i2))
IF Right$(i2, 2) = ".5" THEN
  i1 = i2 + .5
ELSE
  i1 = i2
END IF
If you perform the calculations with floating point variables, you'll often get a fractional result. So you could do something like this to make sure your value is always accurate and never even a byte wasted. Then again, of course, a byte is a byte, so doing the math with integers and just increasing the resulting value by 1 may not be such a bad idea either...in my original algorithm written above, you could just skip the "subtract 1" part. :D

Either way works, really.

Posted: Sat Feb 19, 2005 8:02 am
by Mitth'raw'nuruodo
So...I'm right there is no command.

And yes I did know what rounding up means.

Ok I'll stick to my method:
TO normal Round: Var=INT(Var+.5)
To Round up: Var=INT(Var+1)
To round down: Var=INT(var)

I just wanted to know, thanks you guys.

Posted: Sat Feb 19, 2005 9:22 am
by Z!re
CINT()

Posted: Sat Feb 19, 2005 10:28 am
by Mitth'raw'nuruodo
Great thanks.

Posted: Sun Feb 20, 2005 10:50 am
by Mitth'raw'nuruodo
Well I changed my program, It Looks fine.... :D
It went from 64KB to 62KB, but that's still a lot!

Thanks again to everybody :D