I'm trying to built an Android application in MIT App Inventor 2.
This is my design
This is my code blocks
My purpose is; when I click somewhere on the color wheel; getting the coordinates of the place that I clicked (black ball) and get its RGB values.
It works perfectly on phone screen, it shows the values. But the problem is; when I try to import the rgb values to Firebase, the values are like in this format in this picture
As you see, the text formats in their boxes are like: "\"101\""
But I want: 101 only. Because I will get the values to my NodeMCU ESP8266 for blink a RGB LED. I will insert these values to analogWrite(pin,value) function.
Where is my fault in MIT App Inventor Block screen? Is there any solution in there? Or can you give me suggestion about it for ESP8266 code part (like split the text or something) ?
You can add this line
String b_fir = Firebase.getString("B");
String str_b_fir = getStringPartByNr(b_fir, '"', 1);
int int_b_fir = str_b_fir.toInt();
You can add this function under the loop
String getStringPartByNr(String data, char separator, int index)
{
// spliting a string and return the part nr index
// split by separator
int stringData = 0; //variable to count data part nr
String dataPart = ""; //variable to hole the return text
for(int i = 0; i<data.length()-1; i++) { //Walk through the text one letter at a time
if(data[i]==separator) {
//Count the number of times separator character appears in the text
stringData++;
}else if(stringData==index) {
//get the text when separator is the rignt one
dataPart.concat(data[i]);
}else if(stringData>index) {
//return text and stop if the next separator appears - to save CPU-time
return dataPart;
break;
}
}
//return text if this is the last part
return dataPart;
}
Related
Trying to ditch Excel for Google sheets.
I have this empty table with some colored cells that I need to fill with symbols. Presently I use this VBA script to do the job:
Sub mark()
Dim r As Range
Dim rCell As Range
Set r = Selection.Cells
For Each rCell In r
If rCell.Interior.ColorIndex = 10 Then rCell.Value = "×"
If rCell.Interior.ColorIndex = 3 Then rCell.Value = "×"
If rCell.Interior.ColorIndex = 45 Then rCell.Value = "×"
If rCell.Interior.ColorIndex = 1 Then rCell.Value = "×"
If rCell.Interior.ColorIndex = 15 Then rCell.Value = "×"
Next
End Sub
Is there a way to accomplish same thing using google sheets?
Solution
In order to achieve this you will have to use Google Apps Script. You can attach an Apps Script project to your Google Spreadsheet by navigating Tools > Script Editor.
You should find a template function called myFunction, a perfect starting point for your script.
Here you can start translating your VBA script to Apps Script which is very similar to Javascript.
First you should define some constants for your script:
// An array containing the color codes you want to check
const colors = ['#00ff00']; // Watch out, it's case sensitive
// A reference to the attached Spreadsheet
const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SheetName'); // Selecting the Worksheet we want to work with by name
// Here we retrieve the color codes of the backgrounds of the range we want to check
const range = ss.getDataRange().getBackgrounds(); // Here I select all the cells with data in them
Let's now loop through our range rows and columns to apply the logic:
The .getBackgrounds() method returns a multidimensional array in the form array[row][column] -> "background-color-code".
for (let i = 0; i<range.length; i++) {
let row = range[i];
// Let's loop through the row now
for (let j = 0; j< row.length; j++) {
let color = row[j];
// If the background color code is among the ones we are checking we set the cell value to "x"
if(colors.includes(color)) {
// Javascript index notation is 0 based, Spreadsheet one though, starts from 1
ss.getRange(i+1, j+1).setValue("x"); // Let's add 1 to our indexes to reference the correct cell with the .getRange(row, column) function
}
}
}
Reference
Please take a look at the documentation for further reading and method specifications
Google Apps Script Spreadsheet Service
Range Class
.getBackgrounds()
.getRange(row,column)
I have an online spreadsheet that I maintain that tracks all live local channels in each market for streaming TV providers (Sling, DIRECTV NOW, PS Vue, Youtube TV, Philo, etc)
http://streambuzz.net/streaming-tv-local-channels/
I am using the following formula to include cells in the count of totals:
=countif(B5:B199,"<>")
Each non empty cell will have a logo representing one of the major network affiliates (ABC, CBS, FOX, NBC, CW, MyTV, Telemundo)
However, I need to be able to track when a station that was active suddenly goes off the air and becomes on demand only (usually due to failed retrans negotiations) such as happened this week when Playstation Vue customers lost all Tribune owned Fox stations (about a dozen major cities affected)
In that case, I want to highlight the cell with a white background but leave the Fox logo there to indicate a special case.
So, long question short, how can I append the formula condition to count the cell only if its non empty AND has a white background?
You could write a custom function like this:
function checkw(row1, row2, column) { // input is range of cells like "A1:A25"
var counter = 0;
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
for (var row = row1; row <= row2; row++) {
var cellobj = sheet.getRange(row, column);
var cellval = cellobj.getValue();
var currentColor = cellobj.getBackground();
if (currentColor === "#ffffff" && cellval === "") {
counter++;
}
Logger.log(counter);
}
return counter;
}
and call it from a cell in your spreadsheet like this:
=checkw(2,22,1)
The first two args are the beginning and ending rows. The third arg is the column.
I have read this,but it can only work well in English for it just use white-space and something like NewlineCharacterSet as separator.
I want to add a left arrow and a right arrow in the accessory input view to move the cursor in UITextView by words.
And I am wondering how to support that feature for some Asian languages like Chinese
PS:I will added an example that CFStringTokenizer failed to work with when there are both English Characters and Chinese characters
test string:
Happy Christmas! Text view test 云存储容器测试开心 yeap
the expected boundaries:
Happy/ Christmas!/ Text/ view/ test/ 云/存储/容器/测试/开心/ yeap/
the boundaries show in reality:
Happy/ Christmas!/ Text/ view/ test/ 云存储容器测试开心/ yeap/
I don't speak Chinese, but according to the documentation,
CFStringTokenizer is able to find word boundaries in many languages,
including Asian languages.
The following code shows how to advance from one word ("world" at position 6)
to the next word ("This" at position 13):
// Test string.
NSString *string = #"Hello world. This is great.";
// Create tokenizer
CFStringTokenizerRef tokenizer = CFStringTokenizerCreate(NULL,
(__bridge CFStringRef)(string),
CFRangeMake(0, [string length]),
kCFStringTokenizerUnitWordBoundary,
CFLocaleCopyCurrent());
// Start with a position that is inside the word "world".
CFIndex position = 6;
// Goto current token ("world")
CFStringTokenizerTokenType tokenType;
tokenType = CFStringTokenizerGoToTokenAtIndex(tokenizer, position);
if (tokenType != kCFStringTokenizerTokenNone) {
// Advance to next "normal" token:
tokenType = CFStringTokenizerAdvanceToNextToken(tokenizer);
while (tokenType != kCFStringTokenizerTokenNone && tokenType != kCFStringTokenizerTokenNormal) {
tokenType = CFStringTokenizerAdvanceToNextToken(tokenizer);
}
if (tokenType != kCFStringTokenizerTokenNone) {
// Get the location of next token in the string:
CFRange range = CFStringTokenizerGetCurrentTokenRange(tokenizer);
position = range.location;
NSLog(#"%ld", position);
// Output: 13 = position of the word "This"
}
}
There is no CFStringTokenizerAdvanceToPreviousToken() function, so to move to
the previous word you have to start at the beginning of the string and advance forward.
Finnally I use UITextInputTokenizer to realized the function
I'm building an IOS app. I want the user to input two options from a text field. One of the options will later be randomly displayed in a label. I'm thinking the text field should log the information in an NSMutableArray that I can later call on. The information only needs to be temporarily stored because it will go away after it is randomly displayed in the label.
I'm not sure how to do create this array from a text field. Any help is appreciated.
Is this what your looking for?
int choice = rand() % 2;
NSString* result;
if (choice == 0)
result = textField1.text;
else
result = textField2.text;
....
label.text = result;
I'm new to iOS and Objective C and I'm having trouble figuring out how to use NSData correctly.
I want to count the number of new lines in my data.
// filedata is pulled from a URL asyn
NSInteger knt = 0;
NSInteger len = filedata.length;
const char *pointer = [filedata bytes];
for (NSInteger spot = 0; spot < len; spot++) {
if (pointer[spot] == 10) { // 10 is new line
knt++;
}
}
The count is off, is there a better way to do this?
Try checking for carriage returns as well (ascii 13 http://www.asciitable.com/).
Make sure the newlines are TRULY newlines (ascii 10). You can try this by opening up your data in a hex editor. Hex editors generally will show you text in a right pane, bytes in a middle pain, and addresses of the bytes in a left pane.
If this doesn't resolve your question, please consider posting sample data.