Programming

How To Iterate Through an Associated Array in PHP

The following code will allow you to iterate through any associated array in PHP. The keys in the array are displayed in a bold font.


foreach ($list as $i => $values)
{
foreach ($values as $key => $value)
echo "$key => $value";

echo "
";
}

How to Update .NET Windows Controls at Runtime

If you change the value of a control on Windows .NET form during runtime, it may not be updated with the changes. The following code should change the Text property of ToolStripStatusLabel, but it doesn’t work while its processing in the middle of its function. When its the last command in the function, it will change the label."

label_Folder.Text = "Converting documents to PDF.";

If additional code follows the label_Folder statement, it may not update the Text property. You can force the property to update with the Refresh method:

label_Folder.Text = "Converting documents to PDF.";
label_Folder.Refresh ();

The label will then be updated with the new content. If your using a ToolStripStatusLabel, you don’t have the option of using Refresh this way, i.e.

toolStripStatusLabel_ProcessingStatus.Text = "Status: 12 of 19 documents processed.";
toolStripStatusLabel_ProcessingStatus.Refresh ();

Instead, use this.Refresh () to force an update:

toolStripStatusLabel_ProcessingStatus.Text = "Status: 12 of 19 documents processed.";
this.Refresh ();

Hello World Example in iText

iText is a .NET library for creating and manipulating PDF’s. It was originally written in Java but it was also ported to .NET. The book, “iText in Action”, has examples in Java only which will only be useful if a .NET developer knows this language.  C# examples can be found at iText.NET site. The code needs to be slightly modified for it to compile with Visual Studio 2010.

The first thing that need to change is the library references. It uses a Java style code which may have been used in an older version of iText for .NET.

using com.lowagie.text;
using com.lowagie.text.pdf;

should be written as:

using iTextSharp.text; 
using iTextSharp.text.pdf;

If you cut and paste the code from the examples to VS, you will see multiple errors. Change getInstance to GetInstance, open to Open, add to Add, close to Close. If your not sure about the function being used, delete it (include the period), type a period and the available functions will be listed.

The code will then compile correction in VS 2010. I recommend purchasing iText in Action because it will save you time in learning how to use iText. A knowledge of Java is beneficial, but not necessary to port the examples to .NET.

The following is a simple example of using iText with C#.

 

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text;

using iTextSharp.text; 
using iTextSharp.text.pdf;

namespace Chap0101 
{ 
  class Program 
  { 
    static void Main (string [] args) 
    { 
      Console.WriteLine ("Chapter 1 example 1: Hello World");

      // step 1: creation of a document-object
      Document document = new Document ();

      // step 2: 
      // we create a writer that listens to the document 
      // and directs a PDF-stream to a file 

      PdfWriter.GetInstance (document, new FileStream ("Chap0101.pdf", FileMode.Create));

      // step 3: we open the document 
      document.Open ();

      // step 4: we add a paragraph to the document 
      document.Add (new Paragraph ("Hello World"));

      // step 5: we close the document 
      document.Close (); 
    } 
  } 
}

3 Important Tools for Developing in JavaScript

JavaScript has become a language that every web developer must be deeply familiar with to build web applications, and it will even be heavily used in creating client applications for the upcoming Windows 8 operating system from Microsoft. The following sites will help you produce better, error-free JavaScript which is important if you want to maintain customer confidence over your products.

  1. JSFIDDLE (http://jsfiddle.net/)
    This site can be considered a sandbox for JavaScript. You can write code in HTML, CSS, and of course, JavaScript and run, test, and tidy up the code with automated tools.
  2. JSHINT (http://jshint.org/)
    Debugging tool for JavaScript and enforcing coding conventions. More powerful that JSLINT.
  3. JSONLint (http://www.jslint.com/)
    Specialized tool for validating JSON.

Free JavaScript and jQuery Video Tutorials

If your a web developer and don’t know JavaScript, you need to immediately learn it if you want to continue working in your field. If you don’t know jQuery, its a great idea to learn because it simplifies the use of JavaScript and can enhance your web sites to justify your six figure income.

There are many good books on JavaScript and jQuery, but if your pressed for time and don’t feel like doing a lot of reading, you can watch a series of videos that will get you up to speed. These learning videos were recently released by .appendTo and will have you coding like a pro in no time. The videos range in length from 23 to 43 minutes and teach the basics and advanced concepts in JavaScript, to DOM manipulation and effects/animations in jQuery.

The videos loaded a little slow when I tried them, but this was because I was viewing them during the heaviest Internet traffic hours. Its a good idea to master JavaScript and jQuery since these will be important development tools for building Windows 8 applications. This knowledge will also make your web sites stand out from the competition. Learning new things broadens your mind and these videos will only take an evening to go through them.