Ok, here are a few functions that may or may not be useful to you.
Instr()This is one of those standard BASIC commands that for some mysterious reason has not been included in DBPro, or any other version of DB. I wonder why?
It will return the position of check$ in source$. By changing startpos you can choose where Instr() begins the search in source$. Set ignorecase to 1 to, well... ignore case

example: Instr("Raining Cats and Dogs","Cats",1,1) will return 9
Requires Midstr() to work.
Syntax
Return Integer = Instr(source$, check$, startpos, ignorecase)+ Code Snippetfunction Instr(source$,check$,startpos,ignorecase)
rem --- Requires Midstr() function
if ignorecase 0
source$ = lower$(source$)
check$ = lower$(check$)
endif
repeat
if Midstr(source$,startpos,len(check$)) = check$ then exitfunction startpos
inc startpos,1
until startpos > len(source$)
endfunction 0
Midstr()An slightly extended version of Mid$() where you can set the length of return.
example: Midstr("Raining Cats and Dogs",9,4) will return "Cats"
Syntax
Return String = Midstr(source$, pos, length)+ Code Snippetfunction Midstr(source$,pos,length)
t$ = left$(right$(source$,len(source$)-(pos-1)),length)
endfunction t$
Shiftstr()Will shift the contents of source$ 1 place with carry. Set shift to 1 to shift left or 0 for right.
Syntax
Return String = Shiftstr(source$, shift)+ Code Snippetfunction Shiftstr(source$,shift)
if shift = 0
rem --- shift right
t$ = right$(source$,1) + left$(source$,len(source$)-1)
else
rem --- shift left
t$ = right$(source$,len(source$)-1) + left$(source$,1)
endif
endfunction t$
FlipStr()Simply Reverses contents of source$
Syntax
Return String = Flipstr(source$)+ Code Snippetfunction Flipstr(source$)
for i = len(source$) to 1 step -1
t$ = t$ + mid$(source$,i)
next i
endfunction t$
CircleFill()Draws filled circles or ellipses. There are more accurate ways of drawing circles, but this is one of the fastest.
Have you noticed how badly DBPro draws circles?
Syntax
Circlefill(xcenter, ycenter, xradius, yradius)+ Code Snippetfunction CircleFill(xcenter,ycenter,xradius,yradius)
rem --- find vertical ratio to help draw ellipses
xr# = xradius : yr# = yradius
vr# = yr# / xr#
r2 = xradius^2
for x = 1 to xradius
y = sqrt(r2 - x^2) * vr#
box xcenter - x, ycenter - y, xcenter + x, ycenter + y
next x
endfunction
RoundBox()A slightly modified version of the Box() command where you can draw boxes with rounded corners.
Syntax
RoundBox(left, top, right, bottom, cornerradius)+ Code Snippetfunction RoundBox(left,top,right,bottom,cornerradius)
if cornerradius = 0
box left,top,right,bottom
else
cornerradius = abs(cornerradius)
inc left, cornerradius
inc top, cornerradius
dec right, cornerradius
dec bottom, cornerradius
r2 = cornerradius^2
for x = 1 to cornerradius
y = sqrt(r2 - x^2)
box left - x, top - y, right + x, bottom + y
next x
endif
endfunction
MessageBox()Displays a basic Windows like message box in the center of the current bitmap and returns button number clicked.
width, height defines the size. Note: Any text that is too long is clipped if MessageBox() is to small.
title$ is the erm...title.
txt$ can be divided into sepereate lines with the | character, so "line 1|line 2|line 3" will display 3 lines of text.
butt$ are the buttons which are divided in the same way, so "OK|Cancel" will display two buttons.
Setting centertitle or centertxt to 1 will center justify, 0 will left justify.
minbuttsize will force a minimum width for your buttons, set to 0 to accept largest width defined in butt$.
Will return -1 if MessageBox() fails.
Requires DrawBoxText()
Limitations of use:
Uses image 65535 as a backsave. Not realy a limitation but I mention it anyway.
Will halt your program until user clicks a button.
I could do more with the MessageBox(), but if used properly it's fine as it is.
Syntax
Return Integer = MessageBox(width, height, title$, txt$, butt$, centertitle, centertxt, minbuttsize)+ Code Snippetfunction MessageBox(width,height,title$,txt$,butt$,centertitle,centertxt,minbuttsize)
rem --- Requires DrawBoxText() funtion ---
rem --- parameter checks
if (width=0) or (height=0) then exitfunction -1
if title$="" then title$ = "Message Box"
if butt$="" then butt$="OK"
width = abs(width) : height = abs(height)
left = (bitmap width() - width) / 2 : if left = bitmap width() then right = bitmap width()-1
bottom = top + height : if bottom >= bitmap height() then bottom = bitmap height()-1
th = text height(txt$)
y = top + th + 2
rem --- set array for a maximum of 10 buttons, probably wont need this many
dim b$(9)
rem --- preserve current user text settings
txtstyle = text style() : txtback = text background type()
set text transparent
set text to normal
rem --- store backsave
Get image 65535,left,top,right+1,bottom+1,1
rem --- draw body
DrawBoxText(left,y,right,bottom,"",0,rgb(200,200,200),rgb(255,255,255),rgb(16,16,16),rgb(255,255,255))
rem --- draw title bar
DrawBoxText(left,top,right,y,title$,centertitle,rgb(0,0,200),rgb(255,255,255),rgb(16,16,16),rgb(255,255,255))
rem --- show text
DrawBoxText(left+1,y+1,right-1,bottom - th - 4,txt$,centertxt,rgb(160,160,160),rgb(16,16,16),rgb(255,255,255),0)
rem --- buttons in b$()
pos = len(butt$) : lastpos = pos
repeat
repeat
dec pos,1
until pos = 0 or mid$(butt$,pos) = "|"
b$(i) = left$(right$(butt$,len(butt$)-pos),lastpos-pos)
lastpos = pos
if (text width(b$(i)) > buttwidth) then buttwidth = text width(b$(i))
inc i,1
until pos = 0 or i = 10
if buttwidth ""
buttright = right - (buttwidth * i) - 4
buttleft = buttright - buttwidth + 4
if buttright >= left+4
if buttleft = left and mousex() = (bottom - th - 2) and mousey() ""
ink txtcol,0
th = text height(txt$)
x = left + 4 : y = top
centerx = left + ((right - left) / 2)
pos = 0 : lastpos = 0
repeat
repeat : inc pos,1 : until pos > len(txt$) or mid$(txt$,pos) = "|"
t$ = left$(right$(txt$,len(txt$)-lastpos),(pos-1)-lastpos)
lastpos = pos
rem --- clip text if too long
if text width(t$) > (right - left)
tw = 0 : lp = 0
repeat : inc lp,1 : tw = tw + text width(mid$(t$,lp)) : until tw > (right - left)
t$ = left$(t$,lp-1)
endif
rem --- display text
if centertxt = 0 then text x,y,t$ else center text centerx,y,t$
inc y,th
until pos > len(txt$) or (y+th) > bottom
endif
endfunction