Articles

Round A Number In MS SQL

To round a number in MS SQL use the ROUND() function. This function takes two parameters, the first is the number to be rounded and the second is the number of decimal places to round the number to. Here is an example of rounding the numbers in a column to the nearest whole integer.

Concatenate Strings In MS SQL

If you want to concatenate the output of three different columns in MS SQL just use the + symbol.

Populating A TileList On Creation Complete Using XML In Flex

A TileList is part of a group of elements that allow you to add components in a specific order and orientation. The TileList controls the displaying of a number of items set out as tiles and so it best suited to displaying images as thumbnails.

There are many ways to do this, but none of the examples on the Flex site seemed to be very useful, or very well explained. What I wanted to do was to create a TileList that displayed the tiles in a certain way and used an XML file to fill up the list of items with images, each image having a label associated with it.

The first thing to do is to create the TileList element.

<mx:TileList id="imageTileList"
itemRenderer="CustomItemRenderer"
dataProvider="{theImages}"
width="200"
height="400"
columnCount="2"
creationComplete="initList();"/>

This contains three important attributes, which I have described here.

External Script Files And Printing Objects With Flex

Yesterday I talked about using the Flex Script element to run code within the mxml file, you can also use the source attribute of the Script element to reference external files. To create an external script file FlashDevelop go to the File->New and select Blank Document. You can also do this by pressing Ctrl+N. This will create a blank document that you must save into your src folder of your project with the extension as. Note that if you call this file "sourcefile.as" then you must reference this in your script tag like this.

The Script Element, Adding An Action To A Button And Functions In Flex

Yesterday I talked about creating some simple Flex elements in your application. Today I will introduce a new element called Script.

The Script element, if you haven't already guessed is used to run your application function and should be contained within the Application element. You can either put script inline like this.

<mx:Script>
// some code here
</mx:Script>

Or you can use the source attribute and link it with an external ActionScript source file.

Creating Some Simple Flex Interface Elements

Following on from my previous blog post about installing Flex on Windows I thought I would go through how to create an interface using mxml. When you create a Flex 3 project the first file you are given is called Main.mxml, which has the following content.

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
 
</mx:Application>

This file is used to compile and run your Flex project and is the central starting point for all the rest of the compile process. This file controls your interface of your program. At first this file might look daunting, but there are lots of elements to select from and if you know CSS then you should be somewhat familiar with how elements are coloured, padded and positioned.

Installing Flex 3 On Windows

Flex is a powerful SDK that allows you to build Flash applications that can then be embedded into any web page. The SDK is that Flex uses quite large and covers a whole range of things from interface controls to data processing. To program in Flex you need to use ActionScript 3. What Flex creates as output is swf files, which can be run separately or embedded into a web page.

To get started you will need the Flex SDK. Download the Flex SDK 3 zip file and extract it into a directory where you can get to it. As an example, I put mine in C:\dev\flex_sdk_3.

Swap Values Without Temporary Varaibles In PHP

I have talked about swapping values without a temporary third variable before, but there is another way to do this which doesn't make the code unreadable. This is by using the list() function in the following way.

$a = 1;
$b = 2;
list($a,$b) = array($b,$a);

This swaps the two values over. The good thing about this function is that you can swap any number of values over without the need to create lots of confusing temporary variables or using complicated looking bitwise operators. Take 4 variables.

$a = 1;
$b = 2;
$c = 3;
$d = 4;

These values can be entirely swapped using the list() function in the following way.

Enable Drag And Drop Script In Wordpress

Note: This code has been written with WordPress 2.8 in mind. It won't work on versions prior to 2.6 and might have unpredictable results in later versions.

Drag and drop is a useful mechanism to do stuff and can turn a complicated set of buttons or drop down lists into a simple elegant solution.

Wordpress has lots of scripts built in, which do a lot of useful functions. However, they are not enabled by default, which means that in order to get your script to work you need to enable them.

The drag and drop functionality in Wordpress is provided by the Scriptaculous framework. To get Wordpress to include this in your page header just use the function wp_enqueue_script() with the parameter "scriptaculous-dragdrop".

Adding And Updating Options In Wordpress

Wordpress has an options table that developers can use when creating templates and plugins to store information that would otherwise have to be kept in a separate table or written to a file. Assuming the default table prefix of wp_ the options table is called wp_options.

Rather than allow developers to access this table directly, Wordpress has some functions that you can use to create and change options in that table.

To create an option and assign a null value to it use the add_option() function. The parameters are as follows: