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.

DarkBASIC Discussion / INSTR() Function and why is it not there?

Author
Message
jjarmis
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location:
Posted: 29th Sep 2003 02:50 Edited at: 29th Sep 2003 02:53
Hi I am new to DB and have version 1.11 demo. I am interested in why the INSTR() function is not in DB and if there is a way to do the same thing with current DB commands. If anyone can help me workaround this please do.

Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 29th Sep 2003 03:13 Edited at: 29th Sep 2003 03:14
Ah yes! One of those DB and DBPro mysteries, the missing Instr() command. No Idea why it's not there.

Here's a Instr() function I made some time ago with the help of another function I made some time before that, Midstr()



Hope this helps

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Sep 2003 03:32
No INSTR as such, but many ways to skin the same cat. As a gaming language, it's probably not that high up the wish list.

I think somebody wrote a DLL to do this, most likely TAtoad or TCA.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Sep 2003 01:34
They're both pretty easy functions to write. Most programming classes that I know of teach you that early on.
bruceatk
21
Years of Service
User Offline
Joined: 25th Aug 2003
Location: Loudon, NH
Posted: 2nd Oct 2003 20:26
To me that is an important function to have built in. The InStr function is usually extremely fast. Reproducing it in basic is much slower.

In Visual Basic it is possible to read in entire files into one string very quickly and then easily/quickly search using instr.

Example:

' Retrieve entire file into string

open "whatever.txt" for binary as #1
strBuff = space(lof(1)) 'set strBuff to the length of the file.
get #1,,strBuff
close #1

location = instr(strBuff,SearchText)

Using these commands it's actually quite easy to use a text or binary file as a small database for your game. It takes more work in DB.

Bruce

Login to post a reply

Server time is: 2025-05-20 17:31:37
Your offset time is: 2025-05-20 17:31:37