Author Topic: Convert TEXT in NUMBER  (Read 6327 times)

Pryss

  • Newbie
  • *
  • Posts: 4
    • Chaine YT
Convert TEXT in NUMBER
« on: October 29, 2016, 05:02:11 AM »
Hello,

 I'm working on a VA profile in french using VA and ED:Toolbox.

 Currently I'm trying to convert the fuel data provided in text with EDTB to a number, in order to check my fuel level and to warn me if the fuel is too low.

 I'm trying to convert the text in number (decimal or integer) in order to be able to check it, but I do not achieve that using the Set integer or Set decimal with convert text/token.

Here are the commands :

Set Text [Fuelt] to [http://localhost:3001/Marvin/apiData.php?ship=fuel] (Lower Case)
Set integer [Fuel] value to the converted value of Fuelt
Begin Small Integer Compare : [Fuel] Is Less Than 25
    Say, 'Attention réserve de carburant inférieure à 25%'  (and wait until it completes)
End Condition - Exit when condition met
Begin Small Integer Compare : [Fuel] Is Less Than 50
    Say, 'Réserve de carburant inférieure à 50%'  (and wait until it completes)
End Condition - Exit when condition met
Begin Small Integer Compare : [Fuel] Is Less Than 75
    Say, 'Réserve de carburant inférieure à 75%'  (and wait until it completes)
End Condition - Exit when condition met


Can someone help me, and sorry for my bad english.

Thanks
« Last Edit: October 29, 2016, 05:12:35 AM by Pryss »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Convert TEXT in NUMBER
« Reply #1 on: October 29, 2016, 07:49:12 AM »
What's the input format? When you run this command, what would the value of the "Fuelt" text variable be?

Pryss

  • Newbie
  • *
  • Posts: 4
    • Chaine YT
Re: Convert TEXT in NUMBER
« Reply #2 on: October 29, 2016, 08:44:03 AM »
Hello,

 It's a "number in text" I guess, for example  100.00 or 98.8. But when I try to use it in Small Integer compare, nothing happen.

 I can use the TTS to read It.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Convert TEXT in NUMBER
« Reply #3 on: October 29, 2016, 09:28:41 AM »
Just noticed, you're trying to convert the literal text "Fuelt" to a number, you need to use a token to convert the variable "Fuelt" instead:
Code: [Select]
Set integer [Fuel] value to the converted value of FueltShould be
Code: [Select]
Set integer [Fuel] value to the converted value of {TXT:Fuelt}

However, there is a further caveat: Because the input uses a "." as the decimal seperator, and I'm assuming you're using a "," as is normal in France(and other places), "100.00" will convert to "10000".

I recommend, in this particular case, to simply drop the section entirely:
Code: [Select]
Set Text [Fuelt] to [http://localhost:3001/Marvin/apiData.php?ship=fuel] (Lower Case)
Set Text [Fuelt] to '{TXTSUBSTR:Fuelt:0:{TXTPOS:".":Fuelt:0}}'
Set integer [Fuel] value to the converted value of {TXT:Fuelt}
This will return "100" when given "100.00", but also "9" when given "9.99".

If you don't, you'd have to use a Decimal value instead(Converting to Int doesn't seem work on floats in VoiceAttack), but then those don't currently work on systems that use a "," as the decimal separator.
« Last Edit: October 29, 2016, 09:54:34 AM by Pfeil »

Pryss

  • Newbie
  • *
  • Posts: 4
    • Chaine YT
Re: Convert TEXT in NUMBER
« Reply #4 on: October 29, 2016, 12:45:46 PM »
Thanks Pfeil,

  The tip concerning the {TXT:...] token was the solution but I've made another mistake by using the wrong type of data... Small integer instead of Integer....

 It works fine.

Thanks again.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Convert TEXT in NUMBER
« Reply #5 on: October 29, 2016, 12:49:42 PM »
Small integer instead of Integer....
Ah, I missed that one. Though, for a number as small as 100, Small Integer is the way to go(in fact, anything between 32,767 and -32,767 will fit, so doesn't need a bigger variable).