StringRequest() problem..

Find quick help here to get you started with Hollywood
Post Reply
User avatar
NubeCheCorre
Posts: 77
Joined: Mon Mar 19, 2012 1:24 am
Contact:

StringRequest() problem..

Post 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,
g0blin
Posts: 77
Joined: Tue Oct 04, 2011 9:06 am

Re: StringRequest() problem..

Post 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....
g0blin
Posts: 77
Joined: Tue Oct 04, 2011 9:06 am

Re: StringRequest() problem..

Post 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
User avatar
NubeCheCorre
Posts: 77
Joined: Mon Mar 19, 2012 1:24 am
Contact:

Re: StringRequest() problem..

Post by NubeCheCorre »

thanks for the help, about the conversion of number and letters, shouldn't be Hollywood able to do this automatically?
g0blin
Posts: 77
Joined: Tue Oct 04, 2011 9:06 am

Re: StringRequest() problem..

Post 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
djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: StringRequest() problem..

Post 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
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
User avatar
NubeCheCorre
Posts: 77
Joined: Mon Mar 19, 2012 1:24 am
Contact:

Re: StringRequest() problem..

Post by NubeCheCorre »

ok thanks for the info! :-)

I didn't know it :)
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: StringRequest() problem..

Post 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
Post Reply