a=b with strings for foxpro users

For anyone coming from old foxpro. Just be aware -:

dim a=“test”
if a=“TEST”

  • Xojo will return true

use strcompare for case sensitive comparisons.

unless anyone out there knows a quicker way == would be nice!

not sure what you mean by “quicker”… faster execution? less typing?

dim a="test"
If StrComp(a,"TEST",0)<>0 Then // different include CASE

took me a while to get used to this… but I rarely run across a need to really case about case level comparison in most cases
so its quicker not having to debug code because your literal isn’t the same case as your input (except when you DO care)

You can create an Extends function for a string that will make this easier for you. Something like:

Function Matches (Extends src As String, compareTo As String) As Boolean
  return StrComp( src, compareTo, 0 ) = 0
End Function

After that, it’s just a matter of typing something like:

if x.Matches( y ) then…

Or you can get my M_String module which has this included.

[quote=240434:@dave duke]yeah , in my old foxpro = means equal / identical.
I would much rather

a==b
than

StrComp(a,b,0)<>0 Then

Much easier to read[/quote]
I agree with the == thing, but did you know it’s === in php? :stuck_out_tongue:

Don’t hold your breath… :slight_smile:

== or === is going to enter the same discussion arena as ++ and – and x+=1 etc… [see recent past posts on this forum]

And personally I think XOJO has enough “fixes” on their plate that are more important that making XOJO do something a particular way just because “so-and-so does it that way”

I personally believe in full macro support so that we can write programs like this:

#include <stdio.h>
#define _$()                                         0
#define __$()                                        1
#define _$_()                                        10
#define $_$(a)                                       a;
#define $_(b,a)                                     a##b
#define r(a,b)                                  r##a##b##urn 0;
#define m(b,a,x) };                               m##a##b##n
#define $(b,a,x)                                  a##b##x
#define                                         ____ + __
#define $_$_                                         =
#define __(...)  (                              $(n,i,t))(\\
$(ze,si,of)(($(n,i,t)[]) { _$(), ##__VA_ARGS__})/$(ze,si,of) ($(n,i,t))-__$())
$(n,i,t)  (*___)   ($(n,i,t))  = $(tch,  pu,  ar);   $(ub,do,le) _<::> $_$_ <%

         -2, 1, -1.3, 1.3     /* <-- Configure here: X1, X2, Y1, Y2 */

,_$(), _$(),_$(),_$(),_$() ,_$(), __( ',',',',',' ,',' ,',')  * _$_() ,( _$_()
- __('_','_')) * _$_(), _$(),_$(),_$(),__('_','_')*__('_','_', '_','_', '_') *
__('_','_', '_','_', '_')*__('_','_', '_','_', '_')+__('_','_', '_','_' , '_')
,__('_','_','_','_','_','_','_','_',), _$() m(i,a,u)($(n,i,t) $_)<% $_ (f,i) (
$_ $_(=,=) __(_) ) $_$($_(f,i)(_[ _$_()____(_,_) ]>_[ _$_()] )_[_$_()____ (_,_
,_,_,_,_,_)] $_$_ __(_) )$_(f,i)(_[_$_()____(_ ,_ ,_)] >_[  _$_()+ __$() ]  ||
_[_$_()____(_,_,_,_,_,_,_)] $_ (=,=) __$()) r(e,t) _[__(_,_,_ ,_,_ ,_)] $_$_ _
[__ (_,_,_,_,_,_,_)____(_,_,_,_,_,_) ]/_[__(_,_,_,_,_) ____(_,_,_,_,_,_)]*( _[
  __$()]-_[_$()])+_[ _$() ];_[__(_,_,_,_,_,_,_)] $_$_ _[__(_,_,_,_,_,_,_) ____
(_,_,_,_,_)]/_[_$_()]*(_[__(_,_,_,)]-_[__(_,_,)] )+_[__(_,_,)];_[__(_,_,_,_, _
,_,_,_)] $_$_ _[_$_() - __$()] $_$_ _[__(_,_,_,_,_)+ _$_()-__$()]  $_$_  _$();
_f:_[__(_,_,_,_)]  $_$_  _[__( _,_,_,_, _,_,_, _)] * _ [__(_,_,_, _,_,_,_,_)];
_[__(_,_,_,_,_)] $_$_ _[_$_() - __$()]*_[_$_() - __$()];_[__(_,_,_,_,_,_,_,_,_
)] $_$_ __(_,_)*_[__(_,_,_,_,_,_,_,_)]*_[_$_() -__$()]+ _[__ (_,_,_,_,_,_,_)];
_[__(_,_,_,_,_,_,_,_)] $_$_ _ [ __(_,_,_,_) ]-_[__(_,_,_,_,_)]+_[__(_,_,_,_,_,
_)];$_$(_[_$_()____(_,_,_,_,)]++)$_(f,i)((_ [_$_() ____ (_,_,_,_,)]< _ [_$_ ()
____ (_,_,_,_,_)])&&(_[__(_,_,_,_)]+ _[__(_,_,_,_,_)]<_[_$_()____(_,_,_,_,_,_)
])) $_(to,go) _f; $_(ar,ch) $(m,i,au)[] $_$_ <% __(_,_,_) * _$_()____(_,_), __
(_,_,_,_) * _$_()____(_,_,_),__(_,_,_,_,_,_) * _$_()____(_,_,_,_), __(_,_,_,_)
*_$_() ____(_,_,_,_,_),__(_,_,_,_) * _$_() ____(_,_,_,_,_,_),__(_,_,_,_) * _$_
()____(_,_) %>;___($(m,i,au)[($(n,i,t)) _[_$_()____(_,_,_,_)]%__(_,_,_,_,_)]);
$_$(_[__(_,_ ,_,_ ,_,_,_) + __(_,_,_,_,_,_)]++){m(i,a,u) ( _$()) ;$_$ (_[_$_()
____(_,_)]++)$_$(_[_$_()____(_,_,_)] $_$_ _$()) $_(f,i)(_ [__(_,_,_,_,_,_,_) + 
_$_()] != __(_)) ___(_$_()) ;{  m(i,a,u)(__$()); r(e,t)    /* IOCCC 2014*/  %>

(from the 2015 IOCC)

[quote=240453:@Tim Jones]I personally believe in full macro support so that we can write programs like this:

#include <stdio.h>
#define _$()                                         0
#define __$()                                        1
#define _$_()                                        10
#define $_$(a)                                       a;
#define $_(b,a)                                     a##b
#define r(a,b)                                  r##a##b##urn 0;
#define m(b,a,x) };                               m##a##b##n
#define $(b,a,x)                                  a##b##x
#define                                         ____ + __
#define $_$_                                         =
#define __(...)  (                              $(n,i,t))(\\
$(ze,si,of)(($(n,i,t)[]) { _$(), ##__VA_ARGS__})/$(ze,si,of) ($(n,i,t))-__$())
$(n,i,t)  (*___)   ($(n,i,t))  = $(tch,  pu,  ar);   $(ub,do,le) _<::> $_$_ <%

         -2, 1, -1.3, 1.3     /* <-- Configure here: X1, X2, Y1, Y2 */

,_$(), _$(),_$(),_$(),_$() ,_$(), __( ',',',',',' ,',' ,',')  * _$_() ,( _$_()
- __('_','_')) * _$_(), _$(),_$(),_$(),__('_','_')*__('_','_', '_','_', '_') *
__('_','_', '_','_', '_')*__('_','_', '_','_', '_')+__('_','_', '_','_' , '_')
,__('_','_','_','_','_','_','_','_',), _$() m(i,a,u)($(n,i,t) $_)<% $_ (f,i) (
$_ $_(=,=) __(_) ) $_$($_(f,i)(_[ _$_()____(_,_) ]>_[ _$_()] )_[_$_()____ (_,_
,_,_,_,_,_)] $_$_ __(_) )$_(f,i)(_[_$_()____(_ ,_ ,_)] >_[  _$_()+ __$() ]  ||
_[_$_()____(_,_,_,_,_,_,_)] $_ (=,=) __$()) r(e,t) _[__(_,_,_ ,_,_ ,_)] $_$_ _
[__ (_,_,_,_,_,_,_)____(_,_,_,_,_,_) ]/_[__(_,_,_,_,_) ____(_,_,_,_,_,_)]*( _[
  __$()]-_[_$()])+_[ _$() ];_[__(_,_,_,_,_,_,_)] $_$_ _[__(_,_,_,_,_,_,_) ____
(_,_,_,_,_)]/_[_$_()]*(_[__(_,_,_,)]-_[__(_,_,)] )+_[__(_,_,)];_[__(_,_,_,_, _
,_,_,_)] $_$_ _[_$_() - __$()] $_$_ _[__(_,_,_,_,_)+ _$_()-__$()]  $_$_  _$();
_f:_[__(_,_,_,_)]  $_$_  _[__( _,_,_,_, _,_,_, _)] * _ [__(_,_,_, _,_,_,_,_)];
_[__(_,_,_,_,_)] $_$_ _[_$_() - __$()]*_[_$_() - __$()];_[__(_,_,_,_,_,_,_,_,_
)] $_$_ __(_,_)*_[__(_,_,_,_,_,_,_,_)]*_[_$_() -__$()]+ _[__ (_,_,_,_,_,_,_)];
_[__(_,_,_,_,_,_,_,_)] $_$_ _ [ __(_,_,_,_) ]-_[__(_,_,_,_,_)]+_[__(_,_,_,_,_,
_)];$_$(_[_$_()____(_,_,_,_,)]++)$_(f,i)((_ [_$_() ____ (_,_,_,_,)]< _ [_$_ ()
____ (_,_,_,_,_)])&&(_[__(_,_,_,_)]+ _[__(_,_,_,_,_)]<_[_$_()____(_,_,_,_,_,_)
])) $_(to,go) _f; $_(ar,ch) $(m,i,au)[] $_$_ <% __(_,_,_) * _$_()____(_,_), __
(_,_,_,_) * _$_()____(_,_,_),__(_,_,_,_,_,_) * _$_()____(_,_,_,_), __(_,_,_,_)
*_$_() ____(_,_,_,_,_),__(_,_,_,_) * _$_() ____(_,_,_,_,_,_),__(_,_,_,_) * _$_
()____(_,_) %>;___($(m,i,au)[($(n,i,t)) _[_$_()____(_,_,_,_)]%__(_,_,_,_,_)]);
$_$(_[__(_,_ ,_,_ ,_,_,_) + __(_,_,_,_,_,_)]++){m(i,a,u) ( _$()) ;$_$ (_[_$_()
____(_,_)]++)$_$(_[_$_()____(_,_,_)] $_$_ _$()) $_(f,i)(_ [__(_,_,_,_,_,_,_) + 
_$_()] != __(_)) ___(_$_()) ;{  m(i,a,u)(__$()); r(e,t)    /* IOCCC 2014*/  %>

(from the 2015 IOCC)[/quote]

BTW - that’s a console Mandlebrot generator.

Ummmm … no

fwiw the obfuscated c contests are fun but this one is way more evil
code that LOOKS fine & seems harmless but is really dirty nasty and evil :slight_smile:

I do so HOPE you are KIDDING!

The functionality of equal follows the definition of equal. Case is trivial. What about accents or precomposed vs decomposed? It’s not so easy to say and it may change.

Actually, Text is able to do “é” = “é”, where the first one is one character, and the second e plus non advancing acute.

String would consider them not equal.

The moral is, it falls on the programmer to know (and sometimes learn) the language, instead of trying to shoehorn it into the writing style of another.

That whole regular request to force C syntax into Xojo feels to me like asking English to be pronounced like Chinese to make it easier for foreigners to understand.

these sort of things are very useful exercises and mentally challenging

I know people who can write Fortran in any language :stuck_out_tongue:

@Other Tim that’s fantastic and made my morning.

[quote=240480:@Michel Bujardet]A
The moral is, it falls on the programmer to know (and sometimes learn) the language, instead of trying to shoehorn it into the writing style of another.[/quote]

I had a situation exactly like this many years ago. I was working at General Dynamics, and I was spread thin doing work on multiple commerical contracts, one of which was a “sensitive” project that required me to drive to an off-site faciltiy just to talk about it. So they decided to hire a dedicated resource. A few weeks later, I get a call from the Project Manager who said. “Hey Dave, didn’t you say you could do project “xyz” in a few days, and that it would execute in a few seconds?”… “Yeah”… “Well Fred just wrote it, the code is 200 pages, and it takes 2 hours to run”… “Uh, let me come over there”.

Long story… He had written the code in SAS (which was the requirement), but it was formatted as if it were Fortran. I rewrote it properly, it was 20 pages long, and ran in under a minute. Fred sought employment elsewhere.

Be sure to check out the IOCCC (International Obfuscated C Code Contest) for more amazing collections of tiny code.

http://ioccc.org