none
small basic v 0.8 "if" do nothing in this program RRS feed

Answers

  • You can use the Text.GetCharacterCode to check the value of strings for comparison, but you have to do it character by character in the case that 2 strings have the same starting characters.  For example import RRZ478-0.  There are some cases where this sub might not work exactly as you expect, e.g. V1 = "Anton" and V2 = "AntonXXX", but this could be modified relatively easily, for example RRZ478-1.
    Wednesday, April 21, 2010 5:41 PM
    Moderator
  • In program KBM363 are two errors. he find the last not the first with all follows. What is the possibility to find with wildcard (* or/and +) Please help me!

    Martmen,

    I've put together an example that indexes your music tracks and allows you to do wildcard searches using *text, text*, or *text*

    Hope it helps. Import code is: KBM363-0

    Or: http://smallbasic.com/program/?KBM363-0

     

    I will leave + wildcards up to you :)

    Friday, April 30, 2010 3:32 PM

All replies

  • Martmen,

    I don't have a full answer for you, but if you set V1 and V2 equal to each other, you'll notice that the If V1=V2 does work.  Also, if you try <>, that works as well.  But I don't know why the < or > comparators don't seem to be working.

    Regards

    Wednesday, April 21, 2010 5:26 PM
  • The "<" and ">" operators don't work on text - they operands are treated as number for these operators. 

     

    Wednesday, April 21, 2010 5:29 PM
    Moderator
  • You can use the Text.GetCharacterCode to check the value of strings for comparison, but you have to do it character by character in the case that 2 strings have the same starting characters.  For example import RRZ478-0.  There are some cases where this sub might not work exactly as you expect, e.g. V1 = "Anton" and V2 = "AntonXXX", but this could be modified relatively easily, for example RRZ478-1.
    Wednesday, April 21, 2010 5:41 PM
    Moderator
  • LitDev, do you think it'll be a good idea to support text comparisons for the "<" and ">" operators?  I believe the comparison will be culture dependent. 
    Wednesday, April 21, 2010 6:25 PM
    Moderator
  • Vijaye,

    Since you have = and <> for strings, then it would probably be sensible to have < and > as well, but as you say the results will depend on the culture if you use string.compare.  Part of me thinks that the fun of SmallBasic is to require users work out how to do things with a limited set of commands, but on balance I would include these.

    EDIT

    If you go this route you may want >= and <= as well?

    Wednesday, April 21, 2010 6:43 PM
    Moderator
  • I agree with you, and it should be language dependent right?  I don't see a negative to permitting it yet.  And I would make it case insensitive to keep it simple to use for almost all uses.
    Wednesday, April 21, 2010 7:11 PM
  • Thanks guys - I'll add this for v0.9 (which I'm wrapping up soon).

     

    Wednesday, April 21, 2010 7:29 PM
    Moderator
  • Thanks Vijaye Raji to add it in v0.9. "If" is a basically BASIC command. In Small Basic are any text-commands and i think that is necedssary that strings can check with the if-command.

     

    Thursday, April 22, 2010 11:02 AM
  • Thanks guys - I'll add this for v0.9 (which I'm wrapping up soon).

     

    I don't understand the requirement here. I can't think of a time I've ever needed to do a < or > on strings. What's the benefit?

    Would this basically only do a check to see if one string is alphabetically higher (or lower) than another string? And if you're doing that, what would the precedence be for upper and lower case (or as bigdaddyo says, make it case insensitive, which might cause more problems than leaving it case sensitive)?

    You also have a text object. Would it not make more logical sense to have a text.compare() function, which could sub contain a text.convertToLowerCase() in order to make it case insensitive for those needing it that way.

    Puzzled.

    Monday, April 26, 2010 10:34 PM
  • To sort list and binary search you need it. By 25000 entries you wait a long time if you will find a entry if you search with a loop.
    Program HMR773 use binary search. If you view it and send me a answer.

    Martmen

    Tuesday, April 27, 2010 12:58 PM
  • Best answer is to run a dos command...

    Dir /a /s /b /oN > myMusic.txt

    Then get your SmallBasic program just to read the sorted list of files from myMusic.txt

    With 25000 entries you should be building a separate index file anyway to allow you to find relevant titles to play, and you won't need text.compare() to do any of it.

    With so much commentary to date about keeping SB's command set limited, I think there are other more important commands required before a low use one such as text.compare.

    Just my view.

    Tuesday, April 27, 2010 8:14 PM
  • In program KBM363 are two errors. he find the last not the first with all follows. What is the possibility to find with wildcard (* or/and +) Please help me!
    Thursday, April 29, 2010 8:01 AM
  • It just seems a little silly not to be able to sort a list of names without writing what might be a slightly messy character by character comparison.  Making comparisons case insensitive eliminated Dave's 'tolowercase' method - I just figured case may never matter to people - especially at this level of programming.  And they could always work around it by doing it the hard way.

    Regarding placing an operation like string compare into an object method, I just wonder why languages are putting simple operations into object methods.  It's the modern way of course -- just so unnecessary for practically all general work.  Maybe because of the way SB is trying to demonstrate the basic idea of objects it is better to do the suggested Text.method.  It's just that I just wonder when we'll be forced to do scalar multiply's done using Math.Multiply(x, y)... you know what I mean?

    Thursday, April 29, 2010 8:18 PM
  • Bigdaddyo, I agree with you there.

    Because SmallBasic is already primarily object based do I suggest using the text.compare method. A 'feature rich' language (which SB isn't) should of course use alternative approaches too. I still don't like the idea of < and > on text strings though as they are ambiguous in that sense (due to case and region). In a numerical comparison they are very specific in their operation and result.  

    I suppose accepting an ambiguous situation (which I don't think is suitable to SB), < and > should go to the lowest common denominator, and only do case insensitive alphanumeric comparisons, but that's easily open to disagreement - and how do you get intellisense to show you the help text when a computational symbol is entered ... it's already getting in the way of typing for me as it is.

    The easy answer to sorting is to provide sort methods, but that takes away from SB's learning focus which prefers you to write the sort yourself. The question then is what is the lowest denominator - does it stay at the string level, or make learners start from the character level. I doubt if there's a simple answer to that. (Well, there is a 'simple' answer, which is for SB to allow the definition of Functions.)

    Friday, April 30, 2010 11:13 AM
  • In program KBM363 are two errors. he find the last not the first with all follows. What is the possibility to find with wildcard (* or/and +) Please help me!

    Martmen,

    I've put together an example that indexes your music tracks and allows you to do wildcard searches using *text, text*, or *text*

    Hope it helps. Import code is: KBM363-0

    Or: http://smallbasic.com/program/?KBM363-0

     

    I will leave + wildcards up to you :)

    Friday, April 30, 2010 3:32 PM
  • That's great. Thank you verry much.  It help me for my musicplayer. The binary search is now not necessary and the wildcard is fantstic.
    Friday, April 30, 2010 5:52 PM
  • You did'nt add it for v09 i think. Show JXL748.

    Thursday, June 10, 2010 9:49 AM