[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2005-12-09T19:40:39-05:00 http://petesqbsite.com/phpBB3/app.php/feed/topic/1221 2005-12-09T19:40:39-05:00 2005-12-09T19:40:39-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9940#p9940 <![CDATA[Re: Divisibility by 4 ie. Leap Year]]>
Here's a trick I use to check for divisibility by 4, for Leap Years and such:
.....
Just in case you are not aware of it, the complete logic for determining if a year is a leap year is as follows:

If the year is evenly divisible by 4 and not divisible by 100,
or if the year is evenly divisible by 400,
then it's a leap year.
*****

Statistics: Posted by moneo — Fri Dec 09, 2005 7:40 pm


]]>
2005-12-09T16:58:24-05:00 2005-12-09T16:58:24-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9939#p9939 <![CDATA[odd or even]]>

Code:

if number MOD divisor = 0 then 'number is divisible
But it only works on integers. (But there's not really a clear definition of divisibility for non-integers anyway.)

Statistics: Posted by Xerol — Fri Dec 09, 2005 4:58 pm


]]>
2005-12-09T12:30:38-05:00 2005-12-09T12:30:38-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9937#p9937 <![CDATA[Divisibility by 4 ie. Leap Year]]>

Code:

for i = 2000 to 2017  print i;  if i and not -4 then print "Not" else print "Is"next i
The "-4" is for divisibility by 4. The same concept will work for any power of two.

Statistics: Posted by Zim — Fri Dec 09, 2005 12:30 pm


]]>
2005-12-07T12:48:16-05:00 2005-12-07T12:48:16-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9894#p9894 <![CDATA[Re: odd or even]]>
i'm not seeing a command in my qbasic book
for determining ood or even numbers and the
math eludes me...

what i want to do is generate a number
then check if its odd or even if its even
i leave it alone if its odd i add/sub 1 to make it even

berths = int(rnd * X) +A

if berths = even then goto moveon
if berths = odd then berth = (berth + or - 1)

i do need the +A as there needs to be a minimum # of berths
i have made that an even number to be safe...
The simplest method is to use the MOD function.

Code:

IF berths MOD 2 > 0 THEN berths = berths +1
(That should do it.)

Statistics: Posted by Guest — Wed Dec 07, 2005 12:48 pm


]]>
2005-12-03T22:17:25-05:00 2005-12-03T22:17:25-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9807#p9807 <![CDATA[odd or even]]> of the program for helping with the math?

its just a program that makes data for a starship
for the RPG traveller...basiclly just a tool...not a game
in its self...

Statistics: Posted by Guest — Sat Dec 03, 2005 10:17 pm


]]>
2005-12-03T22:15:49-05:00 2005-12-03T22:15:49-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9806#p9806 <![CDATA[odd or even]]>
Guest: Nek's code works... if every variable is integer.
You are probably using the QB defaults that make all variables floating point, so rounding errors may prevent the code from work. The easiest workaround is to put a pair of parentheses in the IF condition.

Code:

berth = int(rnd * 16) + 5 if (berth AND 1) = 1 THEN 'its ODD    let berth = (berth - 1)    print berth else    print "its okay berths even" 'its EVEN end if 
yep thanks that did it...

Statistics: Posted by Guest — Sat Dec 03, 2005 10:15 pm


]]>
2005-12-03T10:45:16-05:00 2005-12-03T10:45:16-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9787#p9787 <![CDATA[odd or even]]> You are probably using the QB defaults that make all variables floating point, so rounding errors may prevent the code from work. The easiest workaround is to put a pair of parentheses in the IF condition.

Code:

berth = int(rnd * 16) + 5 if (berth AND 1) = 1 THEN 'its ODD    let berth = (berth - 1)    print berth else    print "its okay berths even" 'its EVEN end if 

Statistics: Posted by Antoni — Sat Dec 03, 2005 10:45 am


]]>
2005-12-03T00:55:00-05:00 2005-12-03T00:55:00-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9776#p9776 <![CDATA[odd or even]]>
im defintly a rookie... :oops:
We were all rookies once. :D
1. how would i find the file if i dont have an exact path?
Chances are your file is going to be in the same directory as your executable. All you'd need is the filename in that case. If it's in a subdirectory, then you need the subdir name and the filename (say you have a subdir called "stuff" and a file called "myfile.txt", you'd write this as "stuff\myfile.txt"). Absolute paths are extremely unstable when it comes to another person's computer and in QB, this leads to program crashes.
2. do you mean that next file # available thingy?
Yeah...the keyword is "freefile":

Code:

DIM fh AS INTEGERfh = FREEFILEOPEN myfile$ FOR APPEND AS #fhPRINT #fh, "Stuff!"CLOSE fh
It's a lot cleaner and safer. :)

Statistics: Posted by Nodtveidt — Sat Dec 03, 2005 12:55 am


]]>
2005-12-03T00:52:33-05:00 2005-12-03T00:52:33-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9775#p9775 <![CDATA[odd or even]]>
.....

