Problems in substack - livecode

I create main stack and Substack, also I create a button in sub stack for performing find a word in scrolling field(the scrolling field is main stack).
If coded as
on mouseUp
find "Work" in field "text"--Here "text" is a scrolling field placed in main stack
end mouseUp
This code for button placed in Substack. why it's not working? is it any alternative way

You need to tell where the field is:
on mouseUp
find "Work" in field "text" on stack "mainstack" -- your stack's name, or use stack id XXXX
end mouseUp

Related

Livecode not recognizing variable value

I’ve built an application in Livecode where there are nine buttons on a card. Eight of the buttons play short music samples and have a variable that holds the number of times the button was pushed. Holding down the mouse button allows the buttons to be dragged around the card as well. The ninth button starts a script that surveys the variables associated with the eight sample buttons and ensures that all the samples have been listened to at least once. The script puts the eight variables into one variable and then checks to see if they are empty. If they are, the script returns an error message prompting them to make sure they have listened to all the samples. The problem I’m having is that this works for all but one of the buttons – the one associated with variable gVar08. If this button has not been pressed, gVar08 remains empty and does not trigger the error message. I can’t figure out why. The scripts associated with the sample button and the evaluation button are provided below.
#Code for music sample button
global gVar08
on mouseDown
wait 30
if the mouseClick then
play audioClip "samples/C1/C1-8ConcertoForViolinStringsAndHarpsichordInGR202IAllegroMolto.wav"
set the filename of image "icn08" to "icons/if_abstract_symbol-03_1571964a.png"
add 1 to gVar08
else
grab me
end if
end mouseDown
#Code assigned to 9th button: Check to see if all samples played at least 1x
global gVar01, gVar02, gVar03, gVar04, gVar05, gVar06, gVar07, gVar08, gErr01
local sClct
on mouseUp
put gVar01, gVar02, gVar03, gVar04, gVar05, gVar06, gVar07, gVar08 into sClct
repeat for each item local in sClct
if local = "" then
answer "Have you listened to all of the samples? Be sure to play them all."
add 1 to gErr01
break
end if
end repeat
end mouseDown
You need a comma and “” after gVar08 in the list. When it is empty, the list ends with 7. Adding a this should always include the last value even if empty.
Since local is a reserved word, have you tried using a different variable?
I couldn't get your Music Sample button code to work, probably due to the mouseClick function within a mouseDown handler not triggering, so I came up with this option:
global gVar08
local sMove
on mouseUp
if sMove then
put empty into sMove
exit to top --Avoids playing the audio and adding 1 to gVar08 on move
end if
play audioClip "samples/C1/C1-8ConcertoForViolinStringsAndHarpsichordInGR202IAllegroMolto.wav"
set the filename of image "icn08" to "icons/if_abstract_symbol-03_1571964a.png"
add 1 to gVar08
end mouseUp
on mouseStillDown
if the mouse is down then
put "true" into sMove
grab me
end if
end mouseStillDown
Hope this helps.
Paul

How do LiveCode developers simulate multiple open documents from a standard template?

We need to create a text-editor type app that can open multiple text windows at the same time.
The windows should all use the same stack layout.
Is it possible to open one stack several times as if the stack were a template or "stationery"?
If so, then we could inject empty text into the text field on openStack to create a new blank text editor document using the stack as a template.
If the user wanted to open an existing text file, then we could put URL "file://xyz.txt" into field "Text Editor" of stack "the new text editor window"
This would be conceptually like the old Mac Classic idea of "Stationery" documents which were unchangeable, but when a user double-clicked on the document in the Finder it would open in a new window, and be called "Untitled #1".
We seem to remember there was once a setting in LiveCode to save a sub-stack as a "template" so that it could be used to display several identical windows.
After googling and searching through the LiveCode UI and Dictionary the only thing we found was
templateStack
If we were to use templateStack then we would have to build an entire stack programmatically, which defeats the simplicity of the LiveCode programming paradigm.
Are we approaching this wrong?
How do LiveCode developers simulate multiple open documents from a standard template?
The only workaroud which we had was to create a substack as a template, keep the template hidden, and then when we need a new text editor window we would need to:
Create a new totally empty stack
For each item in the template stack...
Create a duplicate item in the new text editor window.
Are we on the wrong track?
You could use "clone" as follows.
(This is not a 'simulation' but one way to use template stacks.)
local templatePath="/Users/admin/myTemplates"
on mouseUp
lock screen
-- clone from file
put templatePath & "/mytemplate.livecode" into longPath
clone stack longPath
-- # or clone from an open stack:
-- clone stack "mytemplate"
put 1 into J
repeat while there is a stack ("copy_"&J)
add 1 to J
end repeat
put ("copy_"&J) into newName
set name of it to newName -- named but not yet saved!
set title of stack newName to (newName & " (not yet saved)")
go stack newName
put URL ("file:" & templatePath & "/myNew.txt") into fld "mainEdit"
unlock screen
end mouseUp

