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 Professional Discussion / Problem searching a string with INSTR (IanM's plugin)

Author
Message
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 13th Jul 2003 00:36
I am trying to use IanM's INSTR function that comes with the ?Matrix1 plugin.

I have an array, ServerBank$(100, 100), that I want to search through. I only want to search through ServerBank(a, 1) (ie. the 100 entries that have a y coordinate of 1).

The text that I want to search for is in TempString$. If it finds the string in ServerBank$, then I would like it to store the position (a) of that string in another array called TempStorage(100)
This is because I will need to know how many times the string is found and at what location in the array they were found.

I have isolated the following code as the problem.....it causes the game to exit.



Where have I gone wrong?
http://www.aopr79.dsl.pipex.com/tinywars/images/signature.jpg[/img]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jul 2003 00:48
Spotted it - DBPro doesn't initialise strings, so that means that if the value you are comparing has not been set, it's a null pointer.

Quick fix until I fix the plug-in:

TempSearch = INSTR(ServerBank$(a, 1)+"", TempChoice$)
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 13th Jul 2003 01:12 Edited at: 13th Jul 2003 01:14
Thanks for the speedy reply. I have made the change and it no longer crashes. However, I can't get the routine to work still. Maybe you can help?

Say I populate ServerBank$ very sparsley like so:

ServerBank$(1, 1) = "crapbank.com"
ServerBank$(2, 1) = "mail.com"
ServerBank$(3, 1) = "news.com"
ServerBank$(4, 1) = "betterbank.com"

I want the user to be able to search this array to see if the 'server' they want to connect to exists. This is stored in TempChoice$

I am trying to write a routine that will search through ServerBank$(x, 1) looking for that string. I then want to be able to record which x value each successful match was at. For instance, if TempChoice$ is "bank" I would like the routine to record the numbers 1 and 4 (as (1, 1) and (4, 1) both contain the word bank in their string).

I was trying to store these numbers in a separate array called TempStorage. So, for instance,
TempStorage(1) = 1 and TempStorage(2) = 4, in this case

I am assuming that if the search string is present in the source string (I think TempChoice$ is the search string and ServerBank$ is the source?) then INSTR will return an integer other than 0?

What is wrong with this code then?



IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jul 2003 02:01
Basically, your not exiting the inner loop when you find an empty slot.

Try this instead - I think it's more inkeeping with what you're after:



Oh, and the plug-in is now fixed and available from my site in source and executable-only packages
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 13th Jul 2003 02:44
Thankyou so much Ian!

Don't know how I missed that one....must be a sign that I need more coffe

Login to post a reply

Server time is: 2026-07-21 12:49:42
Your offset time is: 2026-07-21 12:49:42