The legal tricks-Learn Your Self

Latest gadgets,softwares,hardware,reviews,programming and campuses, game cheats ext......

Creating a menu system - PHP tutorials

In this tutorial I will show you how to create a simple menu system with 2 levels. You can easy integrate it into your site to get a nice and easy editable site navigation system.

Step 1.

To make a menu system easy changeable and easy readable we will separate the code into more parts. A basic realization contains 3 files which are the following:
menuStruct.php: Contains only the navigation structure. It will be used by the handler function.

menuHandler.php: This file contains the PHP code which generates the menus with corresponding submenus as well.

index.php: The main page which integrates the navigation system.

Step 2.

First let's design the menu system structure. To handle the menu element easy we will use a multi dimensional array. In the array the key will be the name of the menu and the value is the link for it. So we can define the main menu system as follows:

Code:
// Main menu items
$mainMenu['Home'] = 'link-1';
$mainMenu['About us'] = 'link-2';
$mainMenu['Projects'] = 'link-3';
$mainMenu['Contact'] = 'link-4';
$mainMenu['Others'] = 'link-5';
?>


Now we have all the main menu items defined. However usually we need some submenus as well. To sore it in the array we will create a new array which stores the main menu - submenu relations. As you will see here we use a little bit more complex array to store information. You have to take care that the keys - key strings - in the main array and in the sub array must be identical. So the submenu array looks like this:

Code:
// Sub menu items
$subMenu['Projects']['SubMenu-1'] = 'sub-link-1';
$subMenu['Projects']['SubMenu-2'] = 'sub-link-2';
$subMenu['Projects']['SubMenu-3'] = 'sub-link-3';
$subMenu['Projects']['SubMenu-4'] = 'sub-link-4';

$subMenu['Others']['SubMenu-1'] = 'sub-link-11';
$subMenu['Others']['SubMenu-2'] = 'sub-link-12';
$subMenu['Others']['SubMenu-3'] = 'sub-link-13';
?>


At the end store this information in a file let's named it to menuStruct.php.

Step 3.

After you stored the menu structure in a file we can focus on the application logic. We will implement it in the second file
named menuHandler.php. In this file we will implement only one function called createMenu(). This function will have only one parameter which tells what is the actual page link. From this information the function will decide whether or not to display relevant submenus. So the final result is this:

Code:
function createMenu($actLink){

}
?>


Now let's start the most important part. First the function needs to include the menuStruct.php file to access the menu arrays. As second we open a table tag where we will display the menu elements as rows (tr tags).

As next step we check where the input parameter - which is the actual link - can be found in the arrays. It is important to know to decide which submenu the code should display. So the code is the following:

Code:
// Get actual Main menu
$actMenu='';
foreach ($mainMenu as $menu => $link) {
if ($link == $actLink) $actMenu = $menu;
if (isset($subMenu[$menu])){
foreach ($subMenu[$menu] as $menuSub => $linkSub) {
if ($linkSub == $actLink) $actMenu = $menu;
}
}
}
?>


After we got the actual menu we can begin with displaying the menu items row by row. We start it with the main menu items. In all steps we check whether the actually selected link in the array and the menu is the same or not. It is because if they are the same then we should display the relevant submenus before displaying the next main menu item. To make it more pretty we use other CSS class for the submenu rows as the main menu rows. The code looks like this:

Code:
foreach ($mainMenu as $menu => $link) {
echo ''.$menu.'';
if ( ($actMenu == $menu) && (isset($subMenu[$menu])) ){
foreach ($subMenu[$menu] as $menuSub => $linkSub) {
echo ''.$menuSub.'';
}
}
}
?>

Step 4.

The last step is a demonstration how to use it in the real life. To do this we will create a new file. Let's called it to index.php. This is quite straightforward. We include the menuHandler.php and create our HTML page as we want. Where you want to display the navigation block you only need to call our function with the actual link as

Code:

Formatting Dates in PHP

Ok, so how do you format dates in PHP so it outputs the date format you want? Well thanks to PHP’s date() and strtotime() function, we can do all that! To kick off, lets take the most common date format ‘YYYY-MM-DD HH:II:SS‘. This date format seems to be most favoured as it increments in such a way that allows you to query a database that has multiple records in a useful way, such as:

