Page 1 of 1

first letter of variable

Posted: 2005-07-01 15:03:01
by virussino
hi :)
how I can take the first letter of variable (ex: hola return h)

?



tnx

Posted: 2005-07-01 19:11:50
by virussino
sub test()
var n=Left(3250,1)
uo.print(str(n))
endsub



return 0
why? :(

Posted: 2005-07-01 20:48:49
by Beyonder
If you mean the first letter of variable's indentificator, than it is impossible.
If it was about the wat that variable contains than this way:

Code: Select all

sub Test()
var TextLine='Big line'
var Digit=182341
UO.Print(TextLine[0])
UO.Print(Left(str(Digit),1))
end sub

Posted: 2005-07-01 22:56:21
by virussino
mhh

var b = 2500

var c = left(str(b),1)

uo.print(c) # return 2 ok..

var d = c * 1000 # bad operation for this type of variable - D


:(
help :?:

Posted: 2005-07-01 23:47:12
by virussino
:D

var c = val ( left(str(b),1) )



I do not resolve a problem....
I must approximate numbers with ", " for defect

ex...
2,1 or 2,5 or 2,9 return 3

3,1 or 3,2 or 3,3 or 3,4 ecc.... 3,9 .... return 4

3,0 return 3
1,0 return 1

ecc ecc


is possible?

Posted: 2005-07-02 09:33:49
by Edred
Function Left() (or Right()) work with a string. You can't send value in this function. This function will return a string.

You can't use operations multiple and divide (* and /) with a string. You need in convert the string to value.

Code: Select all

VAR b = 3,2, c, d, e
c = str( b )
UO.Print( c )
d = left( c, 1 )
UO.Print( d )
e = c[0]
UO.Print( e )


Try it. UO.Print() need in string parameter. If you send to this function a value - you can't get legal result.

Posted: 2005-07-02 17:46:01
by Beyonder
Try this way:

Code: Select all

sub RoundUp(Value)
return int(Value+0.9999)
end sub


It works this way:
int returns value without ','. That means that 3.0 = 3 and 3.9 = 3. Thats not exactly what we need.
But what do we get after adding 0.9999 (count of '9' is equal to precision you need).
3.0 -> 3.9999 -> 3
3.1 -> 4.0999 -> 4
3.9 -> 4.8999 -> 4
Isn't that what we need?

Posted: 2005-07-03 20:52:32
by virussino
perfect :D
tnx :*