Page 1 of 1

StringRequest() problem..

Posted: Sat Jul 27, 2013 2:12 am
by NubeCheCorre
Hi :-)

before posting my problem i looked for a solution in the forum but I didn't find it, so here I am to ask you an hand.. ;)

Code: Select all


title$ = "Requester!"
body$ = "Inserisci un numero"
def$ = "ciao"

a$, ok  = StringRequest(title$, body$, def$, #ALL,0,FALSE)

If a$ > "5"
	DebugPrint("Il numero che hai inserito non é maggiore di 5")
Elseif a$ < "5"
	DebugPrint("Il numero inserito é maggiore di 5")
Else
	DebugPrint("Il numero inserito é uguale a 5")
EndIf


That's the code.. I would like to understand why the program, once compiled, always told me that the number that I inserted is always bigger than five (>), that's the first question.

The second question is:

Why, if I put #NUMERICAL, instead of #ALL, the compiler reports me an error to this line, telling me to read the documentation?.. the line is:

Code: Select all

a$, ok  = StringRequest(title$, body$, def$, #ALL,0,FALSE)
I also, tried with:

a$ = StringRequested(title$, body$,def$)

and the compiler tells me that I am trying to compare number with string..

Shouldn't be Hollywood able to convert string to number and viceversa and so be able to compare them?

Thanks Davide,

Re: StringRequest() problem..

Posted: Mon Jul 29, 2013 10:20 am
by g0blin
Sorry dude, as for the first question, you just inverted the "greater than" sign with "lesser than". (see code below).
I'm investigating on the second one, now
Ciao

Code: Select all

title$ = "Requester!"
    body$ = "Inserisci un numero"
    def$ = "ciao"

    a$, ok  = StringRequest(title$, body$, def$, #ALL,0,False)

    If a$ < "5"
       DebugPrint("Il numero che hai inserito non é maggiore di 5")
    ElseIf a$ >"5"
       DebugPrint("Il numero inserito é maggiore di 5")
    Else
       DebugPrint("Il numero inserito é uguale a 5")
    EndIf

There seems to be a problem anyway, since this code only works correctly with numbers from 0 to 9. Inserting "12", for example, will result in "12 non greater then 5". It seems only the first digit of the number is taken in account....

Re: StringRequest() problem..

Posted: Mon Jul 29, 2013 10:51 am
by g0blin
I solved the problem by converting the string to a numer and comparing it. Now it works.

Code: Select all

 title$ = "Requester!"
    body$ = "Inserisci un numero"
    def$ = "ciao"

    a$, ok  = StringRequest(title$, body$, def$, #ALL, 0, False)
    n=ToNumber(a$)
    If n < 5
       DebugPrint("Il numero che hai inserito non é maggiore di 5")
    ElseIf n >5
       DebugPrint("Il numero inserito é maggiore di 5")
    Else
       DebugPrint("Il numero inserito é uguale a 5")
    EndIf

Re: StringRequest() problem..

Posted: Mon Jul 29, 2013 10:32 pm
by NubeCheCorre
thanks for the help, about the conversion of number and letters, shouldn't be Hollywood able to do this automatically?

Re: StringRequest() problem..

Posted: Tue Jul 30, 2013 8:11 am
by g0blin
Mah, sai che con le stringhe in Hollywood non ho mai lavorato? A questo punto mi viene il dubbio che non sia così, a differenza di ARexx. Appena posso ci riprovo

Re: StringRequest() problem..

Posted: Tue Jul 30, 2013 1:31 pm
by djrikki
NubeCheCorre wrote:thanks for the help, about the conversion of number and letters, shouldn't be Hollywood able to do this automatically?
When performing any kind of logic against a variable you should always assume the language cannot do any 'conversion' internally and use Val() accordingly.

Code: Select all

age$, ret = StringRequest("How old are you?".....)
if Val(age$) < 16
  debugprint("you are under 16")
elseif Val(age$) > 60
  debugprint("you are older than 60, time to consider retiring?")
else
  debugprint("you are between the age of 16-60")
endif

Re: StringRequest() problem..

Posted: Tue Jul 30, 2013 2:22 pm
by NubeCheCorre
ok thanks for the info! :-)

I didn't know it :)

Re: StringRequest() problem..

Posted: Tue Aug 06, 2013 2:07 pm
by airsoftsoftwair
Read the documentation, chapter 6.3: Relational operators:
Each of the operators compares the operands a and b and returns True if the condition matches and False otherwise. Please note that you can only compare values of the same type. The automatic number to string conversion does not apply here!

The equality operators can be used with all types, i.e. you can also compare functions and tables with them. The order operators (< > <= >=) only work with numbers and strings. If you compare strings with them Hollywood will do an alphabetical comparison. For example:

r = ("Hello" < "World") -> True because H is before W alphabetically
r = ("Commodore" < "Amiga") -> False because C is after A alphabetically