' ========================================================================================
' Force modulus x into the range a..b for Real Numbers
' ========================================================================================
Function cmMod3(ByVal x as Double, _
ByVal a as Double, _
ByVal b as Double) as Double
If a = b Then
Function = x
Else
Function = a + (cmMod(x - a,b - a))
EndIf
End Function
' ========================================================================================
' x MOD y for Real Numbers, y<>0
' ========================================================================================
Function cmMod(ByVal x as Double, _
ByVal y as Double) as Double
Function = x - y * cmFloor(x / y)
End Function
' ========================================================================================
' Return smallest integer greater than or equal to x
' ========================================================================================
Function cmCeiling(ByVal x as Double) as Long
Function = -cmFloor(-x)
End Function
' ========================================================================================
' Return largest integer less than or equal to x
' ========================================================================================
Function cmFloor(ByVal x as Double) as Long
Function = Int(x)
End Function
Last edited by rpkelly on Jun 27, 2018 2:07, edited 1 time in total.
I'll contribute a couple of thousand indispensable functions for every Windows FB programmer. If you are not using this library then you are certainly missing out on a lot.
A magistrate's warrant has been issued ordering you to remove one item of clothing for citing José Roca's superb WinFBX Framework in a thread entitled 'Useful defines'. Failure to comply may result in a custodial sentence of no more than 90 days. <smile>
deltarho[1859] wrote:Hi Rick - haven't seen you for a while.
Been traveling, tying fishing flies, and of course, fishing. I'll be up in Alaska in Aug chasing those pretty arctic grayling with my son.
Now, I'm a bit behind on my FB efforts. We'll get cCalendar done with the addition of an IANA based time zone class and then my SQLite class that will have both a client and TCP based server class. That server class has a challenge to figure out how to support a connection pool without prior knowledge of the databases the client may want with attachments in addition to designing some kind of stored procedure that functions like that on MS SQL Server.
During all this, Paul looks likely to have his new IDE ready for some work and I'll get into that as well.
I typically use GETMOUSE the same way every time. I find these #defines helpful to check mouse button combinations, like I am looking for left-mouse-button-down and right-mouse-button-released, or whatever. I included a little demo; ESCAPE to quit.
'' useful defines for mouse buttons
#define MB_LEFT 1
#define MB_RIGHT 2
#define MB_MIDDLE 4
#define MB_IsUp(b_) ((mb and (b_))<>0)
#define MB_IsDown(b_) ((mb and (b_))=0)
#define MB_Pressed(b_) (((not omb and mb) and (b_))<>0)
#define MB_Released(b_) (((omb and not mb) and (b_))<>0)
#define MB_Changed(b_) (((omb xor mb) and (b_))<>0)
'' demo
dim as integer mx, my, mz, mb, omb
dim s as string
do
omb = mb
GetMouse mx, my, mz, mb
s = "LEFT:"
if MB_Changed(MB_LEFT) then s += " C" else s += " "
if MB_IsUp(MB_LEFT) then s += " U" else s += " "
if MB_IsDown(MB_LEFT) then s += " D" else s += " "
if MB_Pressed(MB_LEFT) then s += " P" else s += " "
if MB_Released(MB_LEFT) then s += " R" else s += " "
print s;
s = " -- RIGHT:"
if MB_Changed(MB_RIGHT) then s += " C" else s += " "
if MB_IsUp(MB_RIGHT) then s += " U" else s += " "
if MB_IsDown(MB_RIGHT) then s += " D" else s += " "
if MB_Pressed(MB_RIGHT) then s += " P" else s += " "
if MB_Released(MB_RIGHT) then s += " R" else s += " "
print s
'' slow down printing
sleep 100,1
loop until multikey(1)
' ========================================================================================
' Force modulus x into the range a..b for Real Numbers
' ========================================================================================
Function cmMod3(ByVal x as Double, _
ByVal a as Double, _
ByVal b as Double) as Double
If a = b Then
Function = x
Else
Function = a + (cmMod(x - a,b - a))
EndIf
End Function
' ========================================================================================
' x MOD y for Real Numbers, y<>0
' ========================================================================================
Function cmMod(ByVal x as Double, _
ByVal y as Double) as Double
Function = x - y * cmFloor(x / y)
End Function
' ========================================================================================
' Return smallest integer greater than or equal to x
' ========================================================================================
Function cmCeiling(ByVal x as Double) as Long
Function = -cmFloor(-x)
End Function
' ========================================================================================
' Return largest integer less than or equal to x
' ========================================================================================
Function cmFloor(ByVal x as Double) as Long
Function = Int(x)
End Function
#define map(a,b,x,c,d) ((d)-(c))*((x)-(a))/((b)-(a))+(c)
#define dmod(x,y) (y)*frac((x)/(y))
screen 19
for x as long=350 to 450 step 5
var newx=map(350,450,x,0,800)
line(x,100)-(newx,500)
next
locate 5
print dmod(20*atn(1)-.05,4*atn(1))
#include "crt.bi"
print fmod(20*atn(1)-.05,4*atn(1))
sleep