correct i was just plugin' in 11 as the "value" to show whats happening...
i used berth as my variable..

but it turned all my "berths" to -1..

i had a number of berths like 15, 11, 29...

it set them all to -1
That can't be. Post your code so we can take a look.
*****

Code:

im confused....:(berth = int(rnd * 16) + 5 if berth AND 1 = 1 THEN 'its ODD    let berth = (berth - 1)    print berth else    print "its okay berths even" 'its EVEN end if

Statistics: Posted by Guest — Sat Dec 03, 2005 12:52 am


]]>
2005-12-02T20:42:39-05:00 2005-12-02T20:42:39-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9770#p9770 <![CDATA[odd or even]]>
.....

correct i was just plugin' in 11 as the "value" to show whats happening...
i used berth as my variable..

but it turned all my "berths" to -1..

i had a number of berths like 15, 11, 29...

it set them all to -1
That can't be. Post your code so we can take a look.
*****

Statistics: Posted by moneo — Fri Dec 02, 2005 8:42 pm


]]>
2005-12-02T20:15:49-05:00 2005-12-02T20:15:49-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9769#p9769 <![CDATA[odd or even]]>

1. Absolute paths are a no-no.
2. Static file handles are also a no-no.
im defintly a rookie... :oops:

1. how would i find the file if i dont have an exact path?


2. do you mean that next file # available thingy?

Statistics: Posted by Guest — Fri Dec 02, 2005 8:15 pm


]]>
2005-12-02T20:11:55-05:00 2005-12-02T20:11:55-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9768#p9768 <![CDATA[odd or even]]>

What Nek means as "value" is the name of a variable containing your value to be tested for odd/even. In your case "value" is "berth".

I tried his code and it works fine. If berth is 11, it's odd, and as a result berth is set to 11-1 or 10. Can't see why it didn't work for you.
*****

correct i was just plugin' in 11 as the "value" to show whats happening...
i used berth as my variable..

but it turned all my "berths" to -1..

i had a number of berths like 15, 11, 29...

it set them all to -1

Statistics: Posted by Guest — Fri Dec 02, 2005 8:11 pm


]]>
2005-12-02T19:42:13-05:00 2005-12-02T19:42:13-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9766#p9766 <![CDATA[odd or even]]>

Code:

input "enter your ships name"; file$file$ = "boohoo"   <<<<exampleopen "c:\xxxx\file$ + ".txt" for append as #1
shouldnt this open a file called boohoo.txt?
It would work if you built the string properly...

Code:

open "c:\xxxx" + file$ + ".txt" for append as #1
On a related item...you're making two rookie mistakes on this line alone...

1. Absolute paths are a no-no.
2. Static file handles are also a no-no.

Statistics: Posted by Nodtveidt — Fri Dec 02, 2005 7:42 pm


]]>
2005-12-02T19:09:17-05:00 2005-12-02T19:09:17-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9764#p9764 <![CDATA[odd or even]]>
Okay to make something a bit more clear:

Code:

IF value AND 1 = 1 THEN  ' value is ODDELSE  'value is EVENEND IF
Basically...If the 0th bit of the value is on, the number is odd, If it's off, the number is even. :D
okay i tried this but it turns my number to
a negative...

this is for TRAVELLER RPG ships... BTW

example:

Code:

berth = int(rnd * 16) + 5  <<<minium 5 berths max 20 berthsberth = 11  <<<<example...if 11 AND 1 = 1 then   let 11 = (11 - 1)else   PRINT "its okay its even"end if
but this does not give me 10 like i want it gives me -1
am i understanding VALUE wrong...did you mean VAL?
What Nek means as "value" is the name of a variable containing your value to be tested for odd/even. In your case "value" is "berth".

I tried his code and it works fine. If berth is 11, it's odd, and as a result berth is set to 11-1 or 10. Can't see why it didn't work for you.
*****

Statistics: Posted by moneo — Fri Dec 02, 2005 7:09 pm


]]>
2005-12-02T18:28:16-05:00 2005-12-02T18:28:16-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=9760#p9760 <![CDATA[odd or even]]> there is no thread that has the asnwer in it...

Code:

input "enter your ships name"; file$file$ = "boohoo"   <<<<exampleopen "c:\xxxx\file$ + ".txt" for append as #1
shouldnt this open a file called boohoo.txt?

Statistics: Posted by Guest — Fri Dec 02, 2005 6:28 pm


]]>