Yoko

All sides of Injection
It is currently 2025-12-24 00:54:50

All times are UTC+02:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
 Post subject: first letter of variable
PostPosted: 2005-07-01 15:03:01 
Offline

Joined: 2004-10-02 14:37:13
Posts: 22
hi :)
how I can take the first letter of variable (ex: hola return h)

?



tnx


Top
   
 Post subject:
PostPosted: 2005-07-01 19:11:50 
Offline

Joined: 2004-10-02 14:37:13
Posts: 22
sub test()
var n=Left(3250,1)
uo.print(str(n))
endsub



return 0
why? :(


Top
   
 Post subject:
PostPosted: 2005-07-01 20:48:49 
Offline
Expert!
User avatar

Joined: 2005-04-23 10:19:43
Posts: 388
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:
sub Test()
var TextLine='Big line'
var Digit=182341
UO.Print(TextLine[0])
UO.Print(Left(str(Digit),1))
end sub


Top
   
 Post subject:
PostPosted: 2005-07-01 22:56:21 
Offline

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


Top
   
 Post subject:
PostPosted: 2005-07-01 23:47:12 
Offline

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


Top
   
 Post subject:
PostPosted: 2005-07-02 09:33:49 
Offline
Expert!

Joined: 2004-04-03 17:36:29
Posts: 2544
Location: Saint-Petersburg
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:
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.


Top
   
 Post subject:
PostPosted: 2005-07-02 17:46:01 
Offline
Expert!
User avatar

Joined: 2005-04-23 10:19:43
Posts: 388
Try this way:
Code:
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?


Top
   
 Post subject:
PostPosted: 2005-07-03 20:52:32 
Offline

Joined: 2004-10-02 14:37:13
Posts: 22
perfect :D
tnx :*


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 8 posts ] 

All times are UTC+02:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited