Ummm, len()? or...
BlitzMax Forums/BlitzMax Beginners Area/Ummm, len()? or...| 
 | ||
| Well, I feel like a total newb today!  :-) How on Blitz Earth do I get the length of either a int variable and ditto for a string variable? Here's what I was doing:   Local vLineNow  = TextAreaCursor(vTextEdit,TEXTAREA_LINES) + 1
  Local vLineAll  = TextAreaLen(vTextEdit,TEXTAREA_LINES) + 1
  Local vRawLine  = TextAreaCursor(vTextEdit,TEXTAREA_LINES)
  Local vCharNow  = TextAreaCursor(vTextEdit,TEXTAREA_CHARS) - TextAreaChar(vTextEdit,vRawLine)
  Local vLinePad  = Len(vLineAll)
  Local vPadding$ = ""
  Local vCurrPad  = Len vCharNow + Len vPadding$
  If vCurrPad <> vLinePad
    Repeat
      vPadding$ = vPadding$ + "."
      vCurrPad  = Len vCharNow + Len vPadding$
    Until vCurrPad = vLinePad
  EndIf
  SetStatusText(vWindow,"Ln:  " + vPadding$ + vLineNow + "    Col:  " + vCharNow + "    " + vLinePad + "|" + vCurrPad)
But the len isn't working. Likely it's something I'm doing wrong, but after hitting the docs for about an hour, haven't found my mistake or a solution. Can anybody slap me in the face with an answer to this? Thanks, -Garrett | 
| 
 | ||
| 1) Not sure about int vars, but strings have a method called Length...  ie length_of_string=vPadding.Length() 2) This may have broken in the latest version of Max. Safe usage of Len requires brackets at the moment... ie Local vCurrPad = Len(vCharNow)+Len(vPadding$) 3) I could be wrong. =] Related links: http://www.blitzbasic.com/Community/posts.php?topic=62888 http://www.blitzbasic.com/Community/posts.php?topic=62674#701278 | 
| 
 | ||
| It has been reported that the presedent order for LEN (Which is an operator and not a function) is broken in 1.22, so as a sudgestion put brakets round (Len vCharNow)+(Len VPadding) EDIT: should have been a bit quicker ther shouldnt I? Interesting that we have chosen to put the brackets in different places tho. | 
| 
 | ||
| I must be wierd or something 'cause I've always been using Len(vCharNow). Must be a throwback from the bad 'ole days. Well, that's my excuse anyway. | 
| 
 | ||
| Well, I'm at a loss.  Nothing seems to work for len on strings or integers  :-( Thanks anyway everyone, -Garrett | 
| 
 | ||
| I use: c$="car" b% = 123 print c.length print string(b).length for strings and int. works fine for me | 
| 
 | ||
| Len and length works on objects. Strings are objects but ints are not. car:String="Ferrari" price:Int=100000 Print Len(car) ' or Print car.length Print Len(String(price)) 'or Print String(price).length | 
| 
 | ||
| Length of an int doesn't make any sense anyway. Length in what? It is just a number in memory. For drawing it needs to be a string, where length makes a sense. | 
| 
 | ||
| Just to clarify what's already been said... Local vLinePad = Len(vLineAll) ... vCurrPad = Len vCharNow + Len vPadding$Makes no sense, It's just... Local vLinePad = vLineAll ... vCurrPad = vCharNow + vPadding$.length ' I don't see the point of Len() TBH. ;o) | 
| 
 | ||
| The point was that I needed to know how many characters in length the int variable held. Such as, if was only 1 character such as "7", or whether it held 2 characters such as "77" or whether it held 3 characters such as "777". In the end, I was trying to place line numbers and column location on the status bar, but pad the line numbers in a way that kept the column count from being moved when the user went from say line 9 to line 10, and then the column count on the status bar would be moved over by a character. So if total lines was 498, I need a total of 3 characters constantly for the line number. So if the user is on line 7, then I need to pad it with two extra spaces to make up the difference, such as " 7", or if the user is on line 77, then I only need to pad with one extra space, such as " 77". I guess I'll just convert the integers to strings and then get the len. Thanks, -Garrett | 
| 
 | ||
| why don't you use "rset" or "Lset"? Rset works like this: b:int = 25 a$ = rSet(String(b),5) 'creates a string 5 char. long padded to the left Print a$ Print Len(a$) | 
| 
 | ||
|  why don't you use "rset" or "Lset"? Rset works like this:  I.... I.... Ummmmmm.... Being old and stupid is my excuse I tell you! ;-) I'll give that a try :-) Thanks Jesse, -Garrett |