Show back button even if no pages are in back stack

I'm making a Master/Details app with Template 10. The Master/Details Template 10 sample uses a CommandBar to get full control over when the back button is shown, but I'd like to show the back button on a PageHeader or on the shell. The problem is, since there is no back stack, the button refuses to be shown. How should I handle this?
Override the OnNavigatedTo event and set AppViewBackButtonVisibility to Visible in the code-behind file for each page that you want to enable the title bar back button.
Take a look here: http://grogansoft.com/blog/?p=1116
The important part is "AppViewBackButtonVisibility"
if (rootFrame.CanGoBack)
{
// Show UI in title bar if opted-in and in-app backstack is not empty.
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
AppViewBackButtonVisibility.Visible;
}
I also suggest you take a look at the AppBar properties.
Especially the Visibility which gets or sets the visibility of a UIElement and you could force the visibility of an item:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.appbar.aspx
So I've created a hacky solution to this. Basically I'm adding a dummy value onto the stack so that the back button thinks there is something to go back to.
var entry = new PageStackEntry(typeof(bool), null, null);
Frame.BackStack.Insert(0, entry);
Then I've added a BootStrapper.BackRequested event which sets HandledEventArgs.Handled to true so Template10 doesnt actually pop the page. That way I've got full control over the back stack and the back visibility.

How to create button to another stack - Livecode

I want to create button to another stack with code
I have two stack.And Stacks name is "AA" and "BB"
I want to create button in stack "BB" from stack "AA" with my code
on createDigits
create button "test" of stack "BB"
end createDigits
Results: It's create in stack name "AA" and this error message:
Here's one way to do what you want:
on createDigits
set the defaultStack to "BB"
create button "test"
end createDigits
What Mark said.
The "create" command only works on the current card. You therefore have to navigate to that card in order to use the command. Mark used the "defaultStack" command to navigate to the target stack. You could also:
lock screen.
go stack "BB".
create button "test".
go back
That sort of thing.
Craig Newman

Difference Between LostFocus Event and Leave Event of TextBox

What is the difference between the LostFocus and the Leave events of TextBox?
Check the notes section on these links:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.lostfocus.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.leave.aspx
According to MSDN, there is difference when changing focus of a control. The Leave event occurs before a validation and LostFocus occurs after validation.
UPDATE: 14 Feb 2019
I see that I'm still getting views and upvotes on the answer that I posted couple of years ago. It has now become imperative that I include a (rather important) quote from the MSDN links above to avoid confusion among new programmers (note the difference of order esp. in case of focus by using the mouse or by calling the Focus method):
When you change the focus by using the keyboard (TAB, SHIFT+TAB, and
so on), by calling the Select or SelectNextControl methods, or by
setting the ContainerControl.ActiveControl property to the current
form, focus events occur in the following order:
Enter
GotFocus
Leave <--- before validation
Validating --
|<--- validation
Validated --
LostFocus <--- after validation
When you change the focus by using the mouse or by calling the Focus
method, focus events occur in the following order:
Enter
GotFocus
LostFocus <--- before validation
Leave <--- before validation
Validating --
|<--- validation
Validated --
N.B: Emphasis on text and indicators in the quote added by me
They happen at different points in the control's lifecycle. Depending on the method used, validation happens after Leave and before LostFocus.
See MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.lostfocus.aspx
Leave() event means that first executes keyboard event and then executes mouse event where as Lost() event means that first executes mouse event and then executes keyboard event.
To sum up, it either won't work for the keyboard or it won't work for the mouse. Considering you can't predict what input method will be used it's not very helpful.
However, that's not my point. LostFocus will happen when the form loads, Leave does not.
This would turn the text box yellow when the form is loaded.
Private Sub txtBox_LostFocus(sender As Object, e As EventArgs) Handles TextBox.LostFocus
txtBox.BackColor = Color.Yellow
End Sub
This would not.
Private Sub txtBox_TextLeave(sender As Object, e As EventArgs) Handles TextBox.Leave
txtBox.BackColor = Color.Yellow
End Sub

Resources