first letter of variable

Ask for help

Moderators: Murderator+, Murderator

Post Reply
virussino
Posts: 22
Joined: 2004-10-02 14:37:13

first letter of variable

Post by virussino »

hi :)
how I can take the first letter of variable (ex: hola return h)

?



tnx
virussino
Posts: 22
Joined: 2004-10-02 14:37:13

Post by virussino »

sub test()
var n=Left(3250,1)
uo.print(str(n))
endsub



return 0
why? :(
Beyonder
Expert!
Posts: 388
Joined: 2005-04-23 10:19:43
Contact:

Post 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
virussino
Posts: 22
Joined: 2004-10-02 14:37:13

Post 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 :?:
virussino
Posts: 22
Joined: 2004-10-02 14:37:13

Post 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?
Edred
Expert!
Posts: 2544
Joined: 2004-04-03 17:36:29
Location: Saint-Petersburg

Post 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.
Beyonder
Expert!
Posts: 388
Joined: 2005-04-23 10:19:43
Contact:

Post 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?
virussino
Posts: 22
Joined: 2004-10-02 14:37:13

Post by virussino »

perfect :D
tnx :*
Post Reply