QBasic and QB64 Discussion Board

[QB Forum Archives (1999-2009)/ ] [QB FAQ] [QB Links and Downloads] [Subforums and Chat Room] [Search]

QB64.Net Homepage   QB/QB64 Keywords   QB Graphics Forum   Homework Policy



haven't been here in years...

by (Login judasghost)

it's been years since i've been to this old N54 forum, since the Mac era. who runs this place now? and how can i access my old login?

cheers,
bp

Posted on May 19, 2013, 6:31 AM

Respond to this message   

Return to Index


Pete

by (Login GarryRicketson)
R

I guess Pete is "in charge", you should be able to access you old login ,using your old loggin name, and password, if you can not remember it, I think you can still get it,..
from Garry
Note:
You log in athttp://www.network54.com
If you do not have a account , you would need to start a new one,..
However
I was just checking, this is what I got "
Login attempt failed. Try again. All login passwords were reset on 18 May 2013. You may need to reset your password. One more try before account is locked."

and it appears as of May 18, 2013,..net54 has reset evryones passwords,.. I have to change mine , now too,..
Also, I select "all ways stay logged in" in my profile, so I don't have to log in every time,..but that is optional.

http://www.network54.com/Forum/44985/thread/1368870975/Password+problems+at+Network54

Posted on May 19, 2013, 5:53 PM

Respond to this message   

Return to Index


*thanks for your help! now i'm REALLY back

by (Login bomberpunk)
R

Posted on May 24, 2013, 3:23 PM

Respond to this message   

Return to Index


qb64.net

by (Login dvdbrgdn)

anyone know why qb64.net is taking so long to approve my account? It making me sad :(

Posted on May 18, 2013, 4:24 PM

Respond to this message   

Return to Index


*You need to send an Email to Galleon

by G (no login)

Posted on May 18, 2013, 5:39 PM

Respond to this message   

Return to Index


* Have you gotten your account yet?

by (Login MCalkins)
Moderator

Posted on May 23, 2013, 8:34 PM

Respond to this message   

Return to Index


VB.NET code

by (no login)


Getting error here in this line "myFolder = myNamespace.GetDefaultFolder(olFolderInbox)" from the code below
"olFolderInbox is not declared. It may not be inaccessible due to its protection level"


Imports System.Runtime.InteropServices
Imports Outlook = Microsoft.Office.Interop.Outlook


Module Module1

Sub Main()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim mySubFolderLevel1 As Outlook.MAPIFolder
Dim mySubFolderLevel2 As Outlook.MAPIFolder
Dim mySubFolderLevel3 As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim mySubFolderLevel4 As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim mySubFolderLevel5 As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim mySubFolderLevel6 As Microsoft.Office.Interop.Outlook.MAPIFolder

Dim objMail As Microsoft.Office.Interop.Outlook.MailItem
myOlApp = CreateObject("Outlook.Application")
myNamespace = myOlApp.GetNamespace("MAPI")

myFolder = myNamespace.GetDefaultFolder(olFolderInbox)

'On Error GoTo ErrorHandler

Dim i As Integer
Dim j As Integer

'Total 6 level, 24 subfolders

For i = 1 To 2
mySubFolderLevel1 = myFolder.Folders.Add("Sub Folder Level 1 " + CStr(i), olFolderInbox)
For j = 1 To 2
mySubFolderLevel2 = mySubFolderLevel1.Folders.Add("Sub Folder Level 2 " + CStr(j), olFolderInbox)
For k = 1 To 2
mySubFolderLevel3 = mySubFolderLevel2.Folders.Add("Sub Folder Level 3 " + CStr(k), olFolderInbox)
For l = 1 To 2
mySubFolderLevel4 = mySubFolderLevel3.Folders.Add("Sub Folder Level 4 " + CStr(l), olFolderInbox)
For m = 1 To 2
mySubFolderLevel5 = mySubFolderLevel4.Folders.Add("Sub Folder Level 5 " + CStr(m), olFolderInbox)
For n = 1 To 2
mySubFolderLevel6 = mySubFolderLevel5.Folders.Add("Sub Folder Level 6 " + CStr(n), olFolderInbox)
Next
Next
Next
Next
Next
Next

'Exit Sub
'ErrorHandler:
'MsgBox "Error creating the folder. The folder may already exist."
'Resume Next
End Sub


End Module

Posted on May 17, 2013, 2:11 AM

Respond to this message   

Return to Index


Post your code here: (url)

by Solitaire (Login Solitaire1)
S

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads

Someone there may be able to help you. Sorry, but my VB.NET expertise does not include advanced concepts, since I teach only beginners.

Posted on May 17, 2013, 6:54 AM

Respond to this message   

Return to Index


VB.NET

by (no login)

You have to declare olFolderInbox somewhere...

Posted on May 23, 2013, 11:49 AM

Respond to this message   

Return to Index


.bas file

by (no login)

I have .bas file. I have to run it. So which software I have to use to run it and from where I can download it. And also please tell me how to run it.

Thanks.

Posted on May 16, 2013, 10:37 PM

Respond to this message   

Return to Index


It depends what BASIC language it was coded in...

by Pete (Login The-Universe)
Admin

If it was written in QBasic, QuickBasic, PDS, or QB64, go to qb64.net, and download the appropriate copy of QB64 for whatever OS you are running, Windows, Linux, or Mac.

If it is a different BASIC language, you need to find if there is a website that has a download that can run it. FreeBasic, Liberty Basic, Real Basic, Dark Basic, Power Basic, etc.

You might want to copy and paste 20 or 30 lines of the code, and maybe someone can identify it.

Pete

Posted on May 16, 2013, 10:43 PM

Respond to this message   

Return to Index


GWBASIC uses a .BAS extension

by Solitaire (Login Solitaire1)
S

Post your code and I'll see if it can run in GWBASIC.

(I may not be back until later today.)

Posted on May 17, 2013, 6:46 AM

Respond to this message   

Return to Index


.bas

by (no login)

Sub CreateHTMLMail()
'Creates new e-mail items and modifies their properties.

Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application

For i = 1 To 2000
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY><br>"

'Set recipient and subject
.To = "abc@gmail.com"
.Subject = " #Test HTML Email From ABC" & i
'.Display
.Send
End With




Next

End Sub

After running QB64 on windows 7 64 bit and running my .bas file

Here getting error : Expected &H... or &O... inline .Subject = " #Test HTML Email From ABC" & i

Also getting this error : Expected operation in equation in line Attribute VB_Name = "Module1"

why I am getting these errors. How can i RESOLVE THEM ?

Also please tell me which language this code is in.

Posted on May 17, 2013, 12:22 AM

Respond to this message   

Return to Index


it might be VB.NET

by James (no login)

There is a vb.net subforum here so there are probably some who will know for sure. QB64 will not run it, but you can get a vb.net compiler for free from microsoft website.

If you are looking to write a program working with emails, qb64 supports tcp/ip as well as ability to load libraries that provide email routines

Posted on May 17, 2013, 12:31 AM

Respond to this message   

Return to Index


is this .bas is in vb.net

by (no login)

Hi,

Please let me know if the above code is in vb.net. If yes how to compile it.

Also I can see that in my windows

c\windows\Microsoft.NET\Framework64\v4.0.30319\vbc.exe.

so is it vb.net compiler. If yes how can I use it to compile and run my file which has .bas extension.

Thanks.

Posted on May 17, 2013, 1:03 AM

Respond to this message   

Return to Index


* No. VB.NET does not use a .bas extension.

by Solitaire (Login Solitaire1)
S

Posted on May 17, 2013, 6:47 AM

Respond to this message   

Return to Index


Help! slowing down bullet speed

by (no login)

I need some help slowing down bullet speed in my jet fighter game. please help!i am just starting out.It is written for qb64 for feel free to paste and run it.
all of the bullets are firing at once, even though i exit the for loop each time.i think it has to do with the mouse button registering more than one click, even though i clear the _mouseinput loop each time...so ....idk


here is the code:

scrn& = _NEWIMAGE(800, 500, 32)
SCREEN scrn&

RANDOMIZE TIMER

white& = _RGB(255, 255, 255)


ship& = _NEWIMAGE(30, 30, 32)
_DEST ship&
LINE (0, 0)-(29, 14), white&
LINE (0, 0)-(0, 29), white&
LINE (0, 29)-(29, 14), white&

bullet& = _NEWIMAGE(10, 10)
_DEST bullet&
LINE (0, 0)-(9, 9), white&, BF

enemy& = _NEWIMAGE(24, 24, 32)
_DEST enemy&
CIRCLE (12, 12), 11, white&


TYPE sprite
x AS INTEGER
y AS INTEGER
height AS INTEGER
width AS INTEGER
alive AS INTEGER
END TYPE


DIM bullets(20) AS sprite
DIM enemy(20) AS sprite

FOR i = 1 TO 20
bullets(i).alive = 0
bullets(i).x = 0
bullets(i).y = 0
bullets(i).height = 20
bullets(i).width = 20

NEXT i

FOR i = 1 TO 20
enemy(i).alive = 0
enemy(i).x = 776
enemy(i).y = INT(RND * 40) + 1
enemy(i).width = 24
enemy(i).height = 24
NEXT i


fire = 0

_DEST scrn&

DO
CLS


'free enemy
IF enemy(1).alive = 0 THEN
enemy(1).alive = 1
enemy(1).x = 776
enemy(1).y = 40
END IF


'get mouse inpput

y = _MOUSEY - (_HEIGHT(ship&) / 2)
x = _MOUSEX - (_WIDTH(ship&) / 2)


'keep ship on screen
IF x < 0 THEN x = 0
IF x > 750 THEN x = 750
IF y < 0 THEN y = 0
IF y > 430 THEN y = 430


'draw ship
_PUTIMAGE (x, y), ship&



'draw and move bullets
FOR i = 1 TO 20
IF bullets(i).alive = 1 THEN
_PUTIMAGE (bullets(i).x, bullets(i).y), bullet&
bullets(i).x = bullets(i).x + 2
IF bullets(i).x > 780 THEN bullets(i).alive = 0
END IF
NEXT i

'draw and move enemy
IF enemy(1).alive = 1 THEN
_PUTIMAGE (enemy(1).x, enemy(1).y), enemy&
enemy(1).x = enemy(1).x - 1
IF enemy(1).x < 1 THEN enemy(1).alive = 0
END IF



i = _MOUSEINPUT
firebutton = _MOUSEBUTTON(1)

IF firebutton = -1 THEN
DO
LOOP UNTIL _MOUSEINPUT = 0

FOR i = 1 TO 20
IF bullets(i).alive = 0 THEN
bullets(i).alive = 1
bullets(i).x = _MOUSEX
bullets(i).y = _MOUSEY
EXIT FOR

END IF
NEXT i


END IF

'check if bullet hits enemy
FOR i = 1 TO 20
IF bullets(i).x > enemy(1).x AND bullets(i).x < enemy(1).x + 20 THEN
IF bullets(i).y > enemy(1).y AND bullets(i).y < enemy(1).y + 20 THEN
bullets(i).alive = 0
enemy(1).alive = 0
END IF
END IF
NEXT i


_DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)

