Add Two Numbers (Visual F# Windows Forms Application)

I’d been desperately combing the net for a while now looking for some tutorials relating to simple computations in Visual F# Windows Forms Application unfortunately I got no fluke finding some so I decided to make one. Today we will be making a simple application that adds two numbers and I hope that this will give you a head start in building advanced application using F# Windows Forms.
To create an application that adds two numbers, follow these simple steps:

1. Click Start>All Programs>Microsoft Visual Studio 2008>Microsoft Visual Studio 2008.

2. Click File>New>Project>Select Visual F# in the project types>Select F# application in the Visual Studio installed templates category.

3. Click the Project menu>Add reference>Click the .Net tab>Locate then double-click System.Windows.Forms.
Do step number 3 again and this time,select System.Drawing

4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:

// Learn more about F# at http://fsharp.net
//uses the F# standard library
open System
//specifies the location of the Drawing classes
open System.Drawing
//specifies the namespace memory location of the form class
open System.Windows.Forms
//creates a new form
let addform=new Form(Text="Add Numbers", Size=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)
//creates a label
let n1label=new Label(Text="First number:",Top=20,Left=5,AutoSize=true)
let firsttextbox=new TextBox(Location=new System.Drawing.Point(80, 20))
//creates another label and change its text to “Second number:”
let n2label=new Label(Text="Second number:", Location=new System.Drawing.Point(0,50),AutoSize=true)
let secondtextbox=new TextBox(Location=new System.Drawing.Point(100,50))
//creates another label and change its text to sum
let n3label=new Label(Text="Sum:", Location=new System.Drawing.Point(0, 90),AutoSize=true)
//creates a label that will display the result of the computation
let anslabel=new Label(Location=new System.Drawing.Point(80, 90))
//make our buttons
let addbutton=new Button(Text="Add", Location=new System.Drawing.Point(100, 130))
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(200, 130))
//add the controls into the form
addform.Controls.Add(n1label)
addform.Controls.Add(firsttextbox)
addform.Controls.Add(n2label)
addform.Controls.Add(secondtextbox)
addform.Controls.Add(n3label)
addform.Controls.Add(anslabel)
addform.Controls.Add(addbutton)
addform.Controls.Add(exitbutton)

//when the add button is clicked
addbutton.Click.Add(fun addfunction ->
//convert the textbox values to unsigned int
let firstnum=Convert.ToUInt32(firsttextbox.Text)
let secondnum=Convert.ToUInt32(secondtextbox.Text)
let sumval=firstnum + secondnum
//display the sum in the anslabel
anslabel.Text<-Convert.ToString(sumval))
 //when the exit button is clicked, close the form            
exitbutton.Click.Add(fun exit -> addform.Close())  
addform.Show()
Application.Run(addform)

6. Press Ctrl+F5 or click the run icon to execute your application. You should now see something similar to the screenshot below:



7. That's all. Enjoy programming!

Fixing the “Fatal Error: Call to undefined imagecreate() function” in PHP

The "call to undefined imagecreate() function" normally appears if you try to execute graphic related scripts such as CAPTCHA scripts. To fix this problem, follow these simple steps:

1. Download a copy of PHP zip package from http://php.net/downloads.php.

2. For the sake of example, we will be using PHP 5.2.14 Windows Binary Zip Package.

3. Once you have downloaded the file, Right-Click it>Extract files>In the Winrar Destination path, enter “C:\PHP\” no quotes. If you have previously installed PHP distros just overwrite it.(I’ve assumed here that you have Winrar installed on your computer.)

4. Go to where your PHP file was extracted, in this case in the C:\ directory.

5. Locate php.ini-dist and rename it to php.ini.(Overwite the previous php.ini).



6. Right-click php.ini>Select Open. The following should then appear:



7. Click Edit>Select Find then enter extension_dir in the Find what textbox.



8. Change the line extension_dir=”./” to extension_dir=”C:\PHP\ext”.



9. Click Edit>Find>Enter “gd”(no quotes) in the Find what textbox then click Find Next.



10. Delete the semi-colon(;) before the line ;extension=php_gd2.dll.




11. Click File the Save. You should now be able to execute your captcha scripts without errors. Here is the screenshot of my captcha that I was able to execute effortlessly using these fixes:



12. If you continue to encounter error messages, try restarting your computer.

13. That's all. Ciao!