Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Some Functions For You

Author
Message
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 20th Nov 2002 02:57
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)




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)



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)




FlipStr()
Simply Reverses contents of source$

Syntax
Return String = Flipstr(source$)




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)




RoundBox()
A slightly modified version of the Box() command where you can draw boxes with rounded corners.

Syntax
RoundBox(left, top, right, bottom, cornerradius)




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)


"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 20th Nov 2002 03:08
sorry, MessageBox() did not copy correctly, will fix, back soon.....

"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 20th Nov 2002 03:33
Ok, hope it's copied properly now, here goes, fingers crossed...




...and it's support function.




"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
ironhoof
21
Years of Service
User Offline
Joined: 3rd Sep 2002
Location:
Posted: 20th Nov 2002 04:33
I made a string library with over 120 functions I dont think there is a DB programmer alive that hasn't improved upon the missing DB string statements.

-----\
There was a man on the stairs that wasn't there.
He wasn't there agian today I think he's from the CIA.
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 22nd Nov 2002 20:30
You just need replacestr$() now!

I love Star Trek.
Especially the Episodes with Starships in.
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 22nd Nov 2002 22:49
Dang!, I knew i forgot one, so here it is

Replacestr()
Replaces any fragment of source$ with a replacement.
check$ is the string fragment to replace (if present).
replace$ is the replacement.
ignorecase, will do just that.

example: Replacestr("Raining Cats And Dogs","Cats","Elephants",0) will return "Raining Elephants and dogs" ( I would'nt like to see that )

Requires Instr() and Midstr() functions.



"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 22nd Nov 2002 23:18
Thanks, I've been needing a DBP compatible one for the programming language (made in DBP).

I love Star Trek.
Especially the Episodes with Starships in.

Login to post a reply

Server time is: 2024-03-29 14:41:21
Your offset time is: 2024-03-29 14:41:21