Set click button events in a loop - app-inventor

In my application, there are several buttons with the same actions:
when button1.Click do ...
when button2.Click do ...
when button3.Click do ...
when button4.Click do ...
...
Can I set a click events for them inside a loop?

you can call the same procedure in each button click event and pass the button id as input parameter
when button1.Click do
call myProcedure "1"...
when button2.Click do
call myProcedure "2"...
when button3.Click do
call myProcedure "3"...
when button4.Click do
call myProcedure "4"...
then in a for each loop you could do something like this (assuming there are 4 buttons) and pass the current number to the procedure
for each number from 1 to 4 do
call procedure "number"
A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles
How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .
Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Related

Blocking code in custom message box in VB6

In my vb6 project, I created my own msgbox using a form, due to difficulties in changing
the font/language of in-built msgbox. A search with google gave the idea of own msg-
box rather than trying msgbox of VB. Now the problem is : - when the user exits the
program, 3 options are given: to close, to restart and to cancel exit. The user need not
again go through the process of giving password etc in restart option. If I give cancel =
true in the QueryUnload event, then 2nd option does not work, 3rd option works. If
cancel = true is not given, 2nd option works, but 3rd option does not. It appears that
the main form does not get unloaded if cancel = true. Unless & until the main form
unloads, the program will not work with the fresh data to be given by the user in the
initial Form. Since the code after "msgbox.show" depends on options, it is not possible
to write that code in the same sub, not even in the same form code. Is there any way
to stop the subsequent code after "msgbox.show" and continue the same after getting
option? (like in the in-built msgbox of VB.) I am not an expert in VB, so please correct
if I made some mistake; also help with advice/suggestions.
EDIT:- [Extended explanation]
The 3 forms in my project:
Initial form for password, data etc. This is input Form for user.
Main Form. This Form shows the results after process of input.
frmMsgBox. This is a custom msgbox created using a form.
Main Form code portion. Code for closing the program:
Private Sub Form_QueryUnload(Cancel as.......)
cancel = True
frmMsgBox.Label1.caption = Do you wish to 1.Exit 2.Restart
3.Cancel the exit?
frmMsgBox.Show
End sub
(The above msgbox is almost like an in-built msgbox in VB with
vbYesNoCancel buttons) The message is in regional language,
which was the main reason forced me to use my own msgbox.
After MsgBox appears, the user selects one of the above options
using 3 commandButtons placed in that Form. The code after
clicking these buttons is written in the code portion of frmMsgBox:
Command1_Click 'This is for Exit from the Program.
All Forms.unload, All forms set to nothing, end.
Command2_click 'This is for restarting the Program.
Unload Main Form, set to nothing
Load Initial Form
Initial Fom.show
frmMsgBox.Hide
Command3_Click 'This is for cancelling the exit request.
Main Form.Show
frmMsgBox.Hide
With the above code, I have no problem with options 1 & 3,
i.e; to exit from the program or to start. The frmMsgBox hides,
the initial form shows - these are OK, but the main form does
not unload nor it is removed from memory. Because of this,
whatever new data is given by the user in the initial form now
is not being processed, the main form is struck with the old results.
If cancel = true is removed from the code above, Options 1 & 2
are OK, but option 3 does not work. Then the Main Form loses
all its results (all labels, texts etc in that Form turn blank.)

Xamarin.Forms Accessibilty VoiceReader

Quick question.
When it comes to Xamarin Forms, I noticed that if there is an alert called from the ViewModel
e.g:
DisplayAlertAsync("Title","Message", "Ok");
That the voice assistant only auto reads the first parameter of DisplayAlertAsync ("title") and does not auto-advance to the following parameters.
So, a temporary solution I did was concatenate the 1st and 2nd parameters into the 2nd parameter, so that VoiceReader auto reads both the title and message for accessibility users.
e.g:
DisplayAlertAsync("" ,"Title"+ "\n"+ Message", "Ok");
Is there a way to keep the traditional DisplayAlertAsync("Title","Message", "Ok"); parameter assignment, and have VoiceReader auto advance to the following parameters?
What you are looking at is expected behavior. Since Xamarin Forms uses Native APIs, so the alert dialog in the native platforms also does the same thing- Whenever you open a new page/alert, it should read the Title of that view.
For the most part, what you want to keep an eye out for is images & icons, you have to override the description of those items.
Q. Is there a way to keep the traditional DisplayAlertAsync("Title","Message", "Ok"); parameter assignment, and have VoiceOver/TalkBack auto advance to the following parameters?
A. No there isn't, you would have to create your own custom renderer if you want the reader to read everything.

what is the best way to switch from or exit from formFlow to Dialog in Bot Framework

Here is my Basic Code
The formFlow works fine and after checking the if condition ,it should go to the else part ,which it does, but in the else part the wrote this line of code
await Conversation.SendAsync(activity, () => new AskMeAnything());
AskMeAnything is a class implementing Idialog. The problem is ,its again going/calling the formflow rather than jumping into the above mentioned dialog.
I read about IdialogStack but unable to understand how to remove the dialog on top of stack or something related to it.
i need help in moving to other dialog without looping into formflow.
Thanks
The first time you call Conversation.SendAsync(...) you actually create a root dialog for your conversation. Every consecutive call to the bot will still enter the controller but will be routed to the dialog at the top of the stack.
So when you call Conversation.SendAsync(...) for a second time you are actually trying to change the root dialog in the stack. I don't think this is possible and that's why your form is called again.
To solve this problem I would create a different dialog and make that dialog your root dialog. From this root dialog you can call your form and any other dialog.

Firefox Add-on SDK context-menu communicate with a content script loaded by page-mod

I'm creating a Firefox add-on with the Firefox Add-on SDK. This add-on does two things:
Inject a content script into every page with sdk/page-mod.
Add a context menu item using sdk/context-menu.
I want that when user clicks the context menu item, the add-on will call functions in the content script which was loaded by PageMod().
Unless your page-mod script is doing other things, it sounds like it might be more appropriate to load it using the context-menu contentScript or contentScriptFile properties. Alternately, load the portions of it that are needed by the context menu using this methodology. How best to split the script you are using depends on what you are actually doing. Without more information from you it is difficult to provide specific recommendations.
Communicating between content scripts loaded at different times or by different methods:
There is no method of directly doing what you desire. Content scripts that are not loaded at the same time by the same methodology are loaded into different contexts. They are unable to directly call functions between them. Multiple content scripts which are loaded at the same time and the same methodology share the same context/scope and can directly call functions between them.
However, you can communicate between content scripts. If they are not loaded into the same page, then you will need to communicate from one content script to another by using your main add-on script to first receive a message from one content script. Then, your main add-on script will need to send a second message (potentially containing exactly the same data) to the second content script. In other words, your main add-on code would need to relay the message between the two content scripts.
For content scripts that are loaded into the same page via different methods (e.g. one with page-mod and another as a context menu item – the situation in which you are interested), you can communicate directly between them using the DOM postMessage() API or a CustomEvent. Either can be used to send whatever JSON serializable data you desire between the two scripts. The DOM postMessage() API provides for more security, but is a bit more complex. With it you must also filter out any other "message" events that are sent on it by random code. It should probably be used if you are going to have code in a released add-on execute functions based on the content of the messages. This is a security issue which will depend on exactly what you are doing with the messages.
Example:
The following code will load a page-mod script into every page that matches "*.mozilla.org". It also creates a context menu item in those same pages which is displayed on links. Clicking on the context menu item will send an event from the context-menu content script with data containing the URL for which the context menu was displayed. The custom event will be received by the page-mod script. The page-mod script will then issue an alert with the URL for the link.
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*.mozilla.org",
contentScript: 'function contextMenuAlert(href) {'
+ ' window.alert("The context menu click on a link with URL:\\n" + href);'
+ '};'
+ 'window.addEventListener("myAddonId-contextMenu-clicked",'
+ ' function(event){contextMenuAlert(event.detail);});'
});
//Context menu
let cm = require("sdk/context-menu");
cm.Item({
label: "Alert link URL",
context: [
cm.URLContext(["*.mozilla.org"]),
cm.SelectorContext("a[href]")
],
contentScript: 'self.on("click", function (node, data) {'
+ ' var event = new CustomEvent("myAddonId-contextMenu-clicked",'
+ ' {detail:node.href});'
+ ' window.dispatchEvent(event);'
+ '});'
});
The above code produces a context menu that looks like:
When clicked on, the page-mod added content script initiates the following alert:
Using the message sent to choose from multiple different functions:
The information passed through the event can be expanded to allow multiple different functions to be called depending on the content. One method of doing this is to send an object as the message. One property of the object can be the function desired and another can be data to use in that function. My answers to the following questions contain examples of doing this:
Add menu item created with the sdk/context-menu API to the top of the context menu: This answer has code which uses the same passed message to indicate that either a click was made on a context menu item and pass the URL on which the context menu item was clicked, or to tell the main script that the context menu is about to be displayed so it can be modified.
How to console.log from ChromeWorker (alternative to dump): This answer shows sending a message that will result in a call to one of a variety of different functions and pass data to the function which was called. It was implemented as a way of using console methods from a worker with just console.log("message"). I'd code this one a bit differently were I doing it today, but it works and demonstrates the concept.
Because the documentation on MDN (here and here) was not very clear on content script to content script communication, I have updated the pages I found on which it was discussed. I have also added the above code as an example.

How to use main menu handle in TrackPopupMenu()

I am recently reading the article of Petzold Charles's Programming Windows(5th Edition), in the book's p371, it mentioned you can display a popup menu by making use of the main menu(which you created like below:)
MENUDEMO MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New", IDM_FILE_NEW
END
POPUP "&Edit"
BEGIN
MENUITEM "&Undo", IDM_EDIT_UNDO
END
END
That the TrackPopupMenu requires a popup menu handle, and the handle acquired from above resource is not. But as the book said you can refer to MS Knowledge Base Q99806 to find the solution on how to walk around this.
I have tried to search that article but cannot find(It seems, over the years, Microsoft has moved many such articles). If anyone has a copy of it or knows the solution, would you please share it with me. Thank you for your help in advance.
hBar=LoadMenu;
hPop=GetSubMenu(hBar,0);
RemoveMenu(hBar,0,MF_BYPOSITION);
TrackPopupMenuEx(hPop,...);

Resources