samedi 27 août 2016

How can I create an array based in a IF funtion

I'm new at VBA and coding. My problem is as follows: I have an array of data in a spreadsheet conformed by client's names and the day the order product. What I need to do is create a new array, in a different spreadsheet, where I can have every client listed (without repeating) on column A and the associated order date for each client on column B, C an so on. So basically is converting the raw data into useful data. I would really appreciate any type of help!! The VBA looks as follows:

Sub Test_1()
Application.ScreenUpdating = False

' Statment

Dim Client As String
Dim Order_date As Date
Dim Counter As Integer
Dim Data As Worksheet
Dim Data_storage As Worksheet
Dim i As Integer

Counter = 10

' Core
' For every value in column B *This values are going to be clients names * They are going to be repeated value in this column *This data is in the Data spreadsheet

' When the counter begins, if new Client is detected
' Then paste in worksheet Data_storage in column A and paste in column B the Order_date value *Every Client will have a order date associated

' If's a repeated Client, only paste the Order_date value in the next column with no value of the existing Client



End Sub

How do I validate more efficiently?

I don't know what everyone calls this but how do I make this piece of code shorter??

I was taught to not repeat code and at the GetAddress() method the if statement I repeat the same line twice, once from the if statement and then another from the else if statement below it

(_CClientFirstName == "John" || _CClientLastName == "Jenkins" || _CClientAge == 21)

How would I do this with less code? Im just wondering if it's possible because if it is, I would love to know. Also, please don't reply with anything too complex as Im only starting out, but if you do then try to explain it as much as you can thanks.

class ClientInfo
{
    private string _CClientFirstName = "Default";
    private string _CClientLastName = "Default";
    private int _CClientAge = 99;

    public ClientInfo(string FullName, string LastName, int Age)
    {
        _CClientFirstName = FullName;
        _CClientLastName = LastName;
        _CClientAge = Age;
    }

    public string GetAddress()
    {
        if (_CClientFirstName == "John" || _CClientLastName == "Jenkins" || _CClientAge == 21)
        {
            return $"{_CClientFirstName}'s address is: 67 Smokey Lane, London, B78 9JN, United Kingdom";
        }
        else if (_CClientFirstName == "Matt" || _CClientLastName == "Benks" || _CClientAge == 25)
        {

        }
    }
}

vendredi 26 août 2016

Two Conditions but invalid syntax

So, I'm still a beginner in python. Right now, I want to create a small script that asked the user for their age.

Instead of asking for their age, I thought that I could, as a learning experience, have the script calculate their age based on their birth year. I also thought I could have the script check if the user's input was an integer and additionally check if the user's input had 4 digits.

Using an if-else statement, once the user's input passed these two conditionals it will print the user's age, else print an error.

My problem is I'm getting an invalid syntax error. The terminal is pointing at the "4" digit with the error.

import datetime

now = datetime.datetime.now()

print('Hello World')
print('What is your name?')
myName = input()
print('It is good to meet you ' + myName + '!')
print('The length of your name is: ' + str(len(myName)) + ' characters')
myAge = input('What year were you born: ')
if type(myAge) == int and len(str(myAge)) = 4
    print('You will be ' + str(now.year - int(myAge)) + ' this year!')
else
    print('That is not a number')

not equals not working in java

I tried the following code :

if (!object.equals(null)) {
                object.setItem(object2.getTime());
}

Here, object and object1 are objects two classes.

The problem is that it enter into the statement for a null value.

Python: Function not holding the value of a variable after execution

I'm trying to convert a string input (y/n) into an integer (1/0). The function appears to be working, as when the 'convert' function is executed using 'a' as an argument, the argument is printed inside the function, however printing outside the function uses the original value of the variable 'a'. I've tried using return inside the 'convert' function, but this appears to have no affect.

a = input("Are you happy?(y/n)")

def convert(x):
    if x == ('y'):
        x = 1
    if x == ('n'):
        x = 0
    print (x)

convert(a)
print (a)

>>> Are you happy?(y/n)y
1
y

ACF PHP if else layout - banner/slideshow

I am new to ACF and PHP, I am getting an error, but I am not sure what I am doing wrong.

<!--BANNER STATIC OR SLIDESHOW LAYOUT-->
<?php if(get_row_layout() == 'banner'): // layout: Content ?>
    <section class="banner">
        <?php
         $sbimage = get_field('static_banner'); // Array returned by Advanced Custom Fields
         $sbimageAlt = $sbimage['alt']; // Grab, from the array, the 'alt'
         $sbimageWidth = $sbimage['width']; // Grab, from the array, the 'width'
         $sbimageHeight = $sbimage['height']; // Grab, from the array, the 'height'
         $sbimageThumbURL = $sbimage['sizes']['large']; //grab from the array, the 'sizes', and from it, the 'thumbnail'
        ?>
        <?php if(get_field('static_banner')): ?>
        <a href="<?php the_field('static_url'); ?>">
        <img src="<?php echo $sbimageThumbURL;?>"  alt="<?php echo $sbimageAlt; ?>"  width="<?php echo $sbimageWidth; ?>"  height="<?php echo $sbimageHeight; ?>" /></a>
    </section>
<?php else: ?>
    <section class="banner">
        <?php the_field('slideshow_banner'); ?>
    </section>
<?php endif; ?>

JAVA: If condition is met, yet it acts as though it isn't [duplicate]

This question already has an answer here:

I'm writing a java "guess my number" sort of game. In the first part of the game, the player selects the difficulty of the game (Easy, Medium, Hard). My problem is that when I play, the game will return "Invalid Response" regardless of what I type into the text box. I know what I'm typing in matches a valid response, but it doesn't seem to think so. What am I doing wrong?

I've attached the first part of the game code below, where the player selects the difficulty. This is process then eventually determines the variable "guessThis0," which is the number to guess during the actual game...

//Guess My Number Game

import java.util.Scanner;
import javax.swing.JOptionPane;

public class playGuessMyNumberGame {

@SuppressWarnings({ "unused", "resource" })
public static void main(String[] args)
{

    boolean gameOver = false;  //becomes 'true' when player WINS or LOSES
    boolean playAgain = true;  //decides if player would like to play again
    boolean setUpDone = false; //for player setup loop
    int guessThis0;  //Target number
    int guessesRemaining = 12;  //Player starting guesses
    int highLimit = 500;  //Highest the Answer can be. Set by (player-chosen) difficulty

    //PLAYER SETUP
    while(setUpDone == false)
    {
        /*
        Scanner playerDifficulty0 = new Scanner(System.in);
        String playerDifficulty = playerDifficulty0.next();
        */
        String playerDifficulty = JOptionPane.showInputDialog("CHOOSE DIFFICULTY \nPlease Enter: 'Easy,' 'Medium,' or 'Hard.' ");
        if(playerDifficulty == "Easy")
        {
            highLimit = 250;
            setUpDone = true;
        }
        if(playerDifficulty == "Hard")
        {
            highLimit = 1500;
            setUpDone = true;
        }
        if(playerDifficulty == "Moderate")
        {
            highLimit = 750;
            setUpDone = true;
        }
        else //This is what it returns regardless of what I type in:
        {
            System.out.println("Not a valid response. Please try again. \n");
        } // ^ This is what it return regardless of what I type in ^
    }
System.exit(0);
guessThis0 = 0 + (int)(Math.random() * highLimit);

//PLAY GAME
}
}