Retrieving a string from a method

Been reading chapter 4 back to front and so lost … (missing visual Basic) :frowning:

I have a method … that ends up with a nice string - that I want to access from other commands … let’s say its name is “Iwantthisstring”

The method (called “cleanthetext”) does result in “iwantthisstrong”

but how do I call that string from somewhere else?

when I mess with return type, parameters, and RETURN I get errors everywhere … I’ve looked for examples - but, as ever, they’re all so very different …

What would be the command that says … “Oi … there’s a string called iwantthisstring and it lives in cleanthetext … gimme it …”

sorry … :frowning:

worked it out :frowning:

Can you explain what you did so others that find the same problem could find your hint to work it out?

As a newbie to XOJO … retrieving data created in another method was something I just couldn’t work out …
I did solve it - and here’s the simplest way I can talk it through …

I wanted a public (global) string … call it “this_string_is_gold”

I created this_string_is_gold by going to insert > methods
there … the I gave the “method name” the name of “Oh-frustration”
scope = public
return type = string

I entered all my lovely code into the big code box …
It end with the string that I wanted publicly available - that string I called “this_string_is_gold”

the key line needed to enter was this:

Return this_string_is_gold

“this_string_is_gold” is the string that I want to be able to access somewhere else … (a global, public string)

Now - I wanted to get this string from a pushbutton event

There - in a pushbutton I entered

dim retrievethetextiwanted as string
retrievethetextiwanted = Oh-frustration
msgbox retrievethetextiwanted

So … “retrievethetextiwanted” becomes “this_string_is_gold” (which was created in the method called “Oh Frustration”

I’m sure this is 101 to everyone else … took me hours and hours and hours :frowning:

[quote=438716:@Philip McCarthy]There - in a pushbutton I entered

dim retrievethetextiwanted as string retrievethetextiwanted = Oh-frustration msgbox retrievethetextiwanted

So … “retrievethetextiwanted” becomes “this_string_is_gold” (which was created in the method called “Oh Frustration”

I’m sure this is 101 to everyone else … took me hours and hours and hours :([/quote]

If Oh_frustration is returning “this_string_is_gold”, then you can change the code to:

MsgBox Oh_frustration

no need to dim a string to get that.

I swear I tried that :frowning:

… but … yup …

thanks!!!

OK … now I’m trying to do things the other way …

I have a pushbutton that creates a string called “save_this_string”
I would like one of my methods to use “save_this_string” (as if it were a public variable)
How can my method (“yeah_me”) retrieve the value of "“save_this_string”?

Also - in the above example - when I call “Oh-Frustration” … do I get just the RETURN value or does the whole set of code in that method run?

I thought there was something like GET and SET for all this business … but looking up GET and SET in the manual doesn’t seem to yield anything … not least because the word SET appears 155 times.

OK - I can go to insert > properties and make a global variable there - apparently called a global property in Xojo
That’s part 1 done.

[quote=438838:@Philip McCarthy]
Also - in the above example - when I call “Oh-Frustration” … do I get just the RETURN value or does the whole set of code in that method run?.[/quote]
Usually you put some code and ‘return something’ where ‘something’ could be a string that contain ‘the_string_is_gold’, integer, etc.

I have a lot to learn too, maybe this will help (just started reading):
https://documentation.xojo.com/getting_started/using_the_xojo_language/methods.html
https://documentation.xojo.com/UserGuide:Object-Oriented_Programming
https://documentation.xojo.com/getting_started/object-oriented_programming/advanced_oop_features.html

Thanks!

I do have a book or two - what I really need is a translation manual … someone should make one of those …
That is “Translate Visual Basic into Xojo” … I know what stuff is in VB, I’d just like to know how to do that stuff in Xojo (where it is etc.?)
If there were such a “translation” text book, it would be very helpful.

Good idea, I don’t know if something like that exists. I’m not a professional programmer and found Xojo as a good fit for a project, so learning from scratch. I know nothing about VB.

I hope you can soon understand the differences in Xojo and fully use it for your needs.

While VB & Xojo are similar in language (which makes it easy to learn) the approach is very different. I would suggest forgetting VB and learning Xojo it will be quick because you understand the syntax.

Global properties will lead you to pain in other than very specific instances, so don’t use them.

A long time ago (in a galaxy …) Xojo posted a VB Migration Assistant . I don’t know if it is still usable but if it is, you might use it and examine the resulting output. It’s probably considerably outdated but…