I'm working on a program to learn how to use arrays in my computer course and my display button doesn't work properly after the first press. The first time I click it, it works properly and displays everything but the 2nd time it stop showing the first value and starts showing the last value twice, the 3rd time cuts off the 2nd value and displays the last value three times and so on. And when I press the button to find the sum of all values it gives me the sum of all of the values that will show up after I hit the display button. Here's my code, and sorry about the french commentary, it's for school.
function afficherFunction(event:MouseEvent):void
{
// Compose cette fonction visant à afficher tous les éléments du tableau.
txtSortie.text = "";
var entier:int;
entier = -1
for (var i:int=entier; i < mesEntiers.length; i++)
{
if (i+1 < mesEntiers.length)
{
mesEntiers[i] = mesEntiers[i+1];
affichage = affichage + mesEntiers[i] + "\n"
}
}
txtSortie.text = affichage;
affichage = "";
i = -1;
} //Fin fonction afficher.
mesEntiers[i] = mesEntiers[i+1];
This line is your problem. Not sure what you meant for that line to be doing, but it's setting the value at index i to the value at the next index--essentially shifting all the values down one (and losing the value at index 0).
Related
I am trying to make a table with python-docx.
This is my desire output:
¡--OK(bold)--¡--MIDDLE(in red)--¡----RIGHT¡
And this is what I get:
¡--OK(bold)--¡MIDDLE(in red)----¡RIGHT----¡
The code that I use is:
from docx import Document
from docx.shared import RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
document = Document()
table = document.add_table(rows=1, cols=3, style='Table Grid')
fila = table.rows[0].cells
# First cell: OK in bold
texto = 'OK'
dentro = fila[0].paragraphs[0]
dentro.add_run(texto).bold = True
dentro.alignment = WD_ALIGN_PARAGRAPH.CENTER
# Second cell: Middle in red
texto = 'MIDDLE'
dentro = fila[1].paragraphs[0].add_run(texto)
dentro.alignment = WD_ALIGN_PARAGRAPH.CENTER
font = dentro.font
font.color.rgb = RGBColor(255,0,0) # Red
# Third cell : Right
texto = 'RIGHT'
dentro = fila[2].paragraphs[0]
dentro.add_run(texto)
dentro.aligment = WD_ALIGN_PARAGRAPH.RIGHT
document.save('demo.docx')
I have two issues: First one is that I do not get the correct alignment in the middle cell when I add the color issue. Second one is that in cells after the wrong output of middle one, the alignment does not seem to work. How can I fix it? Do I have to wait until next version (actual 0.8.10)? Thanks,
Your code for the middle cell is different. You assign the new run to dentro rather than the paragraph. This causes the alignment value to be assigned to the run where it does nothing.
Change:
dentro = fila[1].paragraphs[0].add_run(texto)
to:
dentro = fila[1].paragraphs[0]
run = dentro.add_run(texto)
font = run.font
font.color.rgb = RGBColor(255, 0, 0)
I'm not sure how to account for the RIGHT alignment not "taking" on the third cell; I would make this fix and then see how you go.
I have a datatable with 10 columns which are grouped in 4:4:2 manner. Now the first two groups(of 4) are fixed while the last 2 can be added to any of the groups(single or both at a time) based on a condition.
Is there a way to set indexes for columns so that they can be ordered based on a condition ?
I see that Primefaces reorder using drag n drop gives the kind of result Im looking for except I want the reordering to be programmable and set before the table is displayed.
I had basically the same problem: after allowing the user to rearrange columns, it is easy to save the arrangement into a cookie, but how to restore the order a day later?
As far as I know, there are no primefaces method to this but can be hacked with a little javascript. (I tried with primefaces 6.0)
1) Give all the columns unique styleClasses, like:
styleClass="mystyle col0"
styleClass="mystyle col1"
styleClass="mystyle col2"
...
2) Convert the styleClass strings into valid css selectors, and store the required order of columns as an order of those, like:
".mystyle.col2,.mystyle.col0,.mystyle.col1"
Put it into a cookie, or store and get back as you like.
3) Write a javascript function to rearrange the cells into the required order:
function reorder() {
var o = getCookie('orderString');
var a = o.split(",");
for (var i = a.length - 1; i >= 0; i--) {
$(a[i]).each(function() {
$(this).prependTo($(this).parent())
});
}
}
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length === 2)
return parts.pop().split(";").shift();
}
(Don't use EL expressions to get back the order string from a backing bean, because it evaluates on page render, so won't update if the user rearranges the columns again.)
4) Execute reorder() "every time you need it".
You'll certainly need it on page loads:
$(document).ready(function() {
reorder();
});
but also on paging events, so add something like this:
<p:ajax event="page" oncomplete="reorder();" />
(And perhaps other times I've not met yet.)
I am attempting to find a way so that when a user enters text into the data list, they can come across the same entry by course number (E.G. "CS 101") or course name (E.G. "Intro to Computer Science).
Currently, what I have is only searchable by the value field:
<datalist id="tagList">
<option value=""></option>
<option value="CSCI 4950">Senior Software Project</option>
<option value="CSCI 5117">Developing the Interactive Web</option>
<option value="CSCI 5421">Advanced Algorithms</option>
<option value="CSCI 5980">Design Methods for Comp. Sci.</option>
</datalist>
The solution needs to work in the Android Webkit web browser (Phonegap) -- Chrome seems to handle Datalists the same as Android's native browser so if it works in Chrome I should be ok.
It needs to display both the course name and course number to the user
This needs to be generalizable and not hard-coded as I am using AngularJS to actually populate the full list of courses.
What I've tried
https://stackoverflow.com/a/22827978/2831961 -- For some reason, this didn't work.
I've also tried a similar strategy, but with the data-value attribute. That didn't work either. Unless I am responsible for some behind the scenes Javascript work that I am unaware of.
http://jsfiddle.net/rh48cgrj/3/
Here's a fiddle. I put the option values/text into key:value pairs in a javascript object. NOTE: the key is an index number and the value is the option value attribute AND the text. This makes it easier to search them for our text.
var i = 0;
var selectItems = {}
$('#tagList option').each(function() {
var listvalue = $(this).val();
var listtext = $(this).text();
selectItems[i] = listvalue + " " + listtext + ",";
i++;
});
Then I split them into rows that included both value and text.
count = i;
for(i=0; i < count;i++) {
var blockoftext = blockoftext + " " + selectItems[i].toLowerCase() + ",";
}
I then setup a search function that would search those rows to see if any returned a match, and if they did the result was outputted to a div below the search box.
var texttosplit = blockoftext.split(",");
var searchresults;
for(i=0; i < texttosplit.length; i++) {
(texttosplit[i].indexOf(searchvalue.toLowerCase()) != -1) ?
(searchresults = texttosplit[i] + "<br>") : false;
$("#searched").html(searchresults);
}
There's an example for all of the above in the fiddle.
EDIT: The below is the commented code for the loop to check if search text is in the datalist per op request.
for (i = 0; i < texttosplit.length; i++) {
//The above loops through our array of class values and titles
(texttosplit[i].indexOf(searchvalue.toLowerCase()) != -1) ?
// The above determines if our search text is in class title using a ternary operator
// our array of class values and titles is lowercase so we make
//sure our search text is lowercase as well
// if we find a match between the search text and the class title/values perform the following:
(searchresults = texttosplit[i].replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
})
// The above replaces the first char of every word with an uppercase char
.replace("Csci", "CSCI") + "<br>",
// The above finds Csci and changes it to CSCI since all THOSE letters should be uppercase
prevtext = $("#searched").html(),
//get current text of element with id "searched" and place it in prevtext
$("#searched").html(prevtext + searchresults))
//append "searched" by adding it's current text with the new searchresults
:
//if search text is not in the class title return false
false;
}
im very new to as3 so i would appreciate any help.
Im trying to make a counter only using the command "for".
im counting on this from 1 to 1000 in steps of 20.
the next step i want to make is to display on the output tab
i already know i can make it with "trace();", but i also want this to be displayed on
the main .swf window, im trying using a dynamic text-field which i named "dyna"
The problem is that, it is only displaying the last number. "1000" or changing very fast that i barely notice, and the last one remains.
var i:int;
for (i = 1; i < 1001; i+=20)
{
trace(i);
//dyna is the name of my dynamic textfiled
dyna.text = i.toString();
//dinamico.text = String(i);
}
-Is there any way to record all the numbers on my dynamic textbox, something like [1,20,40,60,....] horizontally or vertically.
-Or maybe someway to run this from a button step by step.
like [click, 20; click, 40; click 60.....]
Thanks in advance
var i:int;
var str:String="1";
for (i = 20; i < 1001; i+=20)
{
str=str+","+i;
}
dyna.autoSize = TextFieldAutoSize.LEFT;
dyna.text=str;
Output
1,20,40,60,80,100,120,140,160...
Hope it helps
To run this from the button step by step you need a button, a listener attached to the button, a counter available to both button and text field, and a bit of code. The button has to be somewhere on the stage or in your asset, and named somehow, so you can address it by the name. Here it's named yourButton:
var counter:int=0;
yourButton.addEventListener(MouseEvent.CLICK,updateDyna);
function updateDyna(e:MouseEvent):void {
counter+=20;
if (counter>1000) counter=1000;
dyna.text=counter.toString();
}
Here you are, click - 20, click - 40, etc., up to 1000.
I have this code that creates a decorated popup panel :
...
var x = 600;
var y = 150+row*23;
var popPanel = app.createDecoratedPopupPanel().setStyleAttributes({background:'#FFFFDD',padding:'15px'});
var message = app.createHTML("Opération non reversible !!<BR>Il faudra 'rafraichir' votre navigateur<BR>"+
"après vous être effacé du planning (case ✖)<BR>pour voir les données à jour").setPixelSize(300,60).setStyleAttributes({background:'#FFFFDD',padding:'15px'});
popPanel.add(message);
popPanel.setAnimationEnabled(true);
popPanel.setPopupPosition(x, y);
popPanel.setAutoHideEnabled(true);
popPanel.show();// I didn't chain the commands to make it easier to test by commenting one or another...
return app;
}
and it gives this result :
My question is : knowing that background attribute determines the surrounding zone (popup panel padding 15px) and that the inside widget has also its background color (and its own padding as well), how can I change the color of this blue frame ?
It seems that decorated** can not be redecorated in GAS. I too have wondered this (when working with decorated tab panels). I concluded that it was not possible. I used the Chrome inspector and found out that the blue part is actually a set of images. So it wouldn't be a simple CSS fix.
This thread seems to have the final verdict.
Thanks to the link from the other answer (leading to James Ferreira's site) I was able to build this new code that is a lot more easy to customize...
Here it is with the result below :
...
var x = 600;
var y = 150+row*23;
var popPanel = app.createPopupPanel().setStyleAttributes({background:'#ccccaa',padding:'5px', borderRadius:'15px 15px 15px 15px',borderColor:'#ffffdd',borderWidth:'5px'});
var message = app.createHTML("Opération non reversible !!<BR>Il faudra 'rafraichir' votre navigateur<BR>"+
"après vous être effacé du planning (case ✖)<BR>pour voir les données à jour").setPixelSize(300,60).setStyleAttributes({padding:'5px'});
popPanel.add(message); popPanel.setAnimationEnabled(true).setPopupPosition(x, y).setAutoHideEnabled(true).show();
return app;
}
The borderRadius:'px px px px' can be used on any widget, allowing for nice buttons as wel ;-)