Bsave-Bload II

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Bsave-Bload II

Post 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?
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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.
"But...It was so beutifully done"
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post 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
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

*Mit bows* Many thanks and many days of happiness to you!
"But...It was so beutifully done"
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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?
"But...It was so beutifully done"
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Dunno
Image
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post 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)
I have left this dump.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post 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.
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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.
"But...It was so beutifully done"
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

CINT()
I have left this dump.
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Great thanks.
"But...It was so beutifully done"
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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
"But...It was so beutifully done"
Post Reply