Loading file random text to label - app-inventor

I want to load a file from my computer into the MIT App Inventor. The file should have these lines. "Nice", "Well Done", "Good Job".
When a user press a button, a label will have the text "Nice", "Well Done" or "Good Job". I want it to choose random. How can i do this? I also have a file with over 200 quotes in it, that I want to load, and not write them as text manually.
How can i do this?
When i press randomtextButton on phone, i get error:
Error 2102: The file "myText.txt" could not be found
The file is uploaded in the designer screen -> Media -> "Upload File..." What is wrong?

I'm assuming, you stored each item in a separate line in the file like this:
Nice
Well Done
Good Job
To read a file from the assets, use // together with the file name. In the File.GotText event you have to convert the text first into a list using the split block (just split at \n, which is new line) to get a list and then use the pick a random item block.
Btw. it helps to read the tooltips of the File.ReadFrom block or the documentation, how the file component works...
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

Injecting VBA As Text Into A PowerPoint Presentation

I think the answer to this will be "no" but it doesn't hurt to ask - and get people thinking.
I'd like to be able to programmatically add VBA as a text string to a PowerPoint presentation I'm creating with python-pptx.
I know I can confect the XML to create a button that, when clicked, runs a macro that already exists in the .pptm file.
Because the macro is stored compiled I don't think I can inject it as text programmatically. (I checked the format of a .pptm file with a "Hello World" macro in and there is an extra file in it with non-text material in.)
I also don't know if I can write a .pptm (macro-enabled .pptx) file with python-pptx.
So, Has anyone experimented with this?
The best I think I might be able to do - in md2pptx - is allow the user to add buttons that call pre-existing macros in the template file when clicked on. Unless the user builds their own template file off one I supply I don't think that enables me to add general function (such as deleting the first slide or note taking).

How can I acquire text from text filed

I am new to programming and am trying to design a Fortune Teller game according to a book "Applescript studio programming for the absolute beginner".
When the player types the question in the Text Field and then clicks the "Ask" button, the program will randomly give the answer "Yes" "No" "Maybe".
I did as the book instructed. But when I press build and go in Xcode, it returns "2018-04-08 22:22:01.189 Fortune Teller[14813:245050] *** -[AppDelegate clicked:]: Can’t get every text of TextField of class "NSObject". (error -1728)"
Can anyone tell me how to fix that problem? Thank you!
The following is the interface.
The following is the code.
-- This code runs whenever the player clicks on the Ask button
on clicked_(theObject)
-- Assign the text entered by the player clicks on the Ask button
set the question to contents of text field "textbox" of window "main"
-- Display an error message if the player did not enter any text
if question = "" then
display dialogue ¬
"Sorry, but you did not ask a question. Please try again."¬
buttons {"OK"}
return
end if
-- Assign a random number between 1 and 3 to a variable named random
set randomNo to a random number from 1 to 3
if randomNo = 1 then
set answer to "Yes"
end if
if randomNo = 2 then
set answer to "No"
end if
if randomNo = 3 then
set answer to "Maybe"
end if
beep -- Play a beep sound to get player's intention
display display dialog "Question:" & question & "Answer:" & answer & buttons {"OK"}
end clicked_
Ouch. Get a new book.
Mac OS X 10.6 replaced AppleScript Studio with AppleScript-ObjC. Unlike ASS, which gave you AppleScript-style commands and classes for controlling Cocoa, ASOC is just a thin wrapper around Cocoa’s Objective-C APIs, meaning you need to learn those APIs before you can use it.
Shane Stanley used to have an e-book on GUI programming with ASOC, but I think it’s out of print unfortunately. There was an introductory chapter to GUI programming with ASOC at the end of Apress’s Learn AppleScript, 3rd edition (which I co-wrote), and the AppleScript Users mailing list/MacScripter.net forum can no doubt point you to whatever other resources are out there. But all in all, documentation and support is not great. You pretty much have to learn ObjC in order to use ASOC effectively, even if just to read the Cocoa documentation and translate it to AS syntax in your head. And it hasn’t been updated in several years so lacks support for newer ObjC features such as blocks, which means you end up writing ObjC code anyway if you want to use those APIs.
..
Frankly, if your goal is to write your own GUI Apps (rather than automate existing ones), I strongly recommend you bite the bullet and learn Apple’s Swift. While it’s a bloated mess of a language, it’s well-documented, widely-used, and 100% supported by Apple [unlike AppleScript]. With Apple recently announcing a new GUI framework for writing iOS and macOS apps, it’s clear that Swift is the future.
If you need a bit of AppleScript to talk to other apps, it is possible to mix Swift and AS in the same app; but that’s a different question for a separate post.

find a better control to display book content in a e-book reader

I want to create an e-book reader app, I have tried to use the control RichTextBox to display the content of a chapter in a book, while, it could not display the entire chapter, finally, I am told that the size of any control in windows phone is less then 2048px, and this causes the text located after 2048px (Height) in the RichTextBox could not be displayed. So, I need to find another one control to do such a thing. Is there any suggestion?
Further more, I want the control may meet the following requirements:
it could customize the fontsize, forecolor of the text displayed in it (this may be the simplest one)
it could customize the background pic.
it allow the user to select the text on it freely for copy (this is the most important one of the 3)
Since an ebook is fundamentally a set of HTML pages, you should display your pages using a web control.
By the way, customizing font size etc. is not by any means trivial, because you end up trying to figure out whether or not and how to override CSS rules in the book.
You might want to check out http://openbookreader.codeplex.com/, although it seems to have been inactive for a couple of years.

Autocomplete/suggest functionality in an applescript input box

I am trying to build an applescript dialog that helps me keep track of the things I am working on. To make it really effective I'd like to have it look up items from my todo list and suggest them as I type a la google suggest or other javascript autocomplete functionality.
I was thinking it would be fairly simple if I just captured the input of the # key, which I wanted to use to denote project or the # key for tasks and at that point started matching the input to my list of tasks or projects. For example, lets say I type:
"Worked on feature for #"
At this point the input of the # would start capturing keyboard input and try to suggest one of the projects on my todo list. This is where I am stuck. It seems like I should be able to attach a listener or something to my input box but I can't seem to find any examples or reference to such functionality.
You can't do this with applescript. You need to build your own window in a cocoa application and then hook into the NSTextField's methods to do this. It's not too difficult but it requires a whole different set of skills than applescript.

Possible To Print 4-Up From Visual Studio?

I got nowhere Googling for this question so if this is a "Google Is Your Friend (GIYF)" question, I apologize in advance.
I always print source code duplex to save paper. Is there an add-in for VS (2003) which allows you to print two pages on one side of the paper so I can print 4 pages on one sheet? I think this is called 4-Up printing. I'm almost certain I can do this if I drop the printing out to a file and then use an external utility but I'd like to be able to do this all from within VS.
This is usually a function of the printer driver. I use it on the Canon printers to print out pamphlets and the like.
If you have the features for duplex and multipage printing, it'll be in the printer properties of the Print dialog.
To print both sides of the page (duplex), you'll need a duplex attachment on the printer or do the old even/odd page two-pass printing.
As spoulson says, its a function of the printer,
Go File->Print
Click on "Properties . . ." button
Find an option called "Pages per
sheet" (on my currently selected
printer it's on the "Finishing" tab.
Set it to the desired number of
pages
Hope this helps
If you want more control than your printer driver provides, take a look at FinePrint.
It works as a virtual printer and can do all sorts of layout manipulations on print jobs. It can even combine several print jobs into one.

Resources