2017년 8월 11일 금요일

how to remove parentheses when displaying lists?


Is there a way to remove the parentheses that appear around text when calling a list?
So im trying to put all text from a list into a label by; set textlable.text - and plugged into that is the global for the list. but the text displayed from the list is always surrounded by ( )
The way im doing it now is using the replace all and replacing all ( ) with nothing.
but surely there is a better way? i just cant figure it out.

--
Have you tried using a ForEach loop?

--
yeah, stevozip is right. use the [foreach] loop.
--
no i have not tried a foreach loop before, could you give a bit more information please? i tried a few things but no luck.

--
See attached for an alternative.
--
aah that is a better way of doing it, thanks hossein!

--
how do you use a foreach loop? I am trying to remove parentheses from displaying when stored data is recalled into a label to view.

--
assume your list is global items.

for each item - item(name)
lbloutput.text = make text item(Value)                                      \n(text)     
in list Items
Try that.

--
Thank you. Your solution work fine!.

--
Here's how I accomplished the task:
Consider the following objects:
The label at the bottom that shows the removed parentheses is named textResult.

I found that using Replace All will only remove one of the parentheses. Copying the same blocks with a second Replace All again will not remove the second ). 

So I Defined a variable named tempText as text "temp".
When you type in a string of text that includes (), and click button1, you tell it to take the text in TextBox1.text and first replace all "(" with "". The value of tempText will now be the string with all "(" removed. Then you tell it to take the resultant values that is now defined as tempText, and do a replace all ")" with "" and end up setting textResult.text as the string that has removed all ()'s. 

--

Removing parenthesis in a list


I need to create a list without those brackets that appears after using "list from csv table". I know I can use loops to create a new list without the brackets 
but I would like to do it other way because my Initialize blocks are huge in the menu screen.
Reading this: how to remove parentheses when displaying lists? there's someone called Hossein that talked about
an alternative way to do it but I didnt undestand his answer, can someone explain me what it is?

--
⦁ Displaying a List

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

--
I have a .txt file like this using Notepad:

a1
a2
a3
.
.
.
an

When I use the block "when file1.GotText" with "set listpicker elements to" "list from csv table text" "get text" I get this:

(a1)
(a2)
(a3)
.
.
.
(an)

I just dont want those parenthesis, because this is a list that has to be deploy in the menu, for information about the own app. My translation has 2 parts: something to put in a list and text for labels, etc.
I know how to eliminate the parenthesis only I select 1 of those items, but in this case I need the list like this:

a1
a2
a3
.
.
.
an

in a list.

-- 
I have a .txt file like this using Notepad:
a1
a2
a3
➠ to convert a 1 column csv table into a list, instead of the list from csv table block use the split block instead, just split at \n (new line) to get a list

-- 
Thanks, that was exactly what I was looking for.

--

Displaying a List


You'll often define list variables to store data. For instance, the following variable stores a list of phone numbers:
Variables such as BroadcastList are the hidden memory of the app-- the user can’t see them. If you want to display such a list on the device, you can use the ListView component. You just need to tell the ListView which list to display. You do this by setting its Elements property, as in the blocks below:
It’s important to remember that you should update the ListView each time the data in the list is changed. For example, if the user adds a new item in a TextBox and clicks submit, you should add the item to the list variable and re-set the ListView.Elements property, as in the sample below:

Serializing a List into a Label

The ListView displays list data in a fixed, vertical manner. If you want to display the list in a different way, such as horizontally with commas, or with decorative text (e.g., numbers in front of each item), you can serialize it into a Label component.
There are many ways to do this, where you would choose the most suitable approach depending on the way you want to use the serialized result.
Using list to csv row
The easiest way to serialize the BroadcastList would be to use the list to csv row block. We use DoIt (click on the block with your right mouse button and chooseDoIt) to show the result here.

A disadvantage is, that the values are enclosed in “. It is easy to correct this as follows:

Using while test
Another way to serialize a list is to use an iterator (foreach, while) block to successively add each item, and any separators or decoration, to the Label.
Here's a sample that displays the BroadcastList in a label, with commas in-between items. The blocks are within a procedure which you call anytime the list is modified.

How the Blocks Work

The BroadcastListLabel.Text is first initialized to “”, so you start out fresh each time the list is displayed.. Then, if the list is not empty, you place the first item into the Label. The while loop then successively adds the other items, placing a comma before each. Note how the blocks within the while loop append a comma and the new item to the end of the Label.
If the list has the items shown in the BroadcastList variable above, the code will first put 111-1111 into the Label. The while blocks will then be executed twice, for index=2 and index=3. During the first iteration, the blocks will add a comma and the second item (,222-2222) to the Label, so that it t will contain 111-1111,222-2222. During the second iteration, (,333-3333) will be appended so that the Label will end up as 111-1111, 222-2222, 333-3333.
Note: If you would like to display the list elements line-by-line, just insert \n instead of , (a comma), and the label will look like this:
111-1111
222-2222
333-3333

Using for each number from - to - by

Variations on the while test approach are to use for each from to by or for each item in list. We show the blocks for both approaches below.
Remark that we have to test for an empty list. If the list has at least one element, then we set the label to whatever is in the first item. Then, for each iteration the next element would be joined to the text. If the list would have only one element, the for each would do nothing because 2 is larger that the length of the list, 1 in this case.

Using for each item in list

A slightly neater solution is to use the for each item in list block:
The result would always have a , in front of the serialized string, except when the list is empty. We remove the , at the end, but we need to check whether the label indeed contains a comma.


Chat web by SimpleWebServer extension


in other post I sent an extension about a Simple Web Server.


- Now let's do an example about a local chat by web with that extension.

- Two users install this app. Each writes local ip of the other.

- [You can also try writing your ip].
com.KIO4_SimpleWebServer.aix

--
(added to new Chat section of FAQ): FAQ for Chat

--

FAQ for Chat


FAQ for Web Services Examples


Extension: Simple Web Server


this extension create a Simple Web Server.

Features and Restrictions:

1.- Only can serve one HTML file, this file is in SdCard, example in root SdCard: /mnt/sdcard/index.htm

2.- Also can serve a text

3.- File only with codes HTML, no images, It is posible externals link.
4.- This extension is a service, if you start this server, click back button mobile and run others apps, this server continue run.
5.- To stop this service, Click in Button1 or Button2 again, when stop service app is closed. With this code isn't posible stop service and continue run app. Button1 and Button2, start server and stop  "app & server".
6.- It Works in MIT COMPANION and installed (better installed).
7.- User must write in browser your local WiFi IP and port 8080, example: 192.168.1.5:8080
8.- My index.htm in only an HTML file example, to try copy in root SdCard (/mnt/sdcard/index.htm)
9. You can set a file (/mnt/sdcard/index.htm) and run server. Then close server-app. Run again server-app. Then set other file (/mnt/sdcard/other.htm) and run server again.
10.- Size extension only 13 KB.
--
what exactly is the advantage of using this extension compared to a webviewer component?

--
this is a web server, a web server serve web pages or files to users, in response to theirs requests.

WebViewer is a browser, as Chrome, Firefox,... to read htm pages or others files.

If you run this server in your app, others users from you local net, can read file in your /mnt/sdcard, example: /mnt/sdcard/file.htm

Others local users in theirs browsers in PC, mobile, tablet... can write your local IP, example: 192.168.1.5:8080 and read your page. (umm difficulty with english).

--
Do you need to use Webviewer to see output of the webserver, you didn't show these blocks?

I presume you need a routine to grab the local IP on each use, but won't each device create its own server, or do you simply have one app for the server and another app to access the server from other devices?

--
when you run this extension in your app, you mobile is a local web server. You find you IP, is easy, example when run MIT COMPANION show your local IP. 

Then you say this IP others user, those user in browsers PC, Android, tablet,...example Chrome, Firefox, WebWiever... write your local IP, example 192.168.1.5:8080 and get you file.

If you need static IP number in your mobile, you can set your router. MAC --------> IP.

--
Thanks Juan, it is making sense now :)

--
this version with a new block to get WiFi IP. 

--
(added to FAQ Web Services section) FAQ for Web Services Examples

--
I imagine this server would be useful for local chat without SMS or BlueTooth,
assuming local WiFi.  Clients of the server would need to poll it periodically.

--

I thought in a chat, perhaps if web page refresh in client by HMTL code http-equiv=”refresh” content="15" poll automatic

But principal restriction of this code is: you can't stop server and continue app. Whenever stop server, close app.

--
this is a new version com.KIO4_SimpleWebServer.aix extension, 7/august/2017

Fixed Stop server. Now when Stop server app doesn't close.

- To try example, please download files index.htm and baile.htm and copy in your: /mnt/sdcard/

- This simple web server can serve text but not images, but works with hotlink.

- Hotlinks works in PC browsers, but doesn't work for me in Chrome mobile.

--
hi,it is very good aix,and could you add a event to app,in the event can get the url path,then can analysis the url path to repose different to the client.

--
Thanks MiuMiu, I'll try that.
btw. in this post a chat example by this SimpleWebServer:

--
Thanks for you reply!

Chat with SimpleWebServer is a good idea! and expect you can add event notice to app and respose to request...

--

Mit Inventor to Service Mit Inventor and background applications


I'm Denis and I would ask an information about Background Application.
I need that my app works also when its screen is not shown. I read a lot of post online but I would ask if someone discovered some tool to leave an app created with Mit Inventor in background. I tried with TaifunNotification.MoveTaskToBack but doesn't works. Infact when i reload the app the numbers are not varied as expected.
Secondly I would ask if there is a way to convert my app created in Mit App Inventor2 for services.appinventor.mit.edu

--
I add that I tried to create an initial app with services.appinventor.mit.edu and then I tried to copy each screen from the project created with Mit Inventor 2.43 into the initial project created with Service Mit Inventor 2.36.
The following error appears "This project was saved with a newer version of the AppInventor system. We will attempt to load the project, but there may be compatibility issues.", but I don't know which functions induce this error.

-- 
MIT recently shared some thoughts on using AI2 as a Service. Do not expect any support any time soon for a Services version.

MIT AI2 development staff indicated recently they could " take the code we (MIT) have and put it into production. But people would be very disappointed when they find that devices with limited memory kill off background apps without warning. That a "simple" background app will either not run enough, because the phone goes into "deep sleep" or if we take a wakelock (to prevent deep sleep) battery life is terrible. People *hate* apps that drain their battery and make their phone warm (or hot!)."

Companion 2.36 is required to use the EXPERIMENTAL services link.  Users cannot use the current 2.43 Companion and expect apps to run.  For the moment, an AI2 Services option does not exist.  MIT's comments indicate that providing Services using AI2 is more difficult than they anticipated when they started to experiment with Services in late 2016.     I read their comments to indicate there will be no general background capability in AI2 in 2017 and perhaps never.  MIT is evaluating options for what appears to be 'limited background' processing.

If you have an immediate programming need for an app that can process in the background Dennis, I suggest you work with the professional Android Studio (which can create apps that do run in the background).  Services is presently unsupported on AI2.   You cannot convert your App to a services app.  The current version of Services is UNSTABLE and buggy.  

-- 
I would ask you two more information: first of all if possible to create a service in background which opens my app created in mit inventor more times with a delay and let to my app to load some data from a server and reclose when it finish the process.
Secondly if exist an automatic way to traslate my mit inventor app in android studio or other applications. I read a lot of forum about he same question, but these are of many years ago. Maybe today exists an automatic way. 

-- 
The reason you receive the warning about backward compatibility is due to the fact that every screen is saved with the version code of App Inventor used to create it. The services instance has not been updated to reflect new additions to App Inventor in the interim because it is not considered a production version of App Inventor (we currently maintain 4 such instances). For the most part, so long as you are not using services nor relying on the ShowListsAsJSON feature you can probably be okay using your newer screens in the older system. However, that being said please be prepared that this instance may go away or be replaced when we explore different implementations of background tasks.

Regarding your latter post about converting your project to Java, the only solution that I'm aware of is Dave Wolber's AI2 Java Bridge project. They provide a version of App Inventor that will generate Java code that you use with their libraries to build apps in Android Studio.

-- 

FAQ for Bluetooth/BLE and micro:bit


⦁ Micro:bit extension. This extension expands the generic BLE extension 
⦁ If you want to just try it out instead of building an app from scratch, here are pointers to sample projects for the LED matrix and temperature sensors:





I have a problem with AI2 BluetoothLE !!!


I am making a APP to control the leds. I finished the programing on the Arduino ,and the APP is connected the Arduino, but the APP can't view the characteristics of the service.
How can the APP read the characteristics ?? 



--
Are you sure your Characteristic UUID is correct? If you want to confirm this, use the following: "call BluetoothLE1.GetCharacteristicsForService" method using your service UUID as the input parameter.

-- 
I sure my UUID is correct.Because I can write Characteristic.And I don't find "call BluetoothLE1.GetCharacteristicsForService"method in AI2.
I use the extonsion is downloaded on the MIT website.

-- 
Looks like you could be using an old version of the BLE extension. 

I am not sure why it is so difficult to find a link to the correct version of the extension, as I too had problems. 

All it takes is a clear simple html link to be placed in a prominent position, with some h1 or h2 headers saying "New BLE extension", on the webpage, such as this one: 



Instead, I had to open up this pdf tutorial to find the link and download the correct extension (see bottom of page one).


Note, for full reference of new ble methods / block functions refer to the above link.

-- 
If you look in the FAQ (FAQ for Bluetooth/BLE and micro:bit) under the Bluetooth headings, you will find updated pointers.
We were promised that the right iOT versions will be more visible soon. (Try find the micro:bit extension for example ;-)
Keep your fingers crossed.

-- 
@Ghica / @Abraham Maybe as a suggestion, you should put the date of when new BLE extension was released. This will act as a trigger for people who assume they have the correct version.

E.g. 

Bluetooth/BLE

-- 
There was already a date, but maybe it was as hidden as the pointers to the extensions.
I tried to improve on it.

-- 
Lebin Liang wrote to me privately:
Hi..Do you have some suggestions??
Please, I told you already twice: do not write to me privately!

No I do not have any suggestion. Install the new extension, look into the documentation and go from there.

--