Code:
SELECT * FROM dates WHERE date > '2006-03-05 11:00:00';


Whereas if you were to use a different date format, such as ‘DD-MM-YYYY HH:II:SS‘ the incrementation wouldn’t work after each month as the starting value (the DD - Day) will start from 01 again. If you don’t get me, it doesn’t matter because we’re just making dates look nice in this post anyway.

Human Readable

When I say ‘Human Readable’ I don’t mean that the particular date (for example) ‘2006-03-05 11:00:00′ isn’t readable, but you wouldn’t necessarily read it out as ‘two-zero-zero-six zero-three zero-five one-one zero-zero zero-zero’ would you? A human readable version of this date would be something like Sunday, 05 March, 2006 @ 11:00:00. So how do we convert from one format to the next? Easy! Like this:

Code:
$sNewDate = date("D, d F, Y @ H:i:s", strtotime('2006-03-05 11:00:00'));


Now if we output the value of the new date variable ‘$sNewDate’:

Code:
print $sNewDate;



We get:

Sun, 05 March, 2006 @ 11:00:00

We could of course use:

Quote:
date("D, d F, Y @ H:i:s")


Which would output a nicely formatted date for the current date and time. You can also use other time strings for the second parameter, as long as you use strtotime() to format it into a nice UNIX timestamp for the date() function to process.

The Magic

So how did I make PHP output the particular parts of the date with extras like commas (,) and the at sign (@)? Let’s look at PHP’s date() function, which takes 2 arguments:
string formatThe format that date() should output
int timestamp (optional)The timestamp for date to format the date. If this is left blank, it will default to the current date and time.

The string format takes preset PHP characters, and will allow other characters provided they’re not in the ‘preset’ list, and if they are they must be escaped. Taking our example into account, lets see what characters we used:

Quote:
"D, d F, Y @ H:i:s"


We used:
D - A textual representation of a day, three letters
d - Day of the month, 2 digits with leading zeros
F - A full textual representation of a month, such as January or March
Y - A full numeric representation of a year, 4 digits
H - 24-hour format of an hour with leading zeros
i - Minutes with leading zeros
s - Seconds, with leading zeros

View the full list of characters to learn more about PHP’s date() function. Now how did we get the commas and @ signs in there? Simple, you can just add these anywhere you like within the ‘format string’ as I did above. If you wanted to actually output text within the formatted string, you could do something like this:

Quote:
"\D\a\\t\e\: D, d F, Y @ H:i:s"


Notice how we ‘escape’ each literal character with a backslash (\), and how we had to ‘double-escape’ the ‘t’ as ‘\t‘ sends a TAB to the page, so if we want a ‘t’ we must use ‘\\t‘. The above outputs:

Date: Sun, 05 March, 2006 @ 11:00:00

I hope this has given you some insight on how easy it is to format dates using PHP.

Simple PHP Class Tutorial

I’m not sure how to start this one… It can be quite difficult to understand PHP classes at first, but hopefully I’ll make everything seem easy!

The two files used can be found below:
time.php
class.Time.php

Right here we go…

Brief overview…

Ok so you’re actually reading this brief overview? You must be serious…

PHP classes can be used to group together a set of ‘like’ functions used within a bigger application. Their main advantage is the fact that you can edit the particular class function, or functions and make a site-wide change. Classes also help give you a more structured approach to programming, and those that like to hack with some GPL released web applications will have a much better understanding of the workings of them.

This may not be the best example of explaining why to use classes in PHP, but it’s an example of how to use them.

Let’s get stuck in

Let’s start by creating a new file called time.php. Within this file, let’s add some code:

File: time.php

Code:
$sTime = gmdate("d-m-Y H:i:s");
print 'The time is: ' . $sTime;
?>


This will simply assign the current date and time to the variable $sTime and then print the string ‘The time is ‘ with the variable value at the end (i.e. The time is: 09-02-2007 21:42:28)

How would we do this, using a class? Well there’s many ways, however I would recommend using the class file to generate the time, then use the acutal ‘action page’ (time.php) to output the time. Let’s create our class file!

Get in class!

Create a new file (keep it in the same directory for this tutorial). Let’s call it class.Time.php. Add the following code:

File: class.Time.php

Code:
class Time {
function GenerateCurrentTime(){
$sTime = gmdate("d-m-Y H:i:s");
return $sTime;
}
}
?>


Lets do this line by line… The first line, class Time {,declares the class as open (exactly the same as a function in PHP, but without the brackets in this case). The next line declares a new function. The difference here is that it exists ONLY within the scope of the class (i.e. it’s built WITHIN the class). We then generate the time as we did before, assigning it to the variable $sTime and then return the value of this variable. The function then closes, followed by the class closure (the squiggly brackets ‘}’). Note that our class needs to also be wrapped in php tags ().

Now open the original file, time.php, and change the code to match the following:

File: time.php

Code:
include ('class.Time.php');
$oTime = new Time;
$sTime = $oTime->GenerateCurrentTime();
print 'The time is: ' . $sTime;
?>


Now, the first line here includes the time class file (include ('class.Time.php');). We must include all the class files we wish to take advantage of, otherwise how the hell would PHP know about these files?

The next line, $oTime = new Time, creates the class object and stores it in the variable $oTime. Notice, to store the class in an object variable, we use VARIABLE = NEW CLASSNAME. VARIABLE can be anything, then there must be an equals sign ‘=’. NEW must use ‘new’ or ‘&new’, and the CLASSNAME must match the name of the class. In this case, the name of the class is Time (case sensitive - as PHP is throughout). The class name is ‘Time’ because we created the class using:

Quote:
class Time {


If we had used:

Quote:
class HelloWorld {


As you can guess, the class name would be ‘HelloWorld’.

Anyway… now we’ve created our class, we have also included it within the page we want to make use of it. Not only that, we have ALSO initalised our class by defining it in an object variable - $oTime.

So, the next line:

Quote:
$sTime = $oTime->GenerateCurrentTime();


This simply assings the variable $sTime with the result of the function GenerateCurrentTime() within the Time class. How does it do this? Simple… We want to use the function GenerateCurrentTime() within the class $oTime so we simply us:

Quote:
$oTime->GenerateCurrentTime()


This tells PHP exactly what we want to do. The ‘->’ explains to PHP that the prefix (in this case $oTime, which we know holds the class object) is the parent of the latter (again, in this case the latter is GenerateCurrentTime()). So it basically means, run GenerateCurrentTime() within the $oTime class. Thus assigning whatever is returned by the function GenerateCurrentTime() to the variable $sTime.

The last line does what we did from scratch… print out the results with the prefixed string ‘The time is ‘.

Samsung L210

Image

Quote:
Key Features :-
1. Size
87.7x55.97x20.3 (mm)
2. LCD Resolution (pixels):
230,000
3. Firewire
No
4. Video sound
Yes
5. Sensor size
1/2.33-inch
6. Maximum Video Resolution
800x592
7. Maximum shutter (sec)
1/1500
8. Exposure compensation
-2EV - +2EV with 1/3EV steps
9. White balance
Auto / Cloudy / Daylight / Fluorescent / Incandescent / Manual
10. Self-timer
No
11. Minimum resolution
1024x768
12. Video Out
Yes
13. LCD display
Yes
14. Brand
Samsung
15. Video function
Yes
16. Zoom tele (mm)
111
17. Zoom wide (mm)
37
18. Built-in flash
Yes
19. Metering
Centre weighted / Multi Spot / Spot
20. Sensor type
CCD
21. Minimum aperture wide
f2.8
22. Frames per second (fps)
30
23. Shutter Priority
No
24. Macro focus range (cm)
10
25. Bluetooth
No
26. Minimum video resolution
320x240
27. File formats
JPEG
28. Aperture Priority
No
29. Electronic viewfinder
No
30. Minimum shutter (sec)
8
31. Minimum aperture tele
f5.2
32. Model Type
L210
33. Maximum resolution
3648x2736
34. ISO ratings
auto, 80, 100, 200, 400, 800, 1600
35. Energy
Li-Ion
36. Focus range (cm)
80
37. USB
USB 2.0
38. Storage types
MultiMedia / SDHC / Secure Digital
39. Voice recording
Yes
40. Optical Viewfinder
No
41. Resolution
10.20 Mpixel
42. Optical Zoom
Yes
43. Digital Zoom
Yes
44. Auto Focus
Yes
45. Manual Focus
No
46. LCD Size (in)
2.5-inch
47. Flash Modes
anti red-eye / auto / fill in / off / slow flash
48. External Flash
No

Samsung GX-10

Image

Quote:
Key Features :-
1. Size
142x101x71.5 (mm)
2. Firewire
No
3. LCD Size
2.5-inch
4. Video sound
No
5. Sensor size
23.5x15.7mm
6. Sequence (fps)
3
7. Maximum shutter (sec)
1/4000
8. Exposure compensation
-2EV - +2EV in 1/3 - 1/2 steps
9. White balance
Auto / Cloudy / Daylight / Flash / Fluorescent / Incandescent / Manual / Shadow / Sunny
10. Self-timer
Yes
11. Minimum resolution
1824x1216
12. Video Out
Yes
13. LCD display
Yes
14. Brand
Samsung
15. Video function
No
16. LCD resolution (pixels)
210,000
17. Built-in flash
Yes
18. Metering
Centre weighted
19. Sensor type
CCD
20. Shutter Priority
Yes
21. Weight
710g.
22. Bluetooth
No
23. File formats
JPEG / RAW
24. Aperture Priority
Yes
25. Electronic viewfinder
No
26. Minimum shutter (sec)
Bulb+30
27. Model Type
GX-10
28. Maximum resolution
3872x2592
29. ISO ratings
auto, 100, 200, 400, 800, 1600
30. Energy
Li-Ion
31. External flash type
Hot-shoe
32. USB
USB 2.0 Hi-Speed
33. Storage types
Secure Digital
34. Voice recording
No
35. Focal length multiplier
1.5
36. Optical Viewfinder
Yes
37. Resolution
10.20 Mpixel
38. Digital Zoom
No
39. Auto Focus
Yes
40. Manual Focus
Yes
41. Flash Modes
anti red-eye / auto / fill in / off / rear curtin / slow flash
42. External Flash
Yes

Nokia 888 Review

Image

A personal mobile communication device which lets you be free and fun. It is light, simple and carefree. You can change its form according to your needs during the day. You dont have to carry it in your pocket or on your wrist. You can carry it anywhere, in anyform. You can roll it, bend it, put on your clothes like a clip. It also makes some form changes that makes it more ergonomical: i.e. when you want to talk on the phone, the body form turns into the form of the good old telephone. You can personalize these forms and record them. So it fits you the best in the way that you have chosen. Also e-motions let you send forms to other 888 users: i.e. you can send a heart shape to your girlfriend or a dancing figure to your friends to call them to the party tonight. This way you can talk without words.

Image

Technologies that are used It uses liquid battery, speech recognition, flexible touch screen, touch sensitive body cover which lets it understand and adjust to the environment. It has a simple programmable body mechanism so that it changes forms in different situations.

* the functionality of design You dont have to carry it in your pocket or on your wrist. You can carry it anywhere, in anyform. You can roll it, bend it, put on your clothes like a clip. It also makes some form changes that makes it more ergonomical: i.e. when you want to talk on the phone, the body form turns into the form of the good old telephone. You can personalize these forms and record them. So it fits you the best in the way that you have chosen. The functions that it has also create a feeling of electronical pet, as it senses your moves, understand what you want, respond you in the best way. It learns you, to fit you better.Also e-motions lets you send forms to the other 888 users. It could be the shape of a heart or a small dance. This way you can talk without words.

Image

* how the user interactsE-motions… It means electronical motions that 888 has. You can send and receive forms from / to friends. You can send a heart shape to your girlfriend, so her telephone turns into an icon of heart. Or you can send a dancing form to your friends to call them to the party tonight. This is the fun side of the product. If we look from the functionality side, 888 is quite flexible. You can put it into your pocket, roll it and make it smaller, or put on your wrist when you want to make a video call on the go. If you want to talk like a normal telephone, there you have your telephone shape. We go through a lot of places and situations in the daily life, so it seems like one form is not enough.

Check this video out :http://www.youtube.com/watch?v=D3dF44XtHek

* what is unique You can change the form of the body. Not just the color. And you can do the same by sending an e-motion to your friend.

* the inspiration The idea is that “the perfect form” does not exist. “Form follows you” We create the perfect form for each function.

Designer: Tamer Nakisci
Image

Nokia E71 [Review]

Mobile professionals who need a powerful but sleek messaging-centric smartphone will be well-served by the Nokia E71; just be prepared to pay a price.

Nokia's E series sometimes gets overshadowed by the flashier N series, but it's just as bright and deserves some recognition too. Traditionally, the E-series devices have been aimed at businesses and serious in design. Now though, Nokia is updating the line with the introduction of the Nokia E66 and Nokia E71, bringing with them a modernised look and a fresh set of features.

For this review, we took a look at the Nokia E71, which steps in to relieve the older Nokia E61i. What the company has done with the E71's design is remarkable, as it's taken the once-bulky smartphone and turned it into an incredibly sleek QWERTY device. You do lose a bit in screen and keyboard size, but we feel it's manageable. Plus, with its strong messaging, productivity and connectivity features plus solid performance, it's worth those little sacrifices. The only downfall is that an unlocked version of the Nokia E71 will go for around AU$709.

Design

The first thing you'll notice about the Nokia E71 is its design. It's noticeably sleeker and sexier than the Nokia E61i, sporting a compact frame that measures 114mm by 57mm by10mm and weighs 126g. The slimness is especially noticeable when you use the E71 as a phone, or just hold it in the palm of your hand. In addition, the handset has a solid construction with its steel frame. Our only complaint — and it's a minor one — is that the back gets a bit tarnished with fingerprints and smudges.

Image

On front, there's a 2.36in. non-touch display with a 16-million-colour support and 320-by-240-pixel (QVGA) resolution. The screen is a bit on the small side, but text and images look sharp. It also has a light-sensing technology that adjusts the display's brightness depending on the environment you're in. A new feature that's not readily apparent from looking at the phone is the Business and Personal home screens. You can now toggle between two different home views, depending on whether you're at work or at home. In Business mode, you'll have immediate access to work tools, such as email, the web and the file manager. After hours, you can switch to Personal mode and have your music and photo gallery a click away. Of course, you're not really 'off' from work since you can easily switch back, but it's a nice thought anyway.

Below the display, there's a standard navigation array of two soft keys, Talk and End buttons, and a four-way toggle with a centre select key. In addition, there are four shortcuts to the Home screen, Calendar, Contacts and Messages. You also get a full QWERTY keyboard. Given that the E71 is physically smaller than the E61i, the layout is a bit more cramped with less spacing between the buttons. Still, I found it pretty easy to use, although I do have small fingers. Customers with larger thumbs might want to give it a test drive. On the bright side, the keys don't have that squishy feel of the E61i; they give more of a satisfying, clicky tactile feedback.

Image

The left spine holds a microSD slot and a micro-USB port. It seems Nokia is sticking with the decision to go with the less standard micro-USB port at this time. It's definitely not a deal-breaker, just a minor inconvenience since you can't use the more widely used mini-USB accessories. On the right side, you have a 2.5mm headset jack, a volume rocker and a voice command activation key. Both sides also have buttons to release the battery cover. The on/off button is located on the top, while the power connector is on the bottom of the unit. Finally, you'll find the camera, flash and self-portrait mirror on the back.

The Nokia E71 comes packaged with an AC adapter, a USB cable, a wired headset, a 2GB microSD card, a protective pouch, a lanyard, a software CD and reference material.

Features
If the QWERTY keyboard didn't give it away, the Nokia E71 is a messaging-centric smartphone, although it's certainly not limited to just email. The E71 works with Microsoft Exchange Server, POP3, IMAP and SMTP accounts and has a full attachment viewer. The device is also compatible with a number of push email solutions, including Intellisync Wireless E-mail, Visto and Seven Always-On Mail. The E71 includes a new wizard to help set up your email as it automatically looks for the settings needed to access your account. There are no instant messaging clients preloaded on the device, although you can certainly download software to do so. In fact, there is a download catalogue right on the device where you can find such titles.

Using the new wizard, we configured our review unit to access our Yahoo Plus account by simply entering our login and password. There's also a voice aid utility that uses text-to-speech technology to read aloud not only your messages but your call history, contacts, clock and more. The feature worked fine in our tests, although the voice sounded quite robotic. We'd say this function might come in handy when you need to hear a message while driving; otherwise, it might just be easier to read the information off the phone.

The E71 runs Symbian OS 9.2, Series 60 3.1 edition, and comes with full support for viewing and editing Microsoft Word, Excel, and PowerPoint documents with the Quickoffice suite. It appears, however, that the company has done away with the Nokia Team Suite, which first debuted on the Nokia E65. The E71 comes with the Nokia Web browser with support for Flash Lite 3.0, so you're able to view and use such sites as YouTube. The smartphone does have a number of other PIM applications and organisation tools, including Adobe Reader, a Zip Manager, a calendar, notes, a calculator, a clock, a voice recorder and a currency converter. There are also a number of security features, including memory encryption and mobile VPN. There's 110MB of internal dynamic memory, and the microSD slot can accept up to 8GB cards.

Image

The good:

* Slim design with full QWERTY keyboard
* Feature-rich, including Wi-Fi, Bluetooth, HSDPA and GPS
* Voice, messaging and productivity tools are also strong

The bad:

* Expensive
* Display is on the small side
* Keyboard is a little cramped

The bottomline:


A powerful but sleek messaging-centric smartphone.

anssss

http://www.megavideo.com/?v=PFPW11GB
http://www.megavideo.com/?v=PFPW11GB
http://www.megavideo.com/?v=PFPW11GB

CSS : Rounded corners without images

Quote:










.rtop, .rbottom{display:block}
.rtop *, .rbottom *{display: block; height: 1px; overflow: hidden}
.r1{margin: 0 5px}
.r2{margin: 0 3px}
.r3{margin: 0 2px}
.r4{margin: 0 1px; height: 2px}

CSS : Tableless forms

Quote:












label,input {
display: block;
width: 150px;
float: left;
margin-bottom: 10px;
}

label {
text-align: right;
width: 75px;
padding-right: 20px;
}

br {
clear: left;
}

CSS : Double blockquote

Quote:
blockquote:first-letter {
background: url(images/open-quote.gif) no-repeat left top;
padding-left: 18px;
font: italic 1.4em Georgia, "Times New Roman", Times, serif;
}

CSS : Vertical centering with line-height

Quote:
div{
height:100px;
}
div *{
margin:0;
}
div p{
line-height:100px;
}

Content here

CSS : Rounded corners with images

Quote:


width="15" height="15" class="corner"
style="display: none" />


CONTENT

width="15" height="15" class="corner"
style="display: none" />



.roundcont {
width: 250px;
background-color: #f90;
color: #fff;
}

.roundcont p {
margin: 0 10px;
}

.roundtop {
background: url(tr.gif) no-repeat top right;
}

.roundbottom {
background: url(br.gif) no-repeat top right;
}

img.corner {
width: 15px;
height: 15px;
border: none;
display: block !important;
}

CSS : Multiple Class name

Quote:


.class1 { border:2px solid #666; }
.class2 {
padding:2px;
background:#ff0;
}


Report this post

CSS : Center horizontally

Quote:


#container {
margin:0px auto;
}

CSS Drop Caps

Quote:

This paragraph has the class "introduction". If your browser supports the pseudo-class "first-letter", the first letter will be a drop-cap. 

p.introduction:first-letter {
font-size : 300%;
font-weight : bold;
float : left;
width : 1em;
}

Show firefox scrollbar, remove textarea scrollbar in IE

Quote:
html{
overflow:-moz-scrollbars-vertical;
}

textarea{
overflow:auto;
}


Report this post

CSS Gradient Text Effect

Quote:

CSS Gradient Text



h1 {
font: bold 330%/100% "Lucida Grande";
position: relative;
color: #464646;
}
h1 span {
background: url(gradient.png) repeat-x;
position: absolute;
display: block;
width: 100%;
height: 31px;
}

Sample VB Programs-Financial Calculator for Amortization

In order to design this program, I need to explain some financial concepts. The term loan amortization means the computation of the amount of equal periodic payments necessary to provide lender with a specific interest return and repay the loan principal over a specified period. The loan amortization process involves finding the future payments whose present value at the load interest rate equal the amount of initial principal borrowed. Lenders use a loan amortization schedule to determine these payment amounts and the allocation of each payment to interest and principal.

The formula to calculate periodic payment is payment=Initial Principal/PVIFAn, where PVIFAn is known as present value interest factor for an annuity . The formula to compute PVIFAn is 1/i - 1/i(1+i)n where n is the number of payments. Normally you can check up a financial table for the value of PVIFAn and then calculate the payments manually. You can also use a financial calculator to compute the values. However, if you already know how to program in VB, why not create your very own financial calculator.

To calculate the payments for interest, you can multiply the initial principal with the interest rate, then use periodic payment to minus payment for interest. To calculate the balance at the end of a period, use the formula 

End-of_year principal=Beginning-of-year principal-periodic payment

The Interface

Image

Code:
Public Sub Cmd_Calculate_Click()
P = Txt_Principal.Text
Num = Txt_Num_payment.Text
r = Txt_Interest.Text
I = r / 100
PVIFA = 1 / I - 1 / (I * (1 + I) ^ Num)
pmt = P / PVIFA
Lbl_Amtpayment.Caption = Round(pmt, 2)

End Sub

Private Sub Cmd_Create_Click()
List_Amortization.AddItem "n" & vbTab & "Periodic" & vbTab & vbTab & "Payment" & vbTab & vbTab & "Payment" & vbTab & vbTab & "Balance"
List_Amortization.AddItem "" & vbTab & "Payment" & vbTab & vbTab & "Interest" & vbTab & vbTab & "Principal"
List_Amortization.AddItem "_______________________________________________________________________"
Do
n = n + 1
PI = P * I
PP = pmt - PI
P = P - PP
List_Amortization.AddItem n & vbTab & Round(pmt, 2) & vbTab & vbTab & Round(PI, 2) & vbTab & vbTab & Round(PP, 2) & vbTab & vbTab & Round(P, 2)
If n = Num Then
Exit Do
End If
Loop



End Sub

Private Sub Cmd_Reset_Click()
Txt_Principal.Text = ""
Txt_Interest.Text = ""
Txt_Num_payment.Text = ""
Lbl_Amtpayment.Caption = ""
List_Amortization.Clear
n = 0


End Sub

Private Sub Command4_Click()
End
End Sub

Sample VB Programs-Depreciation Calculator

Image

Depreciation is an important element in the management of a company's assets. With proper and accurate calculation of depreciation, a company can benefit from the tax advantage. Depreciation is normally computed based on the initial purchase price or initial cosat, number of years of where depreciation is calculated, salvage value at the end of the depreciation period, and the asset's life span.

The Format of a depreciation function is

DDB(Cost,Salvage,Life, Period)

Cost=Initial cost

Salvage=Salvage value

Life=Asset's life span

Period=Depreciation period

Code:
Private Sub Command1_Click()

Dim Int_Cost, Sal_Value, Asset_Life, Deperiod, Depre_Amt As Double
Int_Cost = Val(Txt_Cost.Text)
Sal_Value = Val(Txt_Salvage.Text)
Asset_Life = Val(Txt_Life.Text)
Deperiod = Val(Txt_Period.Text)
Depre_Amt = DDB(Int_Cost, Sal_Value, Asset_Life, Deperiod)

Lbl_Dpre.Caption = Format(Depre_Amt, "$###,###,000.00")

End Sub