I am working through the Tutorial document and have run into something that puzzles me. I have input the following code from the tutorial:
//push comma delimited string from an array
Var tags() As String
Var combinedTags As String
tags.AddRow(“Movies”)
tags.AddRow(“Comedy”)
tags.AddRow(“90s”)
combinedTags = tags.FromArray(",")
// combinedTags is now “Movies,Comedy,90s”
And Im getting these errors:
Window1.PushButton1.Action, line 44
Type “String()” has no member named “FromArray”
combinedTags = tags.FromArray(",")
Window1.PushButton1.Action, line 44
Type mismatch error. Expected String, but got Int32
combinedTags = tags.FromArray(",")
Blockquote
Can someone please explain why?
Thanks in advance for any light you can shed.
Del Thompson
// Let's create a new array that will hold some fruit.
var basket() as String
// Add three fruits to the array.
basket.add("apples")
basket.add("bananas")
basket.add("coconuts")
// Now, let's create a string that contains all of the fruit in the basket.
var shoppingList as String
shoppingList = String.FromArray(basket, ", ")
MessageBox(shoppingList)
Thank you Byron, your example code worked for me. Are you saying that addrow doesn’t work with character string arrays in xojo? Or is it that the fromarray function doesn’t
work with string arrays that have been loaded with addrow? should I just use add anytime I’m building a string array?
About a year ago, Xojo renamed AddRow() to simply Add(). Personally, I think it’s a nice improvement, as it makes it easier for developers to remember.
The fromArray() method takes each item (in the array) and adds it to a string. Take a look at the following code:
var names() as String
names.add("Corey")
names.add("Stephanie")
names.add("Joel")
// Let's put all of the names together in a string!
var totalNames as String
totalNames = String.FromArray(names, "-")
// The totalNames string will now contain the following:
// "Corey-Stephanie-Joel"
MessageBox(totalNames)
In case you’re curious, the String.FromArray() has two parts. The first is String, while the second is a method called FromArray(). String is what is called a “class”. A class is very much like a toolbox, as it contain many useful tools (such as FromArray) inside that you can use. In order to use one of the tools, I have to specify which toolbox that I want to use (the “String” class) and which tool (the “FromArray” method) inside that I want to use. This is why you see it as: String.FromArray()
Thank you Byron. Yes, your explanation is very helpful. After 40 years of working in the IT field(now retired!), I can fully appreciate the difficulty of keeping documentation up to date for ever changing software. Most of my time in the field was spent with procedural(COBOL,PL1) languages and what they called 4th generation languages(FOCUS,SPS) and query language(SQL). Recently I decided to challenge myself and learn something about object oriented development. XOJO appealed to me because of its cross platform capability. Never having worked in the C language terms like CLASS are unfamiliar to me. I would guess it equivalent somewhat to a subroutine in COBOL or PL/1. Anyway, I explain all of this because although my questions may seem inane, I’m really trying to understand the terminology and relate it to what I already know. Your explanation was right on! I’m enjoying my journey into XOJO so far and am quite amazed and thankful at how helpful the user community is.
I’m not sure where I found it on the web but the title of the book is:
Introduction to programming with Xojo
A textbook
RHINE,LEFEBRE
Acknowledgements
Special thanks go out to Brad Rhine who wrote the original
versions of this book with help from Geoff Perlman (CEO of Xojo,
Inc).
We’d also like to acknowledge the Xojo community. We often hear
your stories about how Xojo made it easy for you to learn
programming or build an app or start your own business. You
have made Xojo possible for over 20 years.
This book is in PDF format, I downloaded it.
I prefer complete books for future references as apposed to the on-line web based approach that
XOJO provides with the IDE. I searched until I found this but now realize it might be out of date.
Prior to all this madness, it was “append”, which was a perfectly-suited keyword, but unfortunately Xojo decided its users are too uneducated to know what “append” means.