Tuesday, April 7, 2015

Perimeter and Area of a Square Solver in PHP


A simple program that I wrote in PHP to solve the perimeter and area of a square by providing the value of the side of the square by the user. 


If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com. People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360





Sample Program Output



Program Listing


<html>
<title> Perimeter and Area of a Square Solver </title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
</style>
<?php
error_reporting(0);

$values = $_POST['value'];

 // functions to find the perimeter and area of a square

 function perimeter_solve($variable) {
           return($variable * 4);
}

 function area_solve($variable) {
           return($variable * $variable);
}


if(isset($_POST['check'])) {

     if (ctype_alpha($values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
  $values="";
 }
 
else if(preg_match('#[^a-zA-Z0-9]#', $values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
        $values="";
      
}

    else  if ($values=="") {
      echo "<script>";  
  echo "alert('It Cannot Be Empty!!! Please enter a integer value.');";
  echo "</script>";
  $values="";
           }
else { 
      $title = "The value of the side of the square is ".$values." the equivalent in perimeter is " 
          .perimeter_solve($values)." . <br>";
$title .= "The value of the side of the square is  ".$values." the equivalent in area is" 
          .area_solve($values).".";
      
       }  
   }  

if(isset($_POST['clear'])) {
  $values=" "; 
  $title=" ";
  
}

?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center"> Perimeter and Area of a Square Solver</h2>
  <br>
<form action="" method="post">
 Enter the side value : <input type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=20/>
   <input type="submit" name="check" value="Compute" 
  title="Click here to compute the perimeter and area of the square."/>
  <input type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>
<br> 
<?php 
echo $title;
 ?>
  </body>
</html>

Demonstration of Cookies in PHP



In this article I would like to share with you about a cookie in PHP basically a cookie is a method we use in PHP to identify the user that visited or uses our website. It is a small file the is being send by our server to our user's computer. Every the the user computer send a request to our page with the use of a web browser, it will send a cookie also to the user via a web browser. The code is very simple and easy to understand.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360




Sample Program Output


Program Listing

<?php
$cookie_name = "visitors";
$cookie_value = "Jake Pomperada";
?>

<html>
<title> Demonstration of Cookies PHP</title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
</style>

<body>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center">Demonstration of Cookies in PHP</h2>
  

<?php
if(isset($_COOKIE[$cookie_name])) {  
$last = $_COOKIE[$cookie_name];  
echo "Welcome back, " . $cookie_value . "! <br>
<br> You last visited this site is ". $last. ".";  
} else {  
echo "Welcome to our website , ". $cookie_value. "!";  
?>

</body>
</div>
</html>


Saturday, April 4, 2015

Search a Record Using Visual Basic 6 and MS Access

In this code I would like to show you how to search a record using Microsoft Visual Basic 6 as my programming language and Microsoft Access as my database. I wrote this code as one of the programming project of my client before. You will find the code is very easy to understand and use in your programming projects using Visual Basic 6.

Thank you very much and Happy Productive Programming. If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com. People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360.




Sample Program Output



Employees Commission System in Visual Basic 6

Here is a code that I wrote for a client in United Kingdom I called this program Employees Commission System written entirely in Microsoft Visual Basic 6 and Microsoft Access as my back end database. This program will save,navigate and compute the commission of the employees in a company.

Thank you very much and Happy Productive Programming.


If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360.





Sample Program Output


 

Prime Numbers in Visual Basic 6


One of the most fascinating inventions made by man is the computer. We use computers in our day to day activities such as in business, education, research, military applications, communications as well as entertainment. This computer becomes useful when there is software that runs on it. As we all know software is a collection of programs that makes our computer useful and interesting to work with.  There two classifications of software that we use in our computer system they are application software and system software. The first type of software is application software this type of software was designed to solve common problems that we encounter just like a word processing program like Microsoft Word we use this program to create and print our documents, computer games for instance is a good example of application software it was designed not only to entertain us but also it develops our thinking skills in making decisions and analysis of the situation. 

On the other hand system software was created to maintain the overall operation of our computer system examples of this is operating system that manages all the software and hardware components installed in our computer. Another example is your antivirus software which protects your computer against computer viruses that will damage our files and disable the normal operation of our computer in general.

In this article I will discuss about the program that I considered as application software by its nature I called this program Find the Prime Numbers.  Let me explain in the first place what is a prime number is  an number that is bigger than one and does not have a positive divisor other that one and itself.  We have learned the prime numbers during our elementary and high school days. Examples of prime numbers is  2,3,5,7,11,13,17,19, 23 and 29 for instance. In this program I will be using Visual Basic 6 as my programming language to illustrate of program Find Prime Number. I choose Visual Basic 6 because it is very easy to use and its ability to create sophisticated user interface compared to other programming language that you are the one who will write the statements for its design and layout stage. Having this advantage of Visual Basic 6 we can cut down big amount of our development time and we can focus on solving the problem on hand.

For our program the first thing that will do is to create the form and put a series of objects two command buttons, a list box where the list of prime number will be listed. The first command button is Find the Prime Number when the user click that button it will ask the user using a dialog box to enter the starting value of the number after the user give the initial values our program will ask the user to enter the last range or the maximum number which the generation of prime numbers will be stop.  When the user press the enter key the program will list the values of prime numbers from the given parameters earlier by our user.  Below is the command button cmdPrime for checking if the starting number and the end number by the user and then it will perform a series of computation to find the list of prime numbers. The result will be displayed in the list box adjacent to our command buttons.

Private Sub cmdPrime_Click()
    lstResults.Clear
    lblResults = "Results:"
    lngStart = InputBox("Enter the beginning number:", "Start Number")
    lngEnd = InputBox("Enter the ending number:", "End Number")
   
    lngStart = lngStart + 1
    Do Until lngStart = lngEnd
        If PrimeStatus(lngStart) = True Then
            lstResults.AddItem Str(lngStart)
            lngCount = lngCount + 1
        Else
         End If
        lngStart = lngStart + 1
    Loop
    lblResults = lblResults & " " & Str(lngCount)
    lngCount = 0
   
End Sub

This is the function that we have created to perform the computation and analysis of values of prime numbers in our program.

Function PrimeStatus(TestVal As Long) As Boolean
   Dim Lim As Integer
   PrimeStatus = True
   Lim = Sqr(TestVal)
   For I = 2 To Lim
      If TestVal Mod I = 0 Then
         PrimeStatus = False
         Exit For
      End If
        Next I
End Function
This is the general declaration of our variables it means we can use this variables anywhere in our program.
Public lngStart As Long
Public lngEnd As Long
Public lngCount As Long

Quit command button when the user click this button our program will be terminated and will return to our operating system.
Private Sub cmdExit_Click()
    End
End Sub

I just hope that you have learned something new about programming with this article Find the Prime Numbers using Visual Basic 6. If you have some comments, suggestions about this article feel free to email me I will be grad to answer your questions.

Thank you very much and Happy Productive Programming.


If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360





Sample Program Output



Word Count in Visual Basic 6

In  this simple article I would like to share with you a program that I wrote a long time ago in Microsoft Visual Basic 6 that will count the number of words in a given sentence I called this program word count program. The program is very simple and easy to understand it will give you some idea how to use visual basic 6 build in string functions to count the number of words in a given sentence by our user.


If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360





Sample Program Output


Loan Interest Solver in Visual Basic 6

Most of us experiencing some financial problems in our lives we need to borrow money to support ourselves and our family. We cannot deny the reality in life that it is not easy to earn money for a living especially our economy is not stable enough to provide most people secure jobs to have a steady income.  When we make a loan from a bank, financial institution like a lending company or individual person the money that we loan has a interest for them to earn their money in return. That is called investment of their money in business stand of point. There are several agreements that the lender and the creditor can be agree for example let say a person would like to loan of an amount of $2000 the interest rate that is being agreed by both parties including the lender and the creditor is 10% per month interest rate payable for within two months for example.  That will be $200 dollars per month for two months it will be $400 to the total amount to be paid per month is $1200 for two months the total amount that is due is $2400. This computation is very simple is we are dealing only with monthly payment for a small amount.

How about if the loan is big amount let say $10,000 with 5% interest per year  or annum and payable for 10 years with compounded interest penalty rate if the payment was not able to be paid within the set payment schedule? What is the correct formula to derive to the solution to the problem to answer this question I created a program in Microsoft Visual Basic 6 I called this program Loan Compound Interest Solver.  This program will help the creditor and its customer compute the interest amount to be paid per year depending to the amount to be loaned, the interest rate that is being agree and the number of years the amount to be paid to the creditor or lender of the money.

I make the program very easy to use and does not use complicated programming codes to compute the interest rate of the amount to be paid. The first step that we do is the creation of the graphical user interface that will interact to the end user of our program. In this case we have a first label that will ask the user what is the principal amount to be loaned the value is being stored in a textbox we named the textbox txtAmount.text.  The second label we are the user to enter the interest rate we store the value in a textbox named txtInterest.txt  in this case we use numerical value rather than putting a number with a percentage symbol to avoid confusion on the part of our end user. The third label our program will ask again the user now many years to be paid in this portion every year there is a computation that is being performed by our program to get the amount that should be paid by the customer to its creditor for example a bank or any financial institution the variable that we will use for the storage of the years to be paid will be store in txtYears.txt.

After these values is being provided by the end user of our program the next step is for the user to press or click the compute button to perform a series of computation that shows the amount to be paid every year and the amount including its interest in our list box.  When the values is being listed in our list box the user has the option to clear the values by selecting the clear button it will erase all the contents of computation in the list box and the values in the text box so that the user can put a new set of values to be computed by our program. If the user is done all the computation the user is given a chance to quit the program by pressing the quit button. This quit button will display a confirmation dialog box that asking the user if the user is really sure to quit the program or not.  

Below is the complete program listing of our Loan Compounded Interest Solver.


Option Explicit

Private Sub cmd_compute_Click()
 Dim years, years2 As Integer
              Dim Interest_Rate_Value As Double
Dim Amount_Loaned As Currency
Dim Principal_Amount As Currency
lstdisplayvalues.Clear
years = Val(txtYears.Text)
Principal_Amount = Val(txtAmount.Text)

Interest_Rate_Value = (Val(txtInterest.Text) / 100)

lstdisplayvalues.AddItem vbTab & " Year " & vbTab & " Amount On Deposit "

For years2 = 1 To years

                Amount_Loaned = Principal_Amount * (1 + Interest_Rate_Value) ^ years2
 lstdisplayvalues.AddItem vbTab & Format$(years2, "@@@@") & vbTab & _
                          Format$(Format$(Amount_Loaned, "Currency"), _
                          String$(17, "@"))
 Next years2
End Sub

Private Sub cmd_quit_Click()
Dim reply As String
reply = MsgBox("Do you want to quit program?", vbYesNo + vbQuestion + vbDefaultButton2, "Quit Program")
If (reply = vbYes) Then
  Unload Me
  Else
  frmloan.Show
                 frmloan.txtAmount.SetFocus
                End If
End Sub

Private Sub cmdclear_Click()
txtAmount.Text = ""
txtInterest.Text = ""
txtYears.Text = ""
lstdisplayvalues.Clear
txtAmount.SetFocus
End Sub

This program is not complicated but simple enough that everyone that is interested how to write a loan compounded interest solver program will have a good idea how to start from int. If you want to improve your skills and knowledge in programming always write in a piece of paper what is the desired output of the program, what are the important requirements before you can write a single line of code. By doing this you can more focusing on solving the problem because you have already a clear picture on how the program will be developed and implement.  Good planning means faster the implementation of the project specially in software development.  If you have some questions, comments and suggestions feel free to contact me I am eager to answer your queries about this matter.


Thank you very much and Happy Productive Programming Everyone.





Sample Program Output



Student Record System in Visual Basic 6

In this simple program I would like to share with you a CRUD application that I called student record system that is written in Visual Basic 6 and Microsoft Access. It enables the user to add, edit and delete record of the students from the database. It stores student records like course, section and other related information about the student enrolled in the school. I also added a code for login so that only authorized users can only access the records from our system.


If you have some question send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.


Thank you very much.








Factorial in Visual Basic 6


In the part article that I have already wrote this type of program about factorial of numbers if you are wondering why I wrote this another factorial program my answer is very simple to give you an idea how to write a factorial program using Microsoft Visual Basic 6 as our programming language for program development. As a programmer we are not always dealing with one programming language all the time the reason is the programming has a wide range of application and not all programming language fits in a particular application. I will give you some insights if you want to create a program that deals with the hardware of the computer you can use C++ or C to handle for a job because it is designed for systems programming you can’t use this programming language in making webpage because it is not designed with it use HTML and CSS instead.  I used Microsoft Visual Basic 6 in this application because of its ease of use I my thesis in my college days we used it as our programming language for our thesis in titled “Computers Semi-Encyclopaedia” what is good about this language is that you can draw the different objects or I would say control and then after you design you can put the code for its control and run the program. It can save you big amount of time in designing you application you can more focus in solving the program is a short period of time.

This number factorial program is based on the concept in computer science called recursion algorithm. I will give you some idea what is a recursion is all about. In simple words we can say recursion is the ability of the function to call itself several times during the program execution in order to solve the program one of the basic application of recursion is factorial of numbers, tower of Hanoi and Fibonacci number as an example.  The recursion algorithm was developed by Dr. Stephen Cole Kleene in 1930 he is an American mathematician and a computer scientist who contributed many concepts in computer science.

Before we can write a single line of code for our program number factorial program we need to design our user interface. In our form we put a label that tells the user to enter a number take note we are dealing here with whole positive number and then it followed by our textbox where the use put a value.  The next portion is we have two command button the first button will performed computation and the other one will allow the user to quit the program. In order for us to display the list of numbers I am using List Box control in Visual Basic that advantage of using this control is that is automatically put a vertical scroll bar when the values exceed the size of our list box as we put in our window form.

Here is the function that I wrote for solving the factorial value of a number. What this function will do is to accept a number as its parameter in this case variable y if y <= 1 then the value is 1 it means if the user will only give 1 as the number in our text box it will return 1 as its default factorial value.  If the value of variable y is greater than 1 it will call itself  again and decrement the value of y until such time we arrive with the final answer let say the user will give 4 as its factorial value 4! = 4! * 3! * 2! * 1! = 24.  So the final value of 4! Is 24 we subtract 1 every time our loop statement call itself.  The important of using function compared with writing the code in a straight forward manner is that we can call the function several times in our program without writing the same code all over again it helps us to cut down the development time of our program and minimize the errors that might occur in during program development process.

Private Function Solve_Factorial(ByVal y As Double) As Double
If y <= 1 Then
    Solve_Factorial = 1
   Else
    Solve_Factorial = y * Solve_Factorial(y - 1)
  End If
End Function

In the general declaration we use Option Explicit it means every variable in our program should be declared with its corresponding data types.  It is very important to declare all the variable with its corresponding data type because we will know what is corresponding value should be used in our program. The next portion our code is the call of solve button here we have two variable a and b we declare it integer as its data types. We clear the list box values by calling this command lstValues.Clear the b variable is being used as our assignment operator we assigned for Val(Form1.txtvalue.txt) the keyword Val is a function In Visual Basic 6 to convert text value in a text box into an integer format.  As we go along we use a for loop statement variable a = 0 to b will add the items in our list box by using this commands For a = 0 To b   lstValues.AddItem Format$(a, "@@") & "! = " &    Solve_Factorial((a)) and calling our function called Solve_Factorial(a) and we exit in our loop statement.

Private Sub cmd_solve_Click()
 Dim a As Integer, b As Integer

 Call lstValues.Clear
 b = Val(Form1.txtvalue.Text)

  For a = 0 To b
   lstValues.AddItem Format$(a, "@@") & "! = " & _
   Solve_Factorial((a))
   Next a
End Sub

The last portion of our code is the quit bottom what is code will do when the user click the bottom it will ask the use if the user want to quit the program or not is the user will continue to use the program it will return to the form window and erase the previous value given by the user. If the use choose to quit the program will be terminated and the user return to the windows environment.

Private Sub cmdquit_Click()
Dim reply As String
reply = MsgBox("Do you want to quit program?", vbYesNo + vbQuestion + vbDefaultButton2, "Quit Program")
If (reply = vbYes) Then
  Unload Me
  Else
  Form1.Show
  Form1.txtvalue.SetFocus
 End If
End Sub

The program Number Factorial program is not difficult to write and develop what is very important for us to know the is our desired output and the formulas need to solve that particular problem in hand. If you have some questions feel free to email me I am very happy to answer your questions , comments and suggestions.

Thank you very much and Happy Productive Programming.


If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360






Sample Program Output






Power of a Number in Visual Basic 6


One of the interesting aspects of computers it is designed to perform computation as its first real application to mankind.  Very fast computation that even a human being that is very intelligent in the field of mathematics cannot compete with the speed and accuracy of the computer provided that the program that is being stored and run is correct and there is not errors or bugs on it.  For the information of our readers of this article the first electronic computer was ABC computer that was invented and developed by Dr. John D. Atanasoff and his student Clifford Berry. When we say it first electronic computer it means it doesn’t use any mechanical part not any moving parts all the operation that is being perform is done electronically by switches and logic gates.  This astonishing ability of the computer prove to be useful to us we when visit a bank we can check how much money that we have deposit or withdraw without going to the manual process of opening the filing cabinet and checking those enormous files of papers it save us big amount of time and we can lessen the errors on the part of the teller in the bank for example.

In today’s article I will discuss a very simple program called Power of a Number using Microsoft Visual Basic 6 as our programming language.  If you are new with programming you may ask the question what the heck is Visual Basic is all about why it is so different with other programming language that is being used in school, industry and company. Well before I answer that question let me give you a brief history on how Microsoft Visual Basic 6 came to life. The BASIC (Beginners All-Purpose Symbolic Instruction Code) is a programming language developed in Darthmouth College in Delaware, USA at 1963 by Dr. John Kemeny and Thomas Kurtz their intention is to created a programming language that is easier to learned and understand by students and those people that are not technically inclined with the use computers during those years computers are mainly used by scientist, engineers and technician alike. They want to make programming accessible to common man that’s why they write the first compiler of BASIC.  As the language improved dramatically over the years of use Mr. Allan Cooper the father of Visual Basic would like to create a programming language that handles the design of the graphical user interface of the user by not writing down a single line of code for the design but rather putting a series of controls that a programmer can use to draw the different objects in the form where the program is being developed. The year 1991 Microsoft Corporation headed by Bills Gates collaborate with Allan Cooper to launch a new type of programming language based on BASIC they called it Visual Basic which become of the most highly successful programming language of the world.
One of the most basic feature of Microsoft Visual Basic that cannot be found on other programming language during its introduction in 1991 is that the ability of the programming to draw first the user interface without using a code for the layout and design and after that the use of minimal amount of code to achieve its desired program result. The obvious benefit of using this programming paradigm it cuts down the big amount of time of system development and the programmer can focus more on solving the real problem in programming.  I hope you have learned something on the brief history of Visual Basic now let us go down of our problem Power of a Number.
Basically Power of a Number program it will performed a series of computations to derive the result when the user will give the base and the exponent value of the number.  The base number is the number that we want to raise its exponent value let say 5 is our base value when we want to raise it to the exponent 3 the result will be 5 * 5 * 5 is equal to 125 we just multiply our base number with itself by 3 times of the exponent value that we have given is 3 very simple indeed.

Before we can write a single line of code of our program we would like to design its graphical user interface this user interface is the one that will interact to our end user of our program. We have here three labels the first label will ask the user to enter the base value of the number, the second label will ask the user to enter the exponent value that we like and the third label is the lbl_result.caption it is designed to display the result once the use click the compute button of our program. Below here it the code in our compute button that will perform a computation to find the power value of the number.

The first line of command is option explicit this command will force the programmer to declare all the variables in our program. In Microsoft Visual Basic the language can allow the programmer to use a variable without declaring its data types in our case I use this command so that every variable that I use I will be force to declare it before I used it. It is a good programming practices that we must to follow always in our programming projects or assignments .

We three variables base, exponent, value and result we declare this four variables as integer it means we are dealing with whole number, positive, negative numbers including zero. The exponent variable here will act as our assignment system that will hold the value in our control Val(txt_exponent.text) and base with a value base = Val(txt_base.txt) take note readers the text field in Visual Basic 6 by nature the value that is being handled is string we are using Val() function to convert string value into integer format.

The next portion of our code we assign result with a value of 1 this mean this is the starting point of our initial value of 1  the purpose of result variable in our program is that it will accumulate the value of base with respect to the value of our exponent variable.  We are using a for loop statement below to repeat the process of multiplication of our base and result variable. After the series of repetition of our looping statement we display the result using a label control in this case we are using this command lbl_result.Caption = base & " to the power " & exponent &   " is " & result & "." this command tells us to display the value of base the ampersand symbol separate the string “to the power “ and exponent and it the result as we call our assignment statement to display the computed value of variable result.

Option Explicit

Private Sub cmd_compute_Click()
Dim base, exponent, value, result As Integer
exponent = Val(txt_exponent.Text)
base = Val(txt_base.Text)
result = 1
For value = 1 To exponent
   result = result * base
Next value
lbl_result.Caption = base & " to the power " & exponent &    " is " & result & "."
End Sub

This command button quick will display a dialog box and will ask the end user whether he or she would like to quit using our program Power of a Number if the user reply yes it will terminate the program using the command unload me if no it will display the form once again and clear all the values in the textbox including our label control.

Private Sub cmd_quit_Click()
Dim reply As String
reply = MsgBox("Do you want to quit program?", vbYesNo + vbQuestion + vbDefaultButton2, "Quit Program")
If (reply = vbYes) Then
  Unload Me
  Else
  frm_power.Show
  frm_power.lbl_result.Caption = ""
  frm_power.txt_base.Text = ""
  frm_power.txt_exponent.Text = " "
  frm_power.txt_base.SetFocus
 End If
End Sub

Writing this program is not difficult what is important you know the purpose and the formula we need in our program. A good programming tip that I can give to you plan first before you write a single line of code it will save you big amount of time and you can more focus in solving the problem on hand more effectively and efficiently. If you have some questions, clarifications or comments please email me I am very glad to answer those queries or questions you have in mind.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360


Thank you very much and Happy Programming.




Sample Program Output