Real Software Forums
http://forums.realsoftware.com/

So I can't output a string's length to a string?
http://forums.realsoftware.com/viewtopic.php?f=10&t=47905
Page 1 of 1

Author:  timehacker11 [ Fri May 17, 2013 4:14 am ]
Post subject:  So I can't output a string's length to a string?

if textfield1.text.len = 0 then
MsgBox "no string detected"
else
dim a as string = textfield1.text
msgbox "length: " + a.len

In just about any other language you can:

if string.length = 0 then
alert here
else
string1.text = string.length.tostring
end if.

Author:  shaosean [ Fri May 17, 2013 4:28 am ]
Post subject:  Re: So I can't output a string's length to a string?

if textfield1.text.len = 0 then
MsgBox "no string detected"
else
dim a as string = textfield1.text
msgbox "length: " + str(a.len) ' you need the str()
end if

Author:  timehacker11 [ Fri May 17, 2013 12:16 pm ]
Post subject:  Re: So I can't output a string's length to a string?

shaosean wrote:
if textfield1.text.len = 0 then
MsgBox "no string detected"
else
dim a as string = textfield1.text
msgbox "length: " + str(a.len) ' you need the str()
end if


Thanks.

This is my major complaint about the language; it isn't Englishifide as much as VB.NET or other languages for that matter.

I only wish the Xojo language was a carbon copy of VB.NET, at least English wise.

Author:  shaosean [ Fri May 17, 2013 1:42 pm ]
Post subject:  Re: So I can't output a string's length to a string?

I use xtalk languages a lot and am used to the more verbose English-like syntax ;-)

put the number of characters in the text of field "textfield1"

Author:  Paul Lefebvre [ Fri May 17, 2013 1:50 pm ]
Post subject:  Re: So I can't output a string's length to a string?

If you want to use ToString on an Integer variable, you can just create your own extension method to do so.

On a module, add this global method:
Function ToString(Extends i As Integer) As String
Return Str(i)
End Function


Then you can write code like this anywhere in your project:

Dim i As Integer = 42
MsgBox(i.ToString)

Author:  taylor-design [ Fri May 17, 2013 5:03 pm ]
Post subject:  Re: So I can't output a string's length to a string?

Personally I despise the "English like" syntax of languages like xtalk or AppleScript. Computers are not to the point of being able to understand the infinite variations humans use to construct the same message. "Natural language" systems usually end up being more demanding in terms of syntax because it's not clear, at a glance, which combinations will work and which will not or why. On top of that they are needlessly verbose.

The .NET languages are not "Englishified" in this manner. But they do automatically coerce types when and where they can. I have mixed feelings about this because in theory a strict language like RB catches more errors at compile time. And I can think of examples where automatic type coercion could lead to very subtle and painful bugs. But in practice I find that I prefer the language to do this work for me where it can, and I haven't run into those painful bugs (yet).

Types involve more work in RB. On the flip side, the .NET framework is often excessively complex and deep, with too many nested objects and long .Method call chains. The RB framework is nice and compact in comparison.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/