Posted on May 16, 2013, 5:56 PM

Respond to this message   

Return to Index


bullets(i).x = bullets(i).x + 2

by edvard (no login)

change to +1 or something

Posted on May 16, 2013, 6:35 PM

Respond to this message   

Return to Index


I'm not sure I see the need for 20 for next loops

by Pete (Login The-Universe)
Admin

scrn& = _NEWIMAGE(800, 500, 32)
SCREEN scrn&

RANDOMIZE TIMER

white& = _RGB(255, 255, 255)


ship& = _NEWIMAGE(30, 30, 32)
_DEST ship&
LINE (0, 0)-(29, 14), white&
LINE (0, 0)-(0, 29), white&
LINE (0, 29)-(29, 14), white&

bullet& = _NEWIMAGE(10, 10)
_DEST bullet&
LINE (0, 0)-(9, 9), white&, BF

enemy& = _NEWIMAGE(24, 24, 32)
_DEST enemy&
CIRCLE (12, 12), 11, white&


TYPE sprite
x AS INTEGER
y AS INTEGER
height AS INTEGER
width AS INTEGER
alive AS INTEGER
END TYPE


DIM bullets(20) AS sprite
DIM enemy(20) AS sprite

FOR i = 1 TO 20
bullets(i).alive = 0
bullets(i).x = 0
bullets(i).y = 0
bullets(i).height = 20
bullets(i).width = 20

NEXT i

FOR i = 1 TO 20
enemy(i).alive = 0
enemy(i).x = 776
enemy(i).y = INT(RND * 40) + 1
enemy(i).width = 24
enemy(i).height = 24
NEXT i


fire = 0

_DEST scrn&

DO
CLS


'free enemy
IF enemy(1).alive = 0 THEN
enemy(1).alive = 1
enemy(1).x = 776
enemy(1).y = 40
END IF


'get mouse inpput

y = _MOUSEY - (_HEIGHT(ship&) / 2)
x = _MOUSEX - (_WIDTH(ship&) / 2)


'keep ship on screen
IF x < 0 THEN x = 0
IF x > 750 THEN x = 750
IF y < 0 THEN y = 0
IF y > 430 THEN y = 430


'draw ship
_PUTIMAGE (x, y), ship&



'draw and move bullets
FOR i = 1 TO 1
IF bullets(i).alive = 1 THEN
_PUTIMAGE (bullets(i).x, bullets(i).y), bullet&
bullets(i).x = bullets(i).x + 2
IF bullets(i).x > 780 THEN bullets(i).alive = 0
END IF
NEXT i


'draw and move enemy
IF enemy(1).alive = 1 THEN
_PUTIMAGE (enemy(1).x, enemy(1).y), enemy&
enemy(1).x = enemy(1).x - 1
IF enemy(1).x < 1 THEN enemy(1).alive = 0
END IF



i = _MOUSEINPUT
firebutton = _MOUSEBUTTON(1)

IF firebutton = -1 THEN
DO

LOOP UNTIL _MOUSEINPUT = 0

FOR i = 1 TO 1
IF bullets(i).alive = 0 THEN

bullets(i).alive = 1
bullets(i).x = _MOUSEX
bullets(i).y = _MOUSEY
EXIT FOR

END IF
NEXT i


END IF

'check if bullet hits enemy
FOR i = 1 TO 1
IF bullets(i).x > enemy(1).x AND bullets(i).x < enemy(1).x + 20 THEN
IF bullets(i).y > enemy(1).y AND bullets(i).y < enemy(1).y + 20 THEN
bullets(i).alive = 0
enemy(1).alive = 0
END IF
END IF
NEXT i


_DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)

-------------------------------------

Changed the 20s to 1s.

_LIMIT or _DELAY can be used with the for i = 1 to 20 loops, but they seem to slow things down way too much.

Pete

Posted on May 16, 2013, 7:49 PM

Respond to this message   

Return to Index


Likely for having multiple bullets & enemies on the screen

by edvard (no login)

that doesn't seem to be impleneted yet

Posted on May 16, 2013, 7:59 PM

Respond to this message   

Return to Index


edvard. I think you're right...

by Pete (Login The-Universe)
Admin

But I think the developer will want to re-write it for multiple bullets. The best way is to add to the i variable each time the ship fires a bullet.

Pete

Posted on May 16, 2013, 8:28 PM

Respond to this message   

Return to Index


op says

by (no login)

I guess the title was misleading im sorry. i need to slow down the speed at which the bullets fire from the ship. they fire virtually all in a line unless i tap and release the mouse button super fast because they program loops so fast that tthe mousebutton is still registering for several loops. but if i try to slow the loop down fps suffers everywhere else as well. As you were saying as far as adding to the i each time, can you give me an example please?

Posted on May 17, 2013, 5:49 AM

Respond to this message   

Return to Index


possible solution

by Ben (no login)


Not the cleanest, IMO, but should give you an idea. I added variables k, kk to control firing rate.

scrn& = _NEWIMAGE(800, 500, 32)
SCREEN scrn&

RANDOMIZE TIMER

white& = _RGB(255, 255, 255)


ship& = _NEWIMAGE(30, 30, 32)
_DEST ship&
LINE (0, 0)-(29, 14), white&
LINE (0, 0)-(0, 29), white&
LINE (0, 29)-(29, 14), white&

bullet& = _NEWIMAGE(10, 10)
_DEST bullet&
LINE (0, 0)-(9, 9), white&, BF

enemy& = _NEWIMAGE(24, 24, 32)
_DEST enemy&
CIRCLE (12, 12), 11, white&


TYPE sprite
x AS INTEGER
y AS INTEGER
height AS INTEGER
width AS INTEGER
alive AS INTEGER
END TYPE


DIM bullets(20) AS sprite
DIM enemy(20) AS sprite

FOR i = 1 TO 20
bullets(i).alive = 0
bullets(i).x = 0
bullets(i).y = 0
bullets(i).height = 20
bullets(i).width = 20

NEXT i

FOR i = 1 TO 20
enemy(i).alive = 0
enemy(i).x = 776
enemy(i).y = INT(RND * 40) + 1
enemy(i).width = 24
enemy(i).height = 24
NEXT i


fire = 0

_DEST scrn&

DO
k = k + 1


DO
LOOP WHILE _MOUSEINPUT

firebutton = _MOUSEBUTTON(1)
y = _MOUSEY - (_HEIGHT(ship&) / 2)
x = _MOUSEX - (_WIDTH(ship&) / 2)

CLS

'free enemy
IF enemy(1).alive = 0 THEN
enemy(1).alive = 1
enemy(1).x = 776
enemy(1).y = 40
END IF



'keep ship on screen
IF x < 0 THEN x = 0
IF x > 750 THEN x = 750
IF y < 0 THEN y = 0
IF y > 430 THEN y = 430


'draw ship
_PUTIMAGE (x, y), ship&



'draw and move bullets
FOR i = 1 TO 20
IF bullets(i).alive = 1 THEN
_PUTIMAGE (bullets(i).x, bullets(i).y), bullet&
bullets(i).x = bullets(i).x + 2
IF bullets(i).x > 780 THEN bullets(i).alive = 0
END IF
NEXT i

'draw and move enemy
IF enemy(1).alive = 1 THEN
_PUTIMAGE (enemy(1).x, enemy(1).y), enemy&
enemy(1).x = enemy(1).x - 1
IF enemy(1).x < 1 THEN enemy(1).alive = 0
END IF

IF firebutton = -1 THEN
IF k > kk + 50 THEN
FOR i = 1 TO 20
IF bullets(i).alive = 0 THEN
bullets(i).alive = 1
bullets(i).x = _MOUSEX
bullets(i).y = _MOUSEY

kk = k

EXIT FOR
END IF
NEXT
END IF
END IF

'check if bullet hits enemy
FOR i = 1 TO 20
IF bullets(i).x > enemy(1).x AND bullets(i).x < enemy(1).x + 20 THEN
IF bullets(i).y > enemy(1).y AND bullets(i).y < enemy(1).y + 20 THEN
bullets(i).alive = 0
enemy(1).alive = 0
END IF
END IF
NEXT i

_DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)

Posted on May 17, 2013, 9:00 AM

Respond to this message   

Return to Index


OP says thanks!

by d (no login)

Ok, well that was extremely simple but it works!! usually the hardest fixes seem to be the easiest logic. GRRR! lol
i changed it to be


do
...
loops=loops+1
....

if loops>50 then
....
loops=0
...
etc.

easier for me to keep track of mentally but thanks a ton!
now i just gotta figure out why the enemy is wigging out on collision. after bullet/enemy collision, the enemy restartsbut only goes to the impact point for several loops even though there is no bullet there.

Posted on May 17, 2013, 9:52 AM

Respond to this message   

Return to Index


for that you need to check for bullets(i).alive

by Ben (no login)

you may want to rethink the program structure in general, though

'check if bullet hits enemy
FOR i = 1 TO 20
IF bullets(i).alive = 1 THEN
IF bullets(i).x > enemy(1).x AND bullets(i).x < enemy(1).x + 20 THEN
IF bullets(i).y > enemy(1).y AND bullets(i).y < enemy(1).y + 20 THEN
bullets(i).alive = 0
enemy(1).alive = 0

END IF
END IF
END IF
NEXT i

Posted on May 17, 2013, 3:42 PM

Respond to this message   

Return to Index


kk variable isn't needed.

by Pete (Login The-Universe)
Admin

IF firebutton = -1 THEN
IF k > 50 THEN
FOR i = 1 TO 20
IF bullets(i).alive = 0 THEN
bullets(i).alive = 1
bullets(i).x = _MOUSEX
bullets(i).y = _MOUSEY

k = 0

----------------------------------

Good solution Ben. Variable k just needs to be rest to zero, same effect.

Pete

Posted on May 17, 2013, 10:35 AM

Respond to this message   

Return to Index


Example

by (Login The-Universe)
Admin

scrn& = _NEWIMAGE(800, 500, 32)
SCREEN scrn&

RANDOMIZE TIMER

white& = _RGB(255, 255, 255)


ship& = _NEWIMAGE(30, 30, 32)
_DEST ship&
LINE (0, 0)-(29, 14), white&
LINE (0, 0)-(0, 29), white&
LINE (0, 29)-(29, 14), white&

bullet& = _NEWIMAGE(10, 10)
_DEST bullet&
LINE (0, 0)-(9, 9), white&, BF

enemy& = _NEWIMAGE(24, 24, 32)
_DEST enemy&
CIRCLE (12, 12), 11, white&


TYPE sprite
x AS INTEGER
y AS INTEGER
height AS INTEGER
width AS INTEGER
alive AS INTEGER
END TYPE


DIM bullets(20) AS sprite
DIM enemy(20) AS sprite

FOR i = 1 TO 20
bullets(i).alive = 0
bullets(i).x = 0
bullets(i).y = 0
bullets(i).height = 20
bullets(i).width = 20

NEXT i

FOR i = 1 TO 20
enemy(i).alive = 0
enemy(i).x = 776
enemy(i).y = INT(RND * 40) + 1
enemy(i).width = 24
enemy(i).height = 24
NEXT i


fire = 0

_DEST scrn&

DO
CLS


'free enemy
IF enemy(1).alive = 0 THEN
enemy(1).alive = 1
enemy(1).x = 776
enemy(1).y = 40
END IF


'get mouse inpput

y = _MOUSEY - (_HEIGHT(ship&) / 2)
x = _MOUSEX - (_WIDTH(ship&) / 2)


'keep ship on screen
IF x < 0 THEN x = 0
IF x > 750 THEN x = 750
IF y < 0 THEN y = 0
IF y > 430 THEN y = 430


'draw ship
_PUTIMAGE (x, y), ship&



'draw and move bullets
FOR i = 1 TO 20
IF bullets(i).alive = 1 THEN
_PUTIMAGE (bullets(i).x, bullets(i).y), bullet&
bullets(i).x = bullets(i).x + 2
IF bullets(i).x > 780 THEN bullets(i).alive = 0
END IF
NEXT i

'draw and move enemy
IF enemy(1).alive = 1 THEN
_PUTIMAGE (enemy(1).x, enemy(1).y), enemy&
enemy(1).x = enemy(1).x - 1
IF enemy(1).x < 1 THEN enemy(1).alive = 0
END IF

i = _mouseinput

if firebutton = 1 then
z=z + 1
if z = 150 then firebutton = 0: z = 0
end if

if firebutton = 0 then
firebutton = _MOUSEBUTTON(1)
REM do while _mousebutton(1) <> 0:i = _mouseinput:loop
end if

IF firebutton = -1 THEN
firebutton = 1
for ii = 1 to 20
IF bullets(ii).alive = 0 then exit for
next
if ii < 21 then
bullets(ii).alive = 1
bullets(ii).x = _MOUSEX
bullets(ii).y = _MOUSEY
ii = 0
END IF

END IF

'check if bullet hits enemy
FOR i = 1 TO 20
IF bullets(i).x > enemy(1).x AND bullets(i).x < enemy(1).x + 20 THEN
IF bullets(i).y > enemy(1).y AND bullets(i).y < enemy(1).y + 20 THEN
bullets(i).alive = 0
enemy(1).alive = 0
END IF
END IF
NEXT i


_DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)

Posted on May 17, 2013, 9:41 AM

Respond to this message   

Return to Index


little complicated

by d (no login)

thats a little more complicated than i would like to go with a simple firing rate formula, however if the counting loop thing yields problems later on i will save this example for further help. thank you!

Posted on May 17, 2013, 10:09 AM

Respond to this message   

Return to Index


Setting a fire rate

by (Login PhyloGenesis)
Moderator

If/when you want a configurable/more reliable firing rate, use the timing method: (I haven't run this)

fireRate = 250
lastFired = TIMER(.001)

IF TIMER(.001) - lastFired > fireRate THEN




with explanation:

'first set your firing rate (using milliseconds per bullet)
DIM fireRate AS DOUBLE
fireRate = 250

'the important piece, this is the time that the last bullet was fired so you can tell if enough time has passed to allow another shot
DIM lastFired AS DOUBLE
lastFired = TIMER(.001)

' my game loop
DO
...

'are they firing?
i = _MOUSEINPUT
firebutton = _MOUSEBUTTON(1)
IF firebutton = -1 THEN

'has enough time passed to shoot again?
IF TIMER(.001) - lastFired > fireRate THEN
'fire bullet
END IF

END IF

...
LOOP




- QBasic Rules - Mac (RIP)

Posted on May 17, 2013, 12:57 PM

Respond to this message   

Return to Index


great idea

by d (no login)

I havent gotten it to work though the formula is flawed somehow but im not very skilled at using timer yet so i cant figure it out.

Posted on May 17, 2013, 2:41 PM

Respond to this message   

Return to Index


We use TIMER delays for a lot of programs...

by Pete (Login The-Universe)
Admin

Basically, it just means using the fact a computer tracks time while running a program to set, time, or delay an event.

do
z1 = TIMER
do
z2 = TIMER
if z2 < z1 then z1 = z1 - 86400: REM Resets time calculation for midnight
if z2 - z1 > .5 then
print "* ";
exit do
end if
loop
loop


The cool thing about using TIMER is that unlike for/next loops, it is independent of computer speed.


Pete

Posted on May 17, 2013, 3:37 PM

Respond to this message   

Return to Index


In this case, I'd prefer to time things in terms of frames, then set a framerate

by Ben (no login)

using LIMIT

Posted on May 17, 2013, 3:39 PM

Respond to this message   

Return to Index


_LIMIT really slowed that program down too much.

by Pete (Login The-Universe)
Admin

So did _DELAY. Neither seemed to have timed the routine correctly. QB 64 may need to be tweaked a bit more in that regard, but this is not my area, as I seldom work on games.

Pete

Posted on May 17, 2013, 3:43 PM

Respond to this message   

Return to Index


_display also limits framerate

by Jim (no login)

_delay should never be used inside a main loop

you can try _limit 300. you'd think it will take 2 or 3 secs for bullet to clear distance of screen, but may not be the case.

Another thing to consider is possible different speeds of enemies/bullets. say he wants rockets to be slower than bullets, & so on. relative is often better than exact, & exact should be callibrated once

Posted on May 17, 2013, 7:49 PM

Respond to this message   

Return to Index


_DISPLAY doesn't limit the frame rate.

by (Login burger2227)
R

It stops the screen refresh until you tell it to display the screen. Your code execution speed determines how often it displays.

_LIMIT adjusts the loop's speed by inserting small delays for a given frame rate. It adjusts the next loop's speed up or down as needed.

Posted on May 18, 2013, 2:23 AM

Respond to this message   

Return to Index


what output do you get with this

by Jim (no login)

DEFLNG A-Z
SCREEN 12

DIM t AS SINGLE
DIM t1 AS SINGLE, t2 AS SINGLE

t = TIMER
FOR i = 0 TO 100000
LINE (0, 0)-(639, 479), 10, BF
NEXT
t1 = TIMER - t

t = TIMER
FOR i = 0 TO 100000
LINE (0, 0)-(639, 479), 10, BF
_DISPLAY
NEXT
t2 = TIMER - t

PRINT t1, t2
_DISPLAY

SLEEP
SYSTEM

Posted on May 18, 2013, 12:14 PM

Respond to this message   

Return to Index


Fixed!

by d (no login)

well timer is working perfectly . Heres the code so far, and if anyone has any ideas/tips id aprreciate any feedback.

scrn& = _NEWIMAGE(800, 500, 32)
SCREEN scrn&

RANDOMIZE TIMER

_TITLE "David's Space Game Project"
_SCREENMOVE _MIDDLE

white& = _RGB(255, 255, 255)
blue& = _RGB(0, 0, 255)
red& = _RGB(255, 0, 0)
green& = _RGB(0, 255, 0)
ship& = _NEWIMAGE(30, 30, 32)

_DEST ship&
LINE (0, 0)-(29, 14), blue&
LINE (0, 0)-(0, 29), blue&
LINE (0, 29)-(29, 14), blue&
PAINT (5, 5), blue&

bullet& = _NEWIMAGE(10, 10)
_DEST bullet&
LINE (0, 0)-(9, 9), red&, BF

enemy& = _NEWIMAGE(24, 24, 32)
_DEST enemy&
CIRCLE (12, 12), 11, green&
PAINT (12, 12), green&

TYPE sprite
x AS INTEGER
y AS INTEGER
height AS INTEGER
width AS INTEGER
alive AS INTEGER
END TYPE



DIM bullets(20) AS sprite
FOR i = 1 TO 20
bullets(i).alive = 0
bullets(i).x = 0
bullets(i).y = 0
bullets(i).height = 20
bullets(i).width = 20
NEXT i

DIM enemy(10) AS sprite
FOR i = 1 TO 10
enemy(i).alive = 0
enemy(i).x = 776
enemy(i).y = INT(RND * 40) + 1
enemy(i).width = 24
enemy(i).height = 24
NEXT i

TYPE sprite2
x AS SINGLE
y AS SINGLE
brightness AS INTEGER
speed AS SINGLE
END TYPE

DIM stars(100) AS sprite2

FOR i = 1 TO 100
stars(i).x = (RND * 795) + 1
stars(i).y = (RND * 495) + 1
stars(i).brightness = 50 + RND * 200
stars(i).speed = stars(i).brightness / 750.0
NEXT i

start = TIMER
enemytimer = TIMER

_DEST scrn&

DO
CLS
_PRINTMODE _KEEPBACKGROUND
LOCATE 1, 1: PRINT "destroyed = "; destroyed
LOCATE 2, 1: PRINT "Missed = "; missed

'create stars background
FOR n = 1 TO 100
b = stars(n).brightness
x = stars(n).x
y = stars(n).y
LINE (x - 1, y - 1)-(x + 1, y + 1), _RGB(b, b, b), BF
stars(n).x = stars(n).x - stars(n).speed
IF stars(n).x < 0 THEN stars(n).x = 800
NEXT n

'free enemy
IF TIMER - enemytimer >= .5 THEN
FOR i = 1 TO 10
IF enemy(i).alive = 0 THEN
enemy(i).alive = 1
enemy(i).x = 776
enemy(i).y = (RND * 476) + 24
EXIT FOR
END IF
NEXT
enemytimer = TIMER
END IF

'get mouse inpput
DO
LOOP UNTIL _MOUSEINPUT = 0
i = _MOUSEINPUT
y = _MOUSEY - (_HEIGHT(ship&) / 2)
x = _MOUSEX - (_WIDTH(ship&) / 2)


'keep ship on screen
IF x < 0 THEN x = 0
IF x > 770 THEN x = 770
IF y < 0 THEN y = 0
IF y > 470 THEN y = 470


'draw ship
_PUTIMAGE (x, y), ship&

'if mouse button is pressed
IF _MOUSEBUTTON(1) THEN
IF TIMER - start >= .42 THEN

FOR i = 1 TO 20
IF bullets(i).alive = 0 THEN
bullets(i).alive = 1
bullets(i).x = _MOUSEX
bullets(i).y = _MOUSEY
EXIT FOR
END IF
NEXT i
'reset timer
start = TIMER

END IF
END IF

'draw and move bullets
FOR i = 1 TO 20
IF bullets(i).alive = 1 THEN
_PUTIMAGE (bullets(i).x, bullets(i).y), bullet&
bullets(i).x = bullets(i).x + 2
IF bullets(i).x > 800 THEN bullets(i).alive = 0
END IF
NEXT i

'draw and move enemy
FOR i = 1 TO 10
IF enemy(i).alive = 1 THEN
_PUTIMAGE (enemy(i).x, enemy(i).y), enemy&
enemy(i).x = enemy(i).x - .8
IF enemy(i).x < 1 THEN enemy(i).alive = 0: missed = missed + 1
END IF
NEXT

'check if bullet hits enemy
FOR i = 1 TO 20
FOR n = 1 TO 10
IF bullets(i).alive = 1 THEN
IF bullets(i).x >= enemy(n).x AND bullets(i).x < (enemy(n).x + 24) AND bullets(i).y >= (enemy(n).y - 5) AND bullets(i).y < (enemy(n).y + 30) THEN
bullets(i).alive = 0
bullets(i).x = _MOUSEX
bullets(i).y = _MOUSEY
enemy(n).alive = 0
enemy(n).x = 800
enemy(n).y = 500
destroyed = destroyed + 1
END IF
END IF
NEXT n
NEXT i


_DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)

Posted on May 18, 2013, 3:50 PM

Respond to this message   

Return to Index


Session times out when posting at qb64.net

by Cyperium (no login)

I couldn't find any thread here about it, so I'm just posting this so that users know that it isn't only on their computer.

Have any of you heard from Galleon regarding this?

Posted on May 14, 2013, 5:40 PM

Respond to this message   

Return to Index


* I was able to post just now.

by (Login MCalkins)
Moderator

Posted on May 14, 2013, 8:12 PM

Respond to this message   

Return to Index


* Really, where?

by Pete (Login The-Universe)
Admin

Posted on May 14, 2013, 9:06 PM

Respond to this message   

Return to Index


* At the main qb64.net subforum. Obviously either you or Galleon deleted it.

by (Login MCalkins)
Moderator

Posted on May 14, 2013, 9:15 PM

Respond to this message   

Return to Index


* Ain't I a stinker!

by Bugs Bunny (Login The-Universe)
Admin

Posted on May 14, 2013, 9:30 PM

Respond to this message   

Return to Index


* Yes, I can post now too, I couldn't post for a few days though.

by Cyperium (no login)

Posted on May 15, 2013, 4:12 PM

Respond to this message   

Return to Index


Reading Bits

by Zack (no login)

It's not letting me post new topics in the QB64 Community forum for some reason...
How can you read the bits of a binary file rather than just the characters? (I feel this is Michael's domain ;D)
Also, if there is an easier way to find the headers in an mp3 file, I'm open to new ideas ::)

Posted on May 13, 2013, 7:08 PM

Respond to this message   

Return to Index


* You can use AND with powers of 2.

by (Login MCalkins)
Moderator

Posted on May 13, 2013, 10:04 PM

Respond to this message   

Return to Index


* Could you explain what you mean?

by Zack (no login)

Posted on May 17, 2013, 11:21 AM

Respond to this message   

Return to Index


Re: * You can use AND with powers of 2.

by Zack (no login)

Like you open a file and read it into a string of bytes. But how do you read it as an array of bits? My goal is to open an mp3 file as binary, locate, and read the header. Could you explain what you mean by using AND? I don't understand.

Posted on May 17, 2013, 11:25 AM

Respond to this message   

Return to Index


demo

by (Login MCalkins)
Moderator

You could read/write fixed length strings (using CVL/MKL$, CVI/MKI$, ASC/CHR$, CVD/MKD$, CVS/MKS$ to convert), or you could read/write numeric types directly. You can also read/write user defined types (TYPE structures).

On the x86 platform, numbers (both integers and floats) are stored in little-endian byte order. Signed integers are stored using two's complement. Floats are stored using IEEE 754-1985.

Remember that the operators like NOT, AND, OR, and XOR are bitwise. So, you can use powers of 2 with them to manipulate bits. For example:
x AND 2 ^ 5
returns 0 if the 6th bit is clear, but returns 32 if the 6th bit is set.

Some file formats, algorithms, protocols, etc... specify big endian. You might need to doing some endian inversion.

The program below demonstrates some basic binary file I/O, storage of data types, some bitwise manipulation, and endianness reversal of a dword, using shifts and masks.

Regards,
Michael

' public domain, correctness not guaranteed
TYPE someStructureType
 a AS LONG
 b AS SINGLE
 c AS INTEGER
 d AS _UNSIGNED _BYTE
 e AS STRING * 5
END TYPE

DIM record AS someStructureType
DIM x AS _UNSIGNED LONG
DIM y AS _UNSIGNED LONG
DIM b AS _UNSIGNED _BYTE

CLS

record.a = &H30313233
record.b = 0.15625
record.c = -521
record.d = &H40
record.e = "vwxyz"

OPEN "delme.bin" FOR BINARY AS 1
PUT 1, , record
CLOSE

' SHELL "edit /64 delme.bin"
' SHELL "notepad delme.bin"

PRINT "Notice the little-endian byte order of both integers and floats."
PRINT "http://en.wikipedia.org/wiki/Endianness"
PRINT
PRINT "   .a------------  .b------------  .c----  .d  .e----------------";

OPEN "delme.bin" FOR BINARY AS 1
_CONTROLCHR OFF
FOR x = 1 TO LEN(record)
 GET 1, x, b
 LOCATE 5, 4 * x: PRINT hexb(b);
 LOCATE 6, 4 * x: PRINT CHR$(b);
NEXT
_CONTROLCHR ON
GET 1, 1, record
GET 1, 5, y '          reading the SINGLE as an _UNSIGNED LONG
CLOSE
PRINT
PRINT
PRINT ".a: "; record.a, "0x" + hexd(record.a)
x = revd(record.a)
PRINT "endianness reversed:"
PRINT "    "; x, "0x" + hexd(x); " (reversed to big-endian)"
PRINT
PRINT ".b: "; record.b, , "0x" + hexd(y); " ( <-- reinterpreted )"
PRINT "http://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_numbers"
x = &H80000000~& '                             2 ^ 31
COLOR &HB
DO
 SELECT CASE x
  CASE &H40000000: COLOR &HA: PRINT " ";
  CASE &H400000: COLOR &HC: PRINT " ";
 END SELECT
 PRINT CHR$(&H30 + (y AND x) \ x); '           &h30 is "0"
 x = x \ 2 '                                   right shift
LOOP WHILE x
COLOR 7
PRINT
PRINT
PRINT ".c: "; record.c, "0x" + hexw(record.c), " http://en.wikipedia.org/wiki/Two%27s_complement"
PRINT ".d: "; record.d, "0x" + hexb(record.d)
PRINT ".e: "; record.e
PRINT
PRINT "Press any key..."
SLEEP: WHILE LEN(INKEY$): WEND

CLS
PRINT "You can use AND to test bits, OR to set bits, and XOR to toggle bits."
PRINT "You can multiply by a power of 2 to left shift. You can divide by a power of"
PRINT "2 to right shift. You can add a number to itself to left shift by one."
PRINT "_UNSIGNED LONG:"
PRINT
y = 0
GOSUB printy
PRINT "Using OR 0x430 to set 5th, 6th, 11th bits"
y = y OR &H430
GOSUB printy
PRINT "Using XOR 0x40100020 to toggle 6th, 21st, 30th bits"
y = y XOR &H40100020~&
GOSUB printy
PRINT "Using AND 0x40100010 to test 5th, 21st, 30th bits"
y = y AND &H40100010
GOSUB printy
PRINT "Using \ 8 to right shift 3"
y = y \ 8
GOSUB printy
PRINT "Using + itself to left shift 1"
y = y + y
GOSUB printy

END

printy:
PRINT y, "0x" + hexd(y) + "   Bin: ";
x = &H80000000~&
DO
 PRINT CHR$(&H30 + (y AND x) \ x); '           &h30 is "0"
 x = x \ 2 '                                   right shift
LOOP WHILE x
PRINT
PRINT
RETURN

FUNCTION revd~& (d AS _UNSIGNED LONG)
revd = d \ &H1000000 OR (d AND &HFF0000) \ &H100 OR (d AND &HFF) * &H1000000 OR (d AND &HFF00&) * &H100
END FUNCTION

'$include:'hexx.bi' ' http://www.qb64.net/forum/index.php?topic=4491.0

Posted on May 17, 2013, 3:15 PM

Respond to this message   

Return to Index


Eh

by Zack (no login)

It always returns 1 for me for some reason... Am I doing something wrong?

I didn't try to understand all of your code because I only really need to read it, not edit it or flip it or anything. But I did save it, I will experiment with it later.

a$ = CHR$(48)
PRINT bit(a$, 7)
PRINT bit(a$, 6)
PRINT bit(a$, 5)
PRINT bit(a$, 4)
PRINT bit(a$, 3)
PRINT bit(a$, 2)
PRINT bit(a$, 1)
PRINT bit(a$, 0)

SLEEP

IF 48 AND 2 ^ 7 = 2 ^ 7 THEN PRINT "1" ELSE PRINT "0"
IF 48 AND 2 ^ 6 = 2 ^ 6 THEN PRINT "1" ELSE PRINT "0"
IF 48 AND 2 ^ 5 = 2 ^ 5 THEN PRINT "1" ELSE PRINT "0"
IF 48 AND 2 ^ 4 = 2 ^ 4 THEN PRINT "1" ELSE PRINT "0"
IF 48 AND 2 ^ 3 = 2 ^ 3 THEN PRINT "1" ELSE PRINT "0"
IF 48 AND 2 ^ 2 = 2 ^ 2 THEN PRINT "1" ELSE PRINT "0"
IF 48 AND 2 ^ 1 = 2 ^ 1 THEN PRINT "1" ELSE PRINT "0"
IF 48 AND 2 ^ 0 = 2 ^ 0 THEN PRINT "1" ELSE PRINT "0"

SLEEP

SYSTEM

FUNCTION bit (byte$, twospace)
bit = 0
IF ASC(byte$) AND 2 ^ twospace = 2 ^ twospace THEN bit = 1
END FUNCTION

Posted on May 20, 2013, 2:23 PM

Respond to this message   

Return to Index


That should work. (2 edits)

by (Login MCalkins)
Moderator

P.S. = has higher precedence than AND

IF ASC(byte$) AND 2 ^ twospace = 2 ^ twospace THEN bit = 1

should be:

IF (ASC(byte$) AND 2 ^ twospace) = 2 ^ twospace THEN bit = 1

which could become:

IF (ASC(byte$) AND 2 ^ twospace) <> 0 THEN bit = 1

which is equivalent to;

IF ASC(byte$) AND 2 ^ twospace THEN bit = 1

Or, you could do:

bit = (ASC(byte$) AND 2 ^ twospace) \ 2 ^ twospace

or:

bit = ASC(byte$) \ 2 ^ twospace AND 1

But, it looks like you understand the concept.

Regards,
Michael

Posted on May 20, 2013, 2:47 PM

Respond to this message   

Return to Index


Precedence

by (Login MCalkins)
Moderator

= has higher precedence than AND

change:

IF 48 AND 2 ^ 7 = 2 ^ 7 THEN

to:

IF (48 AND 2 ^ 7) = 2 ^ 7 THEN

But it could become:

IF 48 AND 2 ^ 7 THEN

Regards,
Michael

Posted on May 20, 2013, 2:50 PM

Respond to this message   

Return to Index


* Operator Precedence in QBasic (URL)

by (Login MCalkins)
Moderator

http://www.qb64.net/forum/index.php?topic=5990.0

Posted on May 20, 2013, 2:57 PM

Respond to this message   

Return to Index


* Both QB64 and C++ have direct support for bit arrays, but I'm not experienced with them.

by (Login MCalkins)
Moderator

Posted on May 17, 2013, 3:30 PM

Respond to this message   

Return to Index


* Thank you Michael

by Zack (no login)

Posted on May 20, 2013, 7:00 PM

Respond to this message   

Return to Index


* yw.

by (Login MCalkins)
Moderator

Posted on May 20, 2013, 10:20 PM

Respond to this message   

Return to Index


Extracting pixel data from bmps

by Alexh110 (no login)

Hey guys.
Have just written a QBASIC program to extract the pixel data from a 24-bit bmp, convert to YUV, then convert back to RGB and write out another bmp.
The idea is to manipulate the YUV data with some code I will insert later on.

However it's not working correctly: my output file has a black bar across the top, though the remainder of the image lower down is OK.

Presumably there's an error in my assumptions about the bmp's header structure, but I'm not sure how to adjust the BMPHeaderType.
Any help would be great!

My code is shown below (NB I'm using the array l(x%, y%) for the Y component values to avoid confusion with the y-coordinate):


TYPE BMPHeaderType
 id AS STRING * 2
 size AS LONG
 rr1 AS INTEGER
 rr2 AS INTEGER
 offset AS LONG
 horz AS LONG
 wid AS LONG
 hei AS LONG
 planes AS INTEGER
 bpp AS INTEGER
 pakbyte AS LONG
 imagebytes AS LONG
 xres AS LONG
 yres AS LONG
 colch AS LONG
 ic AS LONG
 pal AS STRING * 1024
END TYPE

DIM BmpHeader AS BMPHeaderType

OPEN "4.bmp" FOR BINARY AS #1

GET #1, , BmpHeader


DIM Pixel AS STRING * 1

DIM l(720, 576) AS INTEGER
DIM u(720, 576) AS INTEGER
DIM v(720, 576) AS INTEGER


FOR y% = 1 TO 576
FOR x% = 1 TO 720

 GET #1, , Pixel
 B = ASC(Pixel)
 GET #1, , Pixel
 G = ASC(Pixel)
 GET #1, , Pixel
 R = ASC(Pixel)

 l(x%, y%) = 0.299 * R + 0.587 * G + 0.114 * B
 u(x%, y%) = (B - l(x%, y%)) * 0.565
 v(x%, y%) = (R - l(x%, y%)) * 0.713


NEXT x%, y%

CLOSE #1





OPEN "4_mod.bmp" FOR BINARY AS #1

PUT #1, , BmpHeader


FOR y% = 1 TO 576
FOR x% = 1 TO 720

 R = l(x%, y%) + 1.403 * v(x%, y%)
 G = l(x%, y%) - 0.344 * u(x%, y%) - 0.714 * v(x%, y%)
 B = l(x%, y%) + 1.770 * u(x%, y%)

 R = INT(R)
 G = INT(G)
 B = INT(B)

IF R > 255 THEN R = 255
IF G > 255 THEN G = 255
IF B > 255 THEN B = 255
IF R < 0 THEN R = 0
IF G < 0 THEN G = 0
IF B < 0 THEN B = 0


 Pixel = CHR$(B)
 PUT #1, , Pixel
 Pixel = CHR$(G)
 PUT #1, , Pixel
 Pixel = CHR$(R)
 PUT #1, , Pixel

NEXT x%, y%

CLOSE #1




I also tried inserting the line:
GET #1, BmpHeader.offset-1, Pixel

after:
DIM Pixel AS STRING * 1

But it didn't help.

Posted on May 13, 2013, 5:29 PM

Respond to this message   

Return to Index


Not sure about header size...

by (Login qb432l)
R

It looks right, but if you want to check, go to

http://www.wotsit.org/

...for all the information you'll need on bitmap structure (.BMP).

I notice that you are working with literal width/depth information. I assume you already know all about the bitmap in "4.bmp". What I suggest is to load a different bitmap of similar size and bit-depth, but work with the x/y data from the file's header and create your new file using the header data as well. If the new file has the same black bar, then the problem is somewhere else in your code.

-Bob

Posted on May 13, 2013, 7:06 PM

Respond to this message   

Return to Index


Solved!

by Alexh110 (no login)

Thanks: I've solved the problem now.
It seems there's an extra byte stored with every pixel; although it serves no useful purpose since there's no alpha channel information in this image!

Apparently one of the many bmp variants stores a fourth byte with each pixel, even when the image information shows it to have a 24 bit RGB file structure. How confusing is that?!
It appears my bmp happens to be in this variant format.

Posted on May 15, 2013, 4:18 PM

Respond to this message   

Return to Index


The palette is stored as 4 bytes

by (Login burger2227)
R

The empty byte is the high byte at the end when it is stored as a LONG value into the file. PUT writes the RGB LONG value backwards as BGR with an empty byte. Each value is an ASCII character like MKL$ makes long values.

Posted on May 15, 2013, 8:49 PM

Respond to this message   

Return to Index


MKL$

by Alexh110 (no login)

Thanks.
So long as the empty byte comes after the BGR values, my program should now work correctly.
Not heard of MKL$, will look it up.

Posted on May 16, 2013, 7:37 AM

Respond to this message   

Return to Index


Re: MKL$

by (Login MCalkins)
Moderator

On this platform, numbers are stored in little-endian byte order, and signed integers use two's complement.

MKL$ represents a LONG integer as a string. CVL does the inverse. MLI$, CHR$, MKD$, MKS$, CVI, ASC, CVD, and CVS do so for other data types.

Regards,
Michael

Posted on May 16, 2013, 8:21 AM

Respond to this message   

Return to Index


Koch fractal ?

by (no login)

I made a few searches, but sorry no joy :

On internet, Pete's page while it seemed easy but he forgot to share the code, then on this forum, my only post, in the whole internet, no much left.

And, my recursion based algo is broken.

L

Posted on May 7, 2013, 2:13 PM

Respond to this message   

Return to Index


recursive

by Ben (no login)

'#lang "fblite"
DEFSNG A-Z


DECLARE SUB tri (x, y, s, a)
DECLARE SUB koch (s, i, x, y)

CONST scrW = 640
CONST scrH = 480
'const pi = 4*atn(1)
DIM SHARED pi
pi = 4 * ATN(1)

'dim shared cc = 2*sqr(3)/9
DIM SHARED cc
cc = 2 * SQR(3) / 9



'screenres scrW, scrH, 32
SCREEN 12

s = 400
tri scrW / 2, scrH / 2, s, 0
tri scrW / 2, scrH / 2, s, pi

koch 400, 4, scrW / 2, scrH / 2

SLEEP
SYSTEM

SUB koch (s, i, x, y)
IF i = 0 THEN EXIT SUB
FOR a = pi / 6 TO 2 * pi + pi / 6 STEP pi / 3
xx = s * cc * COS(a) + x
yy = s * cc * SIN(a) + y

tri xx, yy, s / 3, a + pi / 6

koch s / 3, i - 1, xx, yy
NEXT
END SUB

SUB tri (x, y, s, a)
c = SQR(12) / 6

'line (x,y)-(x+s*c*cos(pi/6 + a),y+s*c*sin(pi/6 + a))
'line (x,y)-(x+s*c*cos(5*pi/6 + a),y+s*c*sin(5*pi/6 + a))
'line (x,y)-(x-s*c*cos(pi/2 + a),y-s*c*sin(pi/2 + a))

LINE (x + s * c * COS(pi / 6 + a), y + s * c * SIN(pi / 6 + a))-(x + s * c * COS(5 * pi / 6 + a), y + s * c * SIN(5 * pi / 6 + a))
LINE -(x - s * c * COS(pi / 2 + a), y - s * c * SIN(pi / 2 + a))
LINE -(x + s * c * COS(pi / 6 + a), y + s * c * SIN(pi / 6 + a))

'line(x,y-s*c)-(x+s*c*cos(pi/6),y+s*c*sin(pi/6))
'line -step(-s,0)
'line -(x,y-s*c)
END SUB

Posted on May 7, 2013, 7:20 PM

Respond to this message   

Return to Index


Re: recursive

by Ben (no login)

[linked image]

I edited to enable the image. - Pete

Posted on May 7, 2013, 7:20 PM

Respond to this message   

Return to Index


Yes...

by (no login)

http://www.petesqbsite.com/sections/zines/qbcm/issues/3-2/default.html

Download and tweak to your taste Apollo12.bas, and play with this easy Screen 12 fractal code. It can plot:

the flock of Von Koch
the triangle of Sierpinsky
the Apollonia fractal
the Apollonia gasket

Posted on May 8, 2013, 12:17 AM

Respond to this message   

Return to Index


'#lang "fblite"? It woks in Qbasic and QB64

by (Login burger2227)
R

Didn't know FB had a lite?

Posted on May 8, 2013, 8:25 AM

Respond to this message   

Return to Index


it was converted

by Ben (no login)

notice the commented out statements

fblite is the sort of QB-like language option in freebasic that forgives use of undeclared variables and other such bug inducing bad habits.

Posted on May 8, 2013, 1:45 PM

Respond to this message   

Return to Index


if you uncomment the first set of 3 lines...

by Ben (no login)

& comment the rest, you get this.., I didn't even realize it was there, haha

http://qbasic.orgfree.com/flake.png

Posted on May 8, 2013, 1:39 PM

Respond to this message   

Return to Index


...

by (no login)

- How do you understand that the perimeter of the Koch curve tends toward infinite when n goes to infinite, while the area still remains under 8/5 ?

Adding something because the perimeters grows in n ^ 4, and never goes convex, but this something is almost nothing.

Anyway i don't understand your algo.

L

Posted on May 9, 2013, 1:57 AM

Respond to this message   

Return to Index


infinite perimeter

by Jim (no login)

It is kind of unintuitive. You'd think if it has infinite perimeter and you were to wrap it around with a wire, you'd need an infinitely long wire, but it's not the case. You would end up with lengths so small that you would need to stretch or cut up the wire to fit. Disregarding atoms and such, you can take any wire and stretch it to infinite length, but it would end up being infinitely thin, but could retain constant mass? or infinitely small mass?

Posted on May 9, 2013, 11:59 AM

Respond to this message   

Return to Index


Parsing csv strings

by (no login)

Hi,

Very simple parsing program, but :

- Is it Dosbox or LTRIM$, anyway a single space, " " was not trimmed by LTRIM$. If i set :

cline$ = " "

This is not trimmed, maybe rtfm.

thx, L


====================================================

outfile$ = "csv.txt"
n = 2

DIM CSV(n) AS STRING

'CLS OUTPUT FILE :
KILL outfile$
OPEN outfile$ FOR APPEND AS #1
CLOSE #1

OPEN outfile$ FOR OUTPUT AS #2

CSV(1) = _
"CALL TRIAN((Sx - Lx) * 1 / 3 + Lx, (Sy - Ly) * 1 / 3 + Ly, (Sx - Lx) * 2 / 3 + Lx, (Sy - Ly) * 2 / 3 + Ly, (Sx - Lx) * 1 / 2 + Lx, (Sy - Ly) * 1 / 2 + Ly, ((Sx - Lx) * 1 / 2 + Lx) - SQR(ABS(D ^ 2 / (1 + (-(Sx - Lx) / (Sy - Ly)) ^ 2))), ((Sy - Ly) * 1 / 2 + Ly) - (SQR(ABS(D ^ 2 / (1 + (-(Sx - Lx) / (Sy - Ly)) ^ 2)))) * (-(Sx - Lx) / (Sy - Ly)), D / 3, C, n - 1)" _


CSV(2) = _
"CALL TRIAN((Rx - Sx) * 1 / 3 + Sx, (Ry - Sy) * 1 / 3 + Sy, (Rx - Sx) * 2 / 3 + Sx, (Ry - Sy) * 2 / 3 + Sy, (Rx - Sx) * 1 / 2 + Sx, (Ry - Sy) * 1 / 2 + Sy, ((Rx - Sx) * 1 / 2 + Sx) + SQR(ABS(D ^ 2 / (1 + (-(Rx - Sx) / (Ry - Sy)) ^ 2))), ((Ry - Sy) * 1 / 2 + Sy) + (SQR(ABS(D ^ 2 / (1 + (-(Rx - Sx) / (Ry - Sy)) ^ 2)))) * (-(Rx - Sx) / (Ry - Sy)), D / 3, C, n - 1)" _


FOR i = 1 TO n

cline$ = CSV(n)

'Trim to first and last parenthesis :

c = INSTR(cline$, "(")
cline$ = RIGHT$(cline$, LEN(cline$) - c)
cline$ = LEFT$(cline$, LEN(cline$) - 1)

'CSV LOOP :

ON ERROR GOTO ERRORHANDLE

DO WHILE LEN(cline$) > 0
cline$ = LTRIM$(cline$)

'getting infos :

c = INSTR(cline$, ",")

'proceeding :

IF c > 0 THEN

stub$ = MID$(cline$, 1, c - 1)
PRINT #2, stub$

'uptdating :

cline$ = RIGHT$(cline$, LEN(cline$) - c)

ELSE

PRINT #2, cline$
cline$ = ""

END IF

LOOP

'separate
PRINT #2,

NEXT i

CLOSE #2

GOTO skip
ERRORHANDLE:
PRINT c
END
skip:

END






Posted on May 7, 2013, 6:13 AM

Respond to this message   

Return to Index


sorry, my bug...

by (no login)

hate that ! will exterminate all bugs !

Posted on May 7, 2013, 6:17 AM

Respond to this message   

Return to Index


help with a program

by JoeLewis (no login)

it's simple I'm sure to some but I'm just starting. what would a program look like that can do this..

ask the user the weight of their fish
if a negative number is entered, end.
If the fish is 0-2 pounds, reply "small sized"
2-5 pounds "medium sized"
5+ pounds "large fish"
and continue asking for fish weights until a negative number is entered

Posted on May 6, 2013, 2:07 PM

Respond to this message   

Return to Index


Negativ weight can be useful for solving center of mass problems.

by (no login)

You should search for Input, IF statement or Case...

L

Posted on May 6, 2013, 2:16 PM

Respond to this message   

Return to Index


what would

by JoeLewis (no login)

what would the code be with an IF statement

Posted on May 6, 2013, 3:34 PM

Respond to this message   

Return to Index


Joe,

by (Login Kewbie)
R

Below is a link to the forum's Homework Policy. You can also access it near the top of the page where you opened this post.

http://www.network54.com/Realm/QBasicFAQ/QBasicHomework.html

What Lisztfr was suggesting is that you look up some QBASIC keywords using the Help system. In order to do what you need to, you will need to write code that uses the following QBASIC statements:

DO
INPUT 'ask the user the weight of their fish
IF, END 'if a negative number is entered, end.
IF, PRINT 'If the fish is 0-2 pounds, reply "small sized"
IF, PRINT '2-5 pounds "medium sized"
IF, PRINT '5+ pounds "large fish"
LOOP 'and continue asking for fish weights until a negative number is entered

Once you have a program written, if you are having problems with it, post the code here to show what you have done, and ask questions about any behavior that you don't understand.

For instance, you might ask how you can tell if a negative number has been entered. We will be happy to help you with that. What we will NOT do is write the program for you.

Kew

Posted on May 6, 2013, 6:34 PM

Respond to this message   

Return to Index


Thank you

by JoeLewis (no login)

I was having a hard time understanding the basics but I've kinda figured it out. Wasn't really looking for someone to write it for me

Posted on May 8, 2013, 9:44 AM

Respond to this message   

Return to Index


If you get more complex assignments...

by Pete (Login The-Universe)
Admin

If you happen to come back and see this message, you are certainly welcome to use this forum for help in the future. The best way is to write what code you can, post it, and state what it is you don't understand, what could make the program work better, why it doesn't work, etc. I think that kind of support actually has helped a lot of students in school learn how to code better, and enjoy coding more. It can get frustration if you try something over and over and don't make progress, otherwise.

Pete

Posted on May 8, 2013, 10:22 AM

Respond to this message   

Return to Index


Some hints on how to proceed

by Solitaire (no login)

Here is an outline on how you would go about preparing your program. This is how you should always plan before you start writing any code:

1. Put the entire program into a DO loop to continue until the value of the weight is negative.
2. Inside the loop:
a. Tell the user to enter weight of a fish, or a negative number to stop.
b. Get user's input of the weight and save it to a variable.
c. Use either an IF-THEN-ELSE block or a SELECT CASE block for evaluating the weight. Inside the IF or SELECT block, output the string with the size, matching the value of the weight variable.

Sorry, but no one here will write the code for you. Since this is a homework assignment, you need to post the code you have so far and ask for help if you're having trouble with a specific part of the code.

Posted on May 6, 2013, 6:26 PM

Respond to this message   

Return to Index


* If we do your homework, your teacher will know.

by (Login burger2227)
R

Posted on May 6, 2013, 8:34 PM

Respond to this message   

Return to Index


Come on Joe, you don't have to weigh fish...

by Pete (Login The-Universe)
Admin

Because they come with their own scales.

Pete happy.gif

Posted on May 8, 2013, 12:38 AM

Respond to this message   

Return to Index


Attention all Personnel

by Radar O'Reilly (Login The-Universe)
Admin

A new sub-forum has just been added to the Index. Welcome the Android QB64 App Developers Message Board, moderated by MystikShadows... I know!

Apparently I missed the Second Coming, because my ol' pal MystikShadows was recently raised from the dead and is back in our coding community once again. He may need some time off to see a doctor, if his resurrection lasts for more than 4-hours, but kidding aside, I'm glad to see him back and looking forward to Android discussions that will be added here and at QB64.

Mobile devices are the future, and I'm really glad Galleon has recognized that, and is heading in this direction. The ability to use our QB programs on mobile devices is going to be huge.

That is all,

Radar

Posted on May 5, 2013, 12:48 PM

Respond to this message   

Return to Index


Sorry, it was my fault mentioning him...

by (Login burger2227)
R

wink.gif

Posted on May 5, 2013, 2:18 PM

Respond to this message   

Return to Index


* Next time put an asterisk in your post, ferret-face.

by Hawkeye (Login The-Universe)
Admin

Posted on May 5, 2013, 3:36 PM

Respond to this message   

Return to Index


*It wasn't empty. Didn't you see the blinking eye face?

by Solitaire (Login Solitaire1)
S

Posted on May 5, 2013, 5:36 PM

Respond to this message   

Return to Index


* Those don't count, major.

by Trapper John (Login The-Universe)
Admin

Posted on May 5, 2013, 5:42 PM

Respond to this message   

Return to Index


Major who?

by (Login burger2227)
R

Hot Lips?

Posted on May 5, 2013, 10:43 PM

Respond to this message   

Return to Index


Not who, who-lihan!

by Col Potter (Login The-Universe)
Admin

Get it together, Burns!

S.P.

Posted on May 6, 2013, 5:05 AM

Respond to this message   

Return to Index


EXIT SUB is nice.

by (no login)

So you can prevent executing malicious code left below, simplifying the tests of variables... test just once, do it and exit ; no care about the rest of code ; no Goto.

It's more and more difficult for me to program, maybe Alzheimer ; takes me ages to figure out a plan. A good thing to help newbies would be to focus on something like templates, useful for a general functions.

Cheers, L

Posted on May 5, 2013, 12:16 PM

Respond to this message   

Return to Index


Page flipping in QB64

by Edvard (no login)

why isn't page flipping working in QB64? What is wrong with my program? It is supposed to switch between two screens graphics, fist containing vertical lines and the other horizontal

SCREEN _NEWIMAGE(640, 480, 32), , 1, 1
FOR x = 0 TO 640 STEP 6
LINE (x, 0)-STEP(2, 480), _RGB(255, 255, 255), BF
NEXT
SCREEN , , 0, 0
FOR y = 0 TO 480 STEP 6
LINE (0, y)-STEP(640, 2), _RGB(255, 255, 255), BF
NEXT


DO
SCREEN , , 1, 1
_DELAY 1
SCREEN , , 0, 0
LOOP UNTIL INKEY$ = CHR$(27)
SYSTEM

Posted on May 5, 2013, 1:49 AM

Respond to this message   

Return to Index


Re: Page flipping in QB64

by (Login MCalkins)
Moderator

It is flipping, but then it is flipping back immediately.

change:

SCREEN , , 1, 1
_DELAY 1
SCREEN , , 0, 0

to:

SCREEN , , 1, 1
_DELAY 1
SCREEN , , 0, 0
_DELAY 1


I would suggest, that especially if you're going to use _NEWIMAGE modes, that you just use multiple images instead of "pages".


DIM handle(0 TO 1) AS LONG
DIM x AS LONG, y AS LONG

handle(0) = _NEWIMAGE(640, 480, 32)
handle(1) = _NEWIMAGE(640, 480, 32)
SCREEN handle(1)
FOR x = 0 TO 640 STEP 6
LINE (x, 0)-STEP(2, 480), _RGB(255, 255, 255), BF
NEXT
SCREEN handle(0)
FOR y = 0 TO 480 STEP 6
LINE (0, y)-STEP(640, 2), _RGB(255, 255, 255), BF
NEXT


DO
SCREEN handle(1)
_DELAY 1
SCREEN handle(0)
_DELAY 1
LOOP UNTIL INKEY$ = CHR$(27)
SYSTEM
'_FREEIMAGE handle(1)
'_FREEIMAGE handle(0)



You would also have access to things like _SOURCE and _DEST.

Regards,
Michael

Posted on May 5, 2013, 2:27 AM

Respond to this message   

Return to Index


Thanks

by Edvard (no login)

I can't believe I overlooked that little error. I think I meant to add _LIMIT like so.

SCREEN , , 1, 1
_DELAY .1
SCREEN , , 0, 0
_LIMIT 5

I wonder if it's possible to keep the delays in real time, such that the time it takes to actually flip the page isn't causing a delay beyond what's set.

Posted on May 5, 2013, 5:00 AM

Respond to this message   

Return to Index


you're welcome.

by (Login MCalkins)
Moderator

If it's any consolation, it took me a while to notice it also.

I'm not the best person to answer your other question. In theory, _LIMIT, or something like it, should be pretty good for maintaining a rough average, I think. Windows is not a real time operating system, so you are never guaranteed exact timing. Perhaps someone else can answer better.

Regards,
Michael

Posted on May 5, 2013, 5:44 AM

Respond to this message   

Return to Index


No biggie, but just learned something about integer division...

by (Login qb432l)
R

In a little text mode (that's right, Pete) money management program I wrote, I use integer division (\) in a sub program that prints results in $ format (PRINT USING is a tad unpredictable in QB64). In any case, I discovered an anomaly. I had an amount, 999.79 that was interpreted as an amount >= 1000. In other words, QB/QB64 round up when doing integer division. If the amount had been 999.49 it would have worked, but 999.5 and greater, rounds to 1000.

Like I say, no biggie, but something to be aware of.

-Bob

Posted on May 3, 2013, 9:59 AM

Respond to this message   

Return to Index


Yep, QB does that to coordinate and color values too

by (no login)

Because they require whole number values. You probably just forgot...

COLOR 11.5: PRINT "not color 11!"

PRINT USING rounds decimal point values by the number of decimal places too.



Posted on May 3, 2013, 2:11 PM

Respond to this message   

Return to Index


I didn't forget...

by (Login qb432l)
R

I just never knew it. To me, the "integer" in the operator's name just meant "the-number-of-times-this-number-can-be-found-whole-in-that-one", not that it was working exclusively in integers. As it is, the operator is semi-useless, since so many operations it's used in involve decimal fractions - and it's true of MOD, too.

'For example, this is what I thought Integer divison/MOD did ---

Amount = 9999.99
TestValue = 1000

Balance = Amount

CLS
PRINT
PRINT
PRINT "Amount being tested:"; Amount
PRINT

DO
IF Balance (less-than) TestValue THEN EXIT DO
Balance = Balance - TestValue
TestNum = TestNum + 1
LOOP

PRINT "Integer divison value:"; TestNum
PRINT "MOD value:"; Balance

END

'-Bob

Posted on May 3, 2013, 2:49 PM

Respond to this message   

Return to Index


Yes, interesting

by lawgin (no login)

I had always thought that x\y was the same as INT(x/y), but not the case as you pointed out.

Posted on May 3, 2013, 3:03 PM

Respond to this message   

Return to Index


You have no business doing business programs!

by Mr. Business (Login The-Universe)
Admin

Next time come to me. I'll be happy to give you the business!

Pete happy.gif

Posted on May 3, 2013, 4:54 PM

Respond to this message   

Return to Index


Integer division

by Solitaire (no login)

'Integer division seems to round out
'if first digit after the decimal point is a 9

CLS
A = 5.9
B = 6.6
C = 6.2
PRINT A / B
PRINT A \ B
PRINT A / C
PRINT A \ C

------------------------
Output is:
.8939394
0
.9516159
1

Posted on May 4, 2013, 8:41 AM

Respond to this message   

Return to Index


5.9 \ 6.2 = 1 That's just absurd, no matter how it's rationalized...

by (Login qb432l)
R

To me, integer division and MOD have very specialized purposes -- they shouldn't be merely "casual division for people who don't like decimals". How many 7's in 45? 6. How many 7's in 48.999999? 6.

Thanks, Solitaire.
-Bob

Posted on May 4, 2013, 11:11 AM

Respond to this message   

Return to Index


Here's a common use for integer division and MOD

by lawgin (no login)

CLS
PRINT "You have 316 donuts and 52 boxes. ": PRINT
PRINT "Put"; 316 \ 52; "donuts in each box"
PRINT "There are"; 316 MOD 52; "donuts left."
PRINT "Eat them."

Posted on May 4, 2013, 12:12 PM

Respond to this message   

Return to Index


Sure...

by (Login qb432l)
R

Unfortunately, that's all it's really reliable for. On the other hand, a better function (check my code in the post above, "I didn't forget..."), could also handle donuts.

-Bob

Posted on May 4, 2013, 12:28 PM

Respond to this message   

Return to Index


Re: Sure...

by lawgin (no login)

Integer division and MOD should be used with integer arguments. Your method finds the remainder when one or both arguments are non-integer.

Posted on May 4, 2013, 2:22 PM

Respond to this message   

Return to Index


*Of course -- the point is, my method also works with integers. Anyway, no biggie.

by (Login qb432l)
R

*

Posted on May 4, 2013, 6:10 PM

Respond to this message   

Return to Index


How to insure no matter what method you use you have zero donuts leftover...

by Pete (Login The-Universe)
Admin

Throw Pete into the equation!

Pete happy.gif

Posted on May 4, 2013, 12:46 PM

Respond to this message   

Return to Index


What do you get from eating too many jelly donuts?

by lawgin (no login)

A jelly belly.

Posted on May 4, 2013, 2:23 PM

Respond to this message   

Return to Index


Lawgin, I didn't open your post, but I'm going to bet it's...

by Pete (Login The-Universe)
Admin

... a jelly ache!

Pete happy.gif

Posted on May 4, 2013, 3:13 PM

Respond to this message   

Return to Index


*Close, but it's a rhyme, not a pun

by lawgin (no login)

Posted on May 4, 2013, 3:19 PM

Respond to this message   

Return to Index


Tried same code in VB.NET

by Solitaire (no login)

I got the same results, BUT only with Option Strict Off.
With Option Strict On, it refuses to convert type Single to type Long. That's because it would have to "narrow" the conversion, which could result in lost data.

So that's what seems to be happening with QB integer division. It's losing data because of a "narrow" conversion, from a greater range to a smaller one.

I tried using Integer values and got the correct result in both VB and QB:

99 / 100 comes to 0.99
99 \ 100 comes to 0

In C# (and all the C languages), Option Strict is always on (there is no such option to turn it off), and is even stricter than VB with Option Strict On. But QB lacks such an option.

Posted on May 4, 2013, 5:29 PM

Respond to this message   

Return to Index


*Interesting - thanks.

by (Login qb432l)
R

*

Posted on May 4, 2013, 6:07 PM

Respond to this message   

Return to Index


There is no integer division symbol in C

by Solitaire (no login)

Forgot to mention this in my above post. In the C family of languages, there is only one symbol for division. In order to do integer division , both operands need to be integers. If one or both operands are real (floating point) numbers, then regular division is performed. Unless a number is declared as double or float and assigned a value, then it is necessary to add .0 to the number if it doesn't happen to have a decimal portion, in order for it to be designated as a real number.

Posted on May 4, 2013, 9:40 PM

Respond to this message   

Return to Index


C++ allows some implicit type conversions.

by (Login MCalkins)
Moderator

Some conversions can be implicit, others must be explicit. C++ is stricter than C.

In the case of floating point to integer:

http://msdn.microsoft.com/en-us/library/fb7fdy7e.aspx


------

#include <stdio.h>

int intdiv(int x, int y) { return x / y; }

int main() {
printf("%i\n", intdiv(5.9 + .5, 6.2 + .5));
return 0;
}

------

Note the
+ .5
as C++ truncates instead of rounds. (Note that this still doesn't duplicate CLNG, as CLNG distinguishes between even and odd numbers in deciding which way to round. (Unless I'm mistaken, CLNG reflects the x87 hardware.))

Compile with:
QB64 SDL:
internal\c\bin\g++ -O3 -s -Wall delme.cpp -o delme.exe
QB64 GL:
internal\c\c_compiler\bin\g++ -O3 -s -Wall delme.cpp -o delme.exe
MSVC++:
cl /O2 /MD /Wall delme.cpp

QB64 SDL's g++ compiles it without warning or error.

cl compiles it without error, but with warnings, including:

\c\delme.cpp(6) : warning C4244: 'argument' : conversion from 'double' to 'int',
possible loss of data
\c\delme.cpp(6) : warning C4244: 'argument' : conversion from 'double' to 'int',
possible loss of data

c:\c\delme.cpp(6) : warning C4711: function 'int __cdecl intdiv(int,int)' select
ed for automatic inline expansion

Regards,
Michael

Posted on May 5, 2013, 3:25 AM

Respond to this message   

Return to Index


Re: Integer division (Edited. changed CINT to CLNG)

by (Login MCalkins)
Moderator

Thanks to TheBOB for pointing this out. If I knew this, I had forgotten it.

floatnumber \ floatnumber

I believe is the same as:

CLNG(floatnumber) \ CLNG(floatnumber)

So, as Solitaire pointed out, the conversion to integer is done before the division.

I use \ and MOD fairly often. But I do so with integer data types. (I very rarely use floats at all.)

It should be noted that division tends to be slower than multiplication on hardware. Therefore floating point multiplication should be preferred over floating point division.

Integer division would usually be done by the x86 processor using the DIV or IDIV instructions. These do both integer division and modulus at the same time.

Float division can be done with the x87 FPU using the FDIV, FDIVP, FDIVR, or FDIVRP instructions.

I just noticed that the x87 FPU also has FIDIV and FIDIVR:

----- from old nasm doc:
`FIDIV' divides `ST0' by the 16-bit or 32-bit integer stored in the
given memory location, and stores the result in `ST0'. `FIDIVR' does
the division the other way up: it divides the integer by `ST0', but
still stores the result in `ST0'.
-----

I wouldn't assume that to mean that it is integer division. More likely, it is just dividing by an integer.

If a compiler can see that you are dividing or multiplying by a constant power of 2, it can change it to a bit shift operation.

Likewise, a MOD by a constant power of 2 can become an AND operation.

A compiler could optimize a multiplication by a constant 3 into a left shift and an add.

Regards,
Michael

P.S. Because BASIC lacks bit shift operators, I tend to use \ and * as substitutes.

Posted on May 5, 2013, 2:48 AM

Respond to this message   

Return to Index


CINT and CLNG, rounding mode

by (no login)

CINT or CLNG: The manual says: "Converts a numeric expression to an integer
(or long integer) by rounding the fractional part of the expression."
Not stated, but the rounding mode used is Bankers' Rounding.

Regards..... Moneo

PS: Taken from my rounding tutorial MONEORND.DOC

Posted on May 18, 2013, 4:35 PM

Respond to this message   

Return to Index


Yes.

by (Login MCalkins)
Moderator

Which happens to be the default rounding mode of the x87 FPU.

The code below changes the rounding mode in the x87 control word. It seems to have no effect on CLNG in QBASIC 1.1 or compiled programs in QB 4.5. However, if you run the program from the QB4.5 IDE (without compiling), the middle one is a 3 instead of a 4.

(The x87 control word also controls floating point exception masking.)

Regards,
Michael

DECLARE FUNCTION h2b$ (h AS STRING)
CLS
TYPE codetype
 storecontrolword  AS STRING * 17
 loadcontrolword AS STRING * 20
END TYPE

DIM oldword AS INTEGER
DIM newword AS INTEGER
DIM t AS STRING
DIM code AS codetype

t = "55" '             push bp
t = t + "89E5" '       mov bp,sp
t = t + "1E" '         push ds
t = t + "53" '         push bx
t = t + "C55E06" '     lds bx,[bp+6]
t = t + "9BD93F" '     fstcw [bx]
t = t + "5B" '         pop bx
t = t + "1F" '         pop ds
t = t + "C9" '         leave
t = t + "CA0400" '     retf 4

code.storecontrolword = h2b(t)

t = "55" '             push bp
t = t + "89E5" '       mov bp,sp
t = t + "1E" '         push ds
t = t + "53" '         push bx
t = t + "C55E06" '     lds bx,[bp+6]
t = t + "9BDBE2" '     fclex
t = t + "9BD92F" '     fldcw [bx]
t = t + "5B" '         pop bx
t = t + "1F" '         pop ds
t = t + "C9" '         leave
t = t + "CA0400" '     retf 4

code.loadcontrolword = h2b(t)
DEF SEG = VARSEG(code)

PRINT CLNG(3.5)

CALL absolute(SEG oldword, VARPTR(code.storecontrolword))
newword = oldword OR &HC00
CALL absolute(SEG newword, VARPTR(code.loadcontrolword))

PRINT CLNG(3.5)

CALL absolute(SEG oldword, VARPTR(code.loadcontrolword))

PRINT CLNG(3.5)
SYSTEM

FUNCTION h2b$ (h AS STRING)
 DIM i AS INTEGER
 DIM t AS STRING
 t = SPACE$(LEN(h) \ 2)
 FOR i = 0 TO LEN(h) \ 2 - 1
  MID$(t, 1 + i, 1) = CHR$(VAL("&h" + MID$(h, 1 + 2 * i, 2)))
 NEXT
 h2b = t
END FUNCTION

Posted on May 18, 2013, 5:57 PM

Respond to this message   

Return to Index


Re: Yes.

by (no login)

Michael,

Thanks for the info.

It's amazing how you can whip out assembler code at the drop of a hat.

Regards.....Moneo

Posted on May 19, 2013, 11:15 AM

Respond to this message   

Return to Index


Integer Division, rounding mode

by (no login)

INTEGER DIVISION: The manual says: "Before integer division is performed,
operands are rounded to integers or long integers..."
Not stated, but the rounding mode used is Bankers' Rounding.

Regards..... Moneo

Posted on May 18, 2013, 4:26 PM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement