mardi 28 avril 2020

VBA Question: Running iterations using multiple for loops and exit once a certain condition has been made

I need help with my code, please.

I am running through a list defined in range M9:M53 using a VBA command button. I am Copying the first value in the list into a different cell in the same sheet, then I have formulas that generate calculations and output a value in cell K24.

This is a linear relationship, the more I go through the range the closer I get to exceed number 5. The idea is that I want the Loop to get as close to 5 before exceeding it. So a part of the missing component would be checking through the list, and copying the right number. So if M15 is the first cell value to be greater than 5, then I would want to copy the previous cell number M14 and leave it on the cell I6

The next part of the code that is missing would be a loop that must occur before I pass from each value in range M9 to M54.

Grab Value in Cell F5, and start subtracting 1. For example, it will the cell has input value 10, then it will check K24 if K24 is greater than 5, then it will subtract 1 again, and so on. if the K24 value is finally less than 5, then it will exit the LOOP completely and the program would have completed its function. ******

This number directly affects the result in K24 which checks for being less than 5. It should stop the closest that it can to generating a result that K24 than is less than 5, without exceeding it.

An Additional condition to step out of this loop and go onto the next value in list M9:M54 Range would be

Checking that the value in Cell A7 is greater than 13.5. Going lower would mean skipping to the next value in range M9:M54

One additional and final condition would be to check for Cell Value G5 being less than or equal to 120.

For example. If copying M15 yields and answer for K24 that is less than 5, but cell G5 still yields over 120, then it should still skip to next value in the M range, M16.

Below a portion of the loop which needs a lot of work.


Private Sub CommandButton1_Click()

Dim Cell As Range

For i = 9 To 53 Range("M" & i).Copy Range("I6")

If Range("K24").Value < 5 Then

Exit Sub

End If Next Application.CutCopyMode = False

End Sub

Loop with If-statement runs slow, too slow

I am new to JavaScript. I use it to write some scripts for Adobe Illustrator. In this script I take a selection of items, and sub-select them by some user definded values (xPointMin, xPointMax, etc.). The loop below is the main part of the function.

My problem is that this loop is terribly slow. It takes several sec. to run a selection of 50 items.

I already tried the following:

  1. run the loop without any if-condition inside. This is fast.
  2. run the loop with only one if-condition inside. This is as fast as with all if-conditions.

Does someone know why it is so slow or can some just make it faster.

// xArray... are extracted vales from the Selection (xSel)
// xPointMin, xPointmax, xLengthMin, xLengthMay, xAreaMin, and xAreaMax are user defined values

for (var i in xSel) { // xSel is a list of selected items
  var xTF = true; // xTF is temporary variable

  // points // this will check if the given value (xArrayPoint) is within the requirements
  if (xArrayPoint[i] <= xPointMin || xArrayPoint[i] >= xPointMax) {
    xTF = false; // if so it sets the temporary variable to false
  }

  //length // same as in the first check, however we are testing the length
  if (xArrayLength[i] <= xLengthMin || xArrayLength[i] >= xLengthMax) {
    xTF = false
  }
  //area // same as in the first check, however this time we are testing area
  if (xArrayArea[i] <= xAreaMin || xArrayArea[i] >= xAreaMax) {
    xTF = false
  }

  xSel[i].selected = xTF; // changes the original value
}
}

android :How to change color of text of counter app after ( 33,66,99,elc ) clicks?

How to change counter when is 33,66,99,elc ??

the project is here on githup https://github.com/hamza94max/Counter

any one can help me ?


public class MainActivity extends AppCompatActivity {
    TextView textView;
    private int counter = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView=findViewById(R.id.countertext);
        reset=findViewById(R.id.reset);
        RelativeLayout relativeLayout=findViewById(R.id.reltivee);



        relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                counter++;


                    textView.setText(Integer.toString(counter));
                    textView.setTextColor(Color.BLACK);


                }
        });


    }}

How to implement if loop inside switcher of python

I want to know how to use if loop or nested if loop inside a switch case or rather switcher case inside python.

comparing two variables in c++

learning c++ and I'm sure I'm overlooking something obvious but I'm not sure why I dont get a message that i == j even though after the 3rd iteration the numbers are the same ?

This is the output:

8 is not equal to 12

9 is not equal to 11

appreciate any hints!

#include<iostream>

int main(){

   int i=8;
   int j=12; 

   for (i,j; i!=j; ++i, --j)
   {    
   if (i == j) 
        {     
         std::cout << "i = j" << "\n";   // this part doesnt work
         break;
        }
   else 

        std::cout << i <<" is not equal to " << j <<"\n"; 

   }
}

Power Query: how to add one to a column when a specific values appear in an other column

I have an ID column and I am looking for ways to increment my IDs each time a specific item appears in my Geography column (ItalyZ, ItalyM, UKY or UKM) is found.

The ID of ItalyZ starts at 0 and ends at 4000.

The ID of ItalyB starts at 4000 and ends at 8000.

The ID of UKY starts at 0 and ends at 4000.

The ID of UKM starts at 4000 and ends at 8000.

However, I am refreshing my file, and I will thus have from time to time new arrivals of "geographies" without the origins or first IDs. These boundaries/ranges are only known beginning and ends.

Here is a sample of my data:

  |---------------------|------------------|    
  |       ID            |   Geography      |
  |---------------------|------------------|
  |    AB0000           |      ItalyZ      |
  |---------------------|------------------|
  |    AB4041           |      ItalyB      |
  |---------------------|------------------|
  |    BC0000           |      UKY         |
  |---------------------|------------------|
  |    BC4001           |      UKM         |
  |---------------------|------------------|
  |    NULL             |      ItalyZ      |
  |---------------------|------------------|
  |    NULL             |      ItalyZ      |
  |---------------------|------------------|
  |    NULL             |      UKY         |
  |---------------------|------------------|
  |    NULL             |      UKM         |
  |---------------------|------------------|  

Here is my expected output :

  |---------------------|------------------|    
  |       ID            |   Geography      |
  |---------------------|------------------|
  |    AB0000           |      ItalyZ      |
  |---------------------|------------------|
  |    AB4041           |      ItalyB      |
  |---------------------|------------------|
  |    BC0000           |      UKY         |
  |---------------------|------------------|
  |    BC4001           |      UKM         |
  |---------------------|------------------|
  |    AB0001           |      ItalyZ      |
  |---------------------|------------------|
  |    AB0001           |      ItalyZ      |
  |---------------------|------------------|
  |    AB4042           |      UKY         |
  |---------------------|------------------|
  |    BC0001           |      UKM         |
  |---------------------|------------------|  

I have been trying many various ways and trying to adapt running total solutions. I have also been trying to break apart my file in four different ones in order not to have an If function alternating between cases, and thus making it simpler, like this in my power query:

 #"Added Custom2" = Table.AddColumn(#"Reordered Columns", "Sum", each if [Geography] = "UKM" then [Number AB range below 4000] + 1 
else if [Geography] = "UKY" then [Number AB range above 4000] + 1 
else if [Geography] = "ItalyB" then [Number BC range above 5000]
else [Number BC range below 5000] + 1)

But absolutely nothing works. This maddening.

Populate a column in R [using if statements?] based on variable in another column

A seemingly simple task that I am struggling with:

I collected behavior data and have a column ("Behavior") in which I recorded what behavior is taking place. I would like to group these behaviors into categories and fill in a column ("BehaviorGroup") with the category name.

An example of how this might look:

Behavior      BehaviorGroup
bite          aggressive contact
ram           aggressive contact
avoid         avoid
fast-approach aggressive approach
flee          avoid
fast-approach aggressive approach

etc. 

So I would like to use the behaviors listed under the Behavior column (which I already have) to fill in the BehaviorGroup column (which is currently empty) based on the category.

For the example above: "bite" and "ram" are "aggressive contact" "avoid" and "flee" are "avoid" "fast-approach" is "aggressive approach"

I have MANY more but I'm hoping this is enough to get started on how to tackle the code to do this! I would greatly appreciate any and all help with this!

Here's code for what I would be working with, based on the example given:

Behavior <- c("bite", "ram", "avoid", "fast-approach", "flee", "fast-approach")
BehaviorGroup <- c("NA", "NA", "NA", "NA", "NA", "NA")
data.frame(Behavior,BehaviorGroup)

I'm just trying to fill in the BehaviorGroup column Thank you in advance!