Why does Sleep(); function skip Label -> Text commands? - winforms

In my Programming I have made two Attack logs (they are labels) which display things that happen during a battle... But whenever I run the code, both labels skip all previous code and display the last thing that It was told to display...
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + " Attacked!!";
Sleep(500);
damage = rnd4 -> Next(-2,3) + EnemyA;
if (D > EnemyA)
{
damage = rnd4 -> Next(3,6);
this -> AttackLog -> Text = "[Attack Log] Your Armor Reduced the Damage!";
}
Sleep(500);
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + " did " + damage + " Damage";
Hp -= damage;
this -> HealthBar -> Value = Hp;
Sleep(800);
damage = rnd4 -> Next(-2,3) + A;
if (EnemyD > A)
{
damage = rnd4 -> Next(3,6);
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + "'s armor reduced damage!";
}
Sleep(1500);
this -> AttackLog -> Text = "[Attack Log] " + Name + " did " + damage + " Damage";
EnemyHp -= damage;
this -> EnemyHealth -> Value = EnemyHp;
If this did what i thought it would do, It would display
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + " Attacked!!";
for Half a second and move on to display the next code for Another half a second, But instead, all it does is wait for ALL the sleep functions (Which added together makes 3300 milliseconds) and THEN displays the text at the very end... which is
this -> AttackLog -> Text = "[Attack Log] " + Name + " did " + damage + " Damage";
Why does it skip all previous commands (for the labels text) but STILL waits for 3300 milliseconds?

It is probably down to the fact you are sleeping the UI thread. I've just tried a similar test in C# and I get the same issue. To fix this you will have to call Refresh on the textbox after setting the value.
Another way would be to do the work on a background thread and then marshal the "this->EnemyAttackLog->Text = sometext" code onto the UI thread. This way your UI will stay responsive.

Related

CodenameOne: Bug in Double.parseDouble on iOS

The following code :
String test1 = "1.000000108001807564";
String test2 = "1.0000001080018075648";
System.out.println(test1 + " -> " + Double.parseDouble(test1));
System.out.println(test2 + " -> " + Double.parseDouble(test2));
works correctly in the simulator and on Android:
1.000000108001807564 -> 1.0000001080018075
1.0000001080018075648 -> 1.0000001080018075
But fails on iOS:
1.000000108001807564 -> 1.0
1.0000001080018075648 -> -1.183888

Change font weight in a WPF label only for some parts

I have a calculator and the results are shown in a label. Is it possible to set the result values (some string, some double) to display in bold?
My code looks like this:
...{
label2.Content = "your time: " + saldoMin +
" and: " + fooNeg +
" " + inH +
" : " + inMin +
" [h : min]\nyour factor: " + YourFactor +
"\n\ngo at: " + beginnH +
" : " + fooNull;
}
and I only want the objects saldoMin, fooNeg, inH, ... to be bold, but not the code behind.
You can use a TextBlock with Runs. Here is an example:
var text = new TextBlock();
text.Inlines.Add(new Bold(new Run("Bold:")));
text.Inlines.Add(new Run(" nonbold"));
label2.Content = text;

Date and Time Format in SSIS

I have a date and time format:
Interval Start Time
1/13/16 1:30:00
1/15/16 10:30:00
Desired Result
Interval Start Time
13/01/2016 13:30:00 (24 Hr)
15/01/2016 10:30:00
The Interval Time is between 08:00 to 17:30.
I would like it to be: 13/01/2016 13:30 and 15/01/2016 10:30:00 and I devised this In SSIS derived Column:
(DT_DATE)(SUBSTRING([Interval Start Time],3,2) + "-" +
SUBSTRING([Interval Start Time],1,1) + "-" +
SUBSTRING([Interval Start Time],6,2) + " " +
SUBSTRING([Interval Start Time],9,1) == 1 ? "13" :
SUBSTRING([Interval Start Time],9,1) == 2 ? "14" :
SUBSTRING([Interval Start Time],9,1) == 3 ? "15" :
SUBSTRING([Interval Start Time],9,1) == 4 ? "16" :
SUBSTRING([Interval Start Time],9,1) == 5 ? "17" :
"[Interval Start Time]" )
+ ":" + SUBSTRING([Interval Start Time],11,2))
The error I get in SSIS is:
...The expression might contain an invalid token, an incomplete token, or an invalid element...
and I am not sure if the formula is correct in what I want it to do either. Any help would be much appreciated.
Before present a possible solution here, I want you be aware about some errors in your approach. Using expressions for this requeriment is very complex and hard to maintain, besides what happen when your Interval Start Time column have dates from October (10) to December (12) months, your string lenght will change and your hardcoded solution via SUBSTRING calls will return absurd data and produce error while package is running.
SOLUTION: Use Script component.
After creating your source, add a Script Component and link the source to it.
Configure the Script component to include Interval Start Time column by selecting it in Input Columns tab.
Add an output column, name it as you want and choose database timestamp (DT_DBTIMESTAMP).
Go to Script tab, and press the Edit Script... button.
Use the below code to overwrite the Input0_ProcessInputRow function.
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
/*
* Add your code here
*/
var str_timestamp = Row.IntervalStartTime.ToString();
string[] arr = str_timestamp.Trim().Split(' ');
string[] date = arr[0].Split('/');
string[] time = arr[1].Split(':');
string formatedDate = "20" + date[2] + "-" + date[0].PadLeft(2, '0') + "-" + date[1].PadLeft(2, '0');
int hour = Convert.ToInt32(time[0]);
int hour_24 = hour < 8 ? hour + 12 : hour;
formatedDate += " " + hour_24 + ":" + time[1] + ":" + time[2];
Row.MyColumn = Convert.ToDateTime(formatedDate);
}
In Row.MyColumn, replace MyColumn by the given name of your output column.
Save changes in Visual Studio and close the editor.
Now you can add a destination after the Script component and you will see the formatted IntervalStartTime as you need.
Let me know if this helps.

how to create pymol rename loop

I would like to create a loop for changing interactions name in PyMol. But after one selection loop it crashes and doesn't work.
def get_dists(interactions): # interactions=([1,2], [3,4])
for i in interactions:
a = "////" + str(i[0]) + "/C2'"
b = "////" + str(i[1]) + "/C2'"
cmd.distance("(" + a + ")", "(" + b + ")")
for j in range(1, 599):
x = "dist" + "0" + str(j)
y = str(i[0]) + " " + str(i[1])
cmd.set_name(str(x), str(y))
In Pymol the default name of interactions is dist01, 02 , 03.
I want to change these to 1_3, 5_59, 4_8, (interaction between residue).
Your code is totally fine except for one thing: If PyMol doesn't succeed with set_name the whole script is aborted. When you change it to, it should work:
try:
cmd.set_name(str(x), str(y))
except:
print('failed to rename')
Some additional comments:
y = str(i[0]) + " " + str(i[1]) should be y = str(i[0]) + "_" + str(i[1])
this line is probably for padding zeros x = "dist" + "0" + str(j). This is only needed when j is a single digit, otherwise the name of the distance objects is dist20 or dist123
cmd.set_name(str(x), str(y)) can be simplified to cmd.set_name(x, y) since x and y are already strings.

I have custom code that I need to bold for output. What google sheets script can I use?

I have created a customized work order submission form in Forms & Sheets that auto emails a confirmation from each submission (job request form) to create a data trail of vendor activity. Fairly integrated and totally cobbled together by a lot of reading in these forums coupled with a gazillion frustrating moments of trial & error. Novice moving towards "capable" but Im stuck on a piece of code for a triggered confirmation email with random work order generator and email confirmations and toggle based management built in. The code below that I actually need help with is for that triggered confirmation email that sends a confirmation of service, work order #, and also shows everything they originally submitted. The problem is that the code I have is providing the data exactly how and I want it and placement is great, but I need to create visual distinction between the column titles and the variable submission data. Can someone please help me add a bold code to the column titles in line 16 to help create that visual differentiation between columnar "category and submission data?
// This constant is written in column C for rows for which an email
// has been sent successfully.
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1000; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 27)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[19];
var message = row[16] + "\n\n" + "Submitted By: " + row[19] + "\n\n" + "Date Submitted: " + row[0] + "\n\n" + row[21] + "\n\n" + "IMPORTANT NOTES FROM CDS: " + row[20] + "\n\n" + "Full Show Services: " + row[3] + "\n\n" + "Event Start Date: " + row[4] + "\n\n" + "Event End Date: " + row[5] + "\n\n" + "Warehouse Locations: " + row[6] + "\n\n" + "Individual Services Requested: " + row[7] + "\n\n" + "Individual Services - Warehouse(s) & Date(s) Requested: " + row[8] + "\n\n" + "Partial Hourly Staffing Details Requested: " + row[9] + "\n\n" + "Requestors Instructions / Comments: " + row[10] + "\n\n" + "Files: " + row[11] + row[12] + "\n\n" + "Thank you for your request. We appreciate your business. CDS Special Events Team ";// Second columnn
var emailSent = row[18];
var subject = row[16];// Third columnvar ss = SpreadsheetApp.getActiveSpreadsheet();
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 19).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}

Resources