Bsave-Bload II
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
Bsave-Bload II
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?
"But...It was so beutifully done"
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact:
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
*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!
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.
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!
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.
"But...It was so beutifully done"
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:
BLOAD as usual.
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
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
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?
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?
"But...It was so beutifully done"
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)
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)
I have left this dump.
You could always use the "cheap bastard's method":
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.
Either way works, really.
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
Either way works, really.
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact: