This thread illustrates some of the confusion people have with API 2
The documentation doesn’t help clear it up either since it says, quite clearly, that there seems to be a Boolean.ToString method.
I know this isn’t whats meant, but the writer of that thread obviously doesn’t.
Right now code has to look like
dim b as boolean = Boolean.FromString("true) dim s as string = b.ToString
One line uses a parameter and the other doesn’t. One is defined in a module named for a type and the other isnt. Its a little unsymmetrical and hard to get used to because its not consistent. This confusion is what spawned the original posters post on the forum.
One way to fix this is to just tell people their code is wrong. Thats not likely to garner a lot of “Gee thanks” kind of responses though.
One way to fix this might be to just add operator_convert method to all the data types. But this then smacks of “variant magic” and isnt quite as explicit or obvious. But you could do something like
dim b as boolean = "true" dim s as string = b
Another might be to add to the Boolean module, a “ToString” method that takes a boolean as a parameter and returns a string.
Then code could look like
dim b as boolean = Boolean.FromString("true") dim s as string = Boolean.ToString(b)
which also improves symmetry – except now you use a TO method and FROM method on one data type which is a bit verbose and not quite symmetrical. As well do you then need to add a TO and FROM method to every data type ? Thats a big pile of TO and FROM methods in every data type module.
Maybe this could be improved by putting additional FROM conversion methods in for String, Boolean, and the other data types. Then the code might look like
dim b as boolean = Boolean.FromString("true") dim s as string = String.FromBoolean(b)
That way at least the conversions are more consistent and you use the data type name as the prefix to know what the conversion will return. A String.From will give you back a string from the passed type. A Boolean.From method will give you a boolean. And if all you have is From methods then its 100% consistent. Everything JUST has Convert From style methods.
Either way the current set up has issues because it isn’t consistent and it apparently confuses the very people who it was intended to help.