[Not Bug] FindString find not the string

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

[Not Bug] FindString find not the string

Post by Kwai chang caine »

Hello

Is it normal ?? :shock:

Code: Select all

Debug FindString("a", "A", #PB_String_NoCase)
Result 0
I have try v5.22 and 5.30 it's the same thing
If i remove #PB_String_NoCase that's works

Good day
Last edited by Kwai chang caine on Tue Sep 09, 2014 2:34 pm, edited 3 times in total.
ImageThe happiness is a road...
Not a destination
User avatar
majikeyric
Enthusiast
Enthusiast
Posts: 187
Joined: Mon Oct 21, 2013 5:21 pm
Location: France
Contact:

Re: FindString find not the string

Post by majikeyric »

Hey KCC,
you have forgotten one parameter (the start position).
:mrgreen:

Code: Select all

Debug FindString("a", "A",1, #PB_String_NoCase)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FindString find not the string

Post by Kwai chang caine »

Aaaaarrrrrggghhh !!!!
It's not the first time :oops: :oops:

FREEEEED !!!! Please ....a protection, is really wellcome :wink:

Thanks a lot MAJIKEYRIC 8)

Have a very good day :wink:
Last edited by Kwai chang caine on Tue Sep 09, 2014 3:04 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: [Not Bug] FindString find not the string

Post by blueb »

I still think there's something wrong....

The help file states: ' If this parameter isn't specified, the whole string is searched. '

KCC's results show that this is not the case.
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: FindString is accepting a string as an Int parameter

Post by Tenaja »

I ran into this myself just last week. (Fortunately I sorted it out within a few minutes.)

The bug is that you are using a string as an argument for an Int, and the compiler is not throwing an error.
Last edited by Tenaja on Tue Sep 09, 2014 3:12 pm, edited 1 time in total.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: [Not Bug] FindString find not the string

Post by c4s »

blueb wrote:The help file states: ' If this parameter isn't specified, the whole string is searched. '

KCC's results show that this is not the case.
Well, in KCC's case #PB_String_NoCase (= 1) is the start position. The parameter "isn't specified" if something like FindString("a","a") is used.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: [Not Bug] FindString find not the string

Post by netmaestro »

This crops up every so often with different commands, if you specify an optional parameter that appears later in the list, all other optional params that appear before it have to be specified too. Personally, I'd like to see Fred make this syntax legal:

Code: Select all

Debug FindString("a","A",,#PB_String_NoCase)
instructing the command to use the default for the first optional parameter while specifying the second. This way the coder doesn't have to read up on all the optional parameters and supply values for them. Who likes reading documentation anyway? Ick.
BERESHEIT
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [Not Bug] FindString find not the string

Post by davido »

@netmaestro,
+1
Thanks, perhaps you will be heard.
DE AA EB
Fred
Administrator
Administrator
Posts: 18179
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Not Bug] FindString find not the string

Post by Fred »

While I understand the optional proposal, how would it help in this case ?

May be a solution would be to change the constant values to negative one, so we could introduce a runtime debugger check to check this.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [Not Bug] FindString find not the string

Post by wilbert »

Fred wrote:May be a solution would be to change the constant values to negative one, so we could introduce a runtime debugger check to check this.
I doubt if that will solve anything. If you take PeekS for example
PeekS(*MemoryBuffer [, Length [, Format]])
Length can both be positive or negative (-1).
So if you accidentally forget to specify Length and only specify Format, sign checking won't work.
Windows (x64)
Raspberry Pi OS (Arm64)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: [Not Bug] FindString find not the string

Post by PB »

This command doesn't really need fixing; it was just user error.

But if anything: maybe swap the start position and mode flags,
because that way KCC wouldn't have had any error, and the
starting position is likely always going to be 1 in most cases
anyway, which means it should be optional? I don't know.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: [Not Bug] FindString find not the string

Post by Thade »

+10 PB
PB wrote:But if anything: maybe swap the start position and mode flags
Yes and not only in this case ... no special function ready at present ... but I often think, why is this Parameter at the end of 3 optional parameters, when it is the most important and has to be the first while the other parameters are not touched anyway ... you often have to look up what the default parameters are to fill them in, when you only need the last one changed.
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
User avatar
skywalk
Addict
Addict
Posts: 4215
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [Not Bug] FindString find not the string

Post by skywalk »

Changing the order of parameters breaks lots of code.
I prefer the blank optional parameters request similar to netmaestro.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: [Not Bug] FindString find not the string

Post by Thade »

skywalk wrote:Changing the order of parameters breaks lots of code.
I prefer the blank optional parameters request similar to netmaestro.
True and an important aspect.
The other idea (sort options by importance) is therefore better kept in mind when developing new functions.
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: [Not Bug] FindString find not the string

Post by Foz »

Just as a thought, but what if it was possible to say, all functions *have* to define all parameters, i.e. EnableExplicitParameters.

Personally I detest optional parameters, because (imho) it encourages bad coding practice, such as the same function doing completely different things, depending on the parameters and *how many parameters* I pass in!

Instead of spending more time up front, creating more functions that describe what that function actually does, and changing the appropriate places, it's covered over with quick and dirty programming, which then comes back to bite you on the backside when a function does something unexpected, or even worse, when the parameters have to change.

And yes, I have been bitten by this problem more times than I care to regale.
Post Reply