Practical Web Programming

Thursday, January 31, 2008

How to Get the File Information Using API in Visual Basic

This function takes a passed filename as an argument and returns the description of that file. For example, if you pass the filename "c:\windows\sys.com" to the function, it will return the string "MS-DOS Application". If the file doesn'texist, it will return a blank type information.

NOTE: To see the result, copy and paste the code below in the
declaration section of a form.

'Constants declaration
Const SHGFI_DISPLAYNAME = &H200
Const SHGFI_TYPENAME = &H400
Const MAX_PATH = 260
Private Type SHFILEINFO
hIcon As Long ' out: icon
iIcon As Long ' out: icon index
dwAttributes As Long ' out: SFGAO_ flags
szDisplayName As String * MAX_PATH ' out: display name (or path)
szTypeName As String * 80 ' out: type name
End Type

'API declaration
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias _
"SHGetFileInfoA" (ByVal pszPath As String, _
ByVal dwFileAttributes As Long, _
psfi As SHFILEINFO, ByVal cbFileInfo As Long, _
ByVal uFlags As Long) As Long

'Gets the information of the file passed to it
Private Function GetFileInfo(strFileName) As SHFILEINFO
Dim lngRetVal As Long
Dim fileInfo As SHFILEINFO

lngRetVal = SHGetFileInfo(strFileName, 0, fileInfo, Len(fileInfo), _
SHGFI_DISPLAYNAME Or SHGFI_TYPENAME)
GetFileInfo = fileInfo
End Function

'This fucntion is used to strip al the unnecessary chr$(0)'s
Private Function StripTerminator(sInput As String) As String
Dim ZeroPos As Integer
'Search the position of the first chr$(0)
ZeroPos = InStr(1, sInput, vbNullChar)
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function

Private Sub Form_Load()
Dim fileInfo As SHFILEINFO

fileInfo = GetFileInfo("c:\autoexec.bat")
MsgBox "Displayname: " & StripTerminator(fileInfo.szDisplayName) & _
vbNewLine & _
"Typename: " & StripTerminator(fileInfo.szTypeName)
End Sub

Tuesday, January 29, 2008

Cut, Copy, Paste and Delete Using the Clipboard Object Source Codes in Visual Basic

Are you having difficulty in doing Cut, Copy, Paste and Delete of texts routines in Visual Basic? Well, settle down now.

This source codes shows the CUT, COPY, PASTE and DELETE routines using the Clipboard object. This source codes assumes that you have four commandbutton controls (EditCut, EditCopy, EditPaste and EditDelete) in your Visual Basic project

Private Sub EditCut_Click()
'Clear the contents of the Clipboard.
Clipboard.Clear
'Copy selected text to Clipboard.
Clipboard.SetText Screen.ActiveControl.SelText
'Delete selected text.
Screen.ActiveControl.SelText = ""
End Sub

Private Sub EditCopy_Click()
'Clear the contents of the Clipboard.
Clipboard.Clear
'Copy selected text to Clipboard.
Clipboard.SetText Screen.ActiveControl.SelText
End Sub

Private Sub EditPaste_Click()
'Place text from Clipboard into active control.
Screen.ActiveControl.SelText = Clipboard.GetText()
End Sub

Private Sub EditDelete_Click()
'Delete selected text.
Screen.ActiveControl.SelText = ""
End Sub

Monday, January 28, 2008

How to Handle Control Arrays with Index Holes in Between in Visual Basic

Here's simple tutorial on how you can handle control arrays with index holes in between.

Control array is one of the best feature of Visual Basic. However, this can cause runtime errors if you are not careful, especially if they have missing elements or index in between.

To handle control arrays with sequence index, you can use this method.

Dim intX as integer
For intX = Text1.LBound to Text1.UBound
MsgBox Text1(intX).Text
Next


However, if they have holes in between them (Ex: Text1(0), Text1(1), Text1(3), Text1(4)), the above method spits an error. To avoid that situation, treat the array like a collection as below.

Dim txt as TextBox
For Each txt In Text1
MsgBox txt.Text
Next txt


That's it. Tamed control arrays. (^_^)

Sunday, January 27, 2008

Oracle DDL Basics: A Simple Tutorial on Oracle Data Definition Language

Here's a simple tutorial on Oracle Data Definition Language. I always make this handy at the office as I sometimes forget some of the basis of the Oracle DDL.

1. Data Type.

Type                Storage     Range/Length
----------------- ---------- --------------
NUMBER 16 40 digit floating point
FLOAT 16 40 digit floating point
SMALLINT 16 40 digit floating point
NUMBER(a,b) varies a digits, b precision
FLOAT(a,b) varies a digits, b precision
DECIMAL 16 40 digit
INTEGER 16 40 digits
INTEGER(a) varies a digits
CHAR(a) a a=(1-255)
VARCHAR(a) varies 1 - 255
VARCHAR2(a) varies 1 - 2000
DATE 8 1/1/4217BC - 12/31/4712AD
LONG varies 0 - 2 GB
LONG RAW varies 0 - 2 GB
LONG VARCHAR varies 0 - 2 GB
BLOB varies 0 - 4 GB
CLOB varies 0 - 4 GB
NCLOB varies 0 - 4 GB
BFILE ?? ??
ROWID 8 n/a


* Long datatypes are discouraged in Oracle 8.
Note that are long and blob datatypes are incompatible.

2. Creating a Table.

PCTFREE = Amount of space to leave in block during insert operations. Allows room for records to grow within the same area.
PCUSED = The threshold at which the block is placed back on the free block list.
INITIAL/NEXT = The initial disk allocated, and the next extent size.
LOGGING = Indicates whether operations are written to the redo logs.

CREATE TABLE EMPLOYEE (
EMP_ID NUMBER(8),
LNAME VARCHAR2(30),
FNAME VARCHAR2(15),
HIRE_DT DATE,
SALARY NUMBER(8,2) )

PCTFREE 20
PCTUSED 50
STORAGE (INITIAL 200K NEXT 200K PCTINCREASE 0 MAXEXTENTS 50 )
TABLESPACE ts01 LOGGING;


3. Creating indexes

CREATE UNIQUE INDEX EMP_IDX ON EMPLOYEE (EMP_ID);


/* index create - table has sorted data */
CREATE UNIQUE INDEX IDX_INVOICE_ITEMS   ON INVOICE_ITEMS
(INVOICE_ID,YEAR,FREQ_CODE,FREQ_NUMBER,FIELD_NUMBER,RECORD_SEQ)
TABLESPACE TS_07
NOLOGGING
NOSORT;


/* create index - constraint */
ALTER TABLE  INVOICE_FORMAT
ADD CONSTRAINT PK_INVOICE_FORMAT PRIMARY KEY(INVOICE_ID)
USING INDEX TABLESPACE PROD_IDX_01;


/* Get index information */
SELECT A.COLUMN_NAME,
A.COLUMN_POSITION,
A.INDEX_NAME,
B.UNIQUENESS
FROM USER_IND_COLUMNS A,
USER_INDEXES B
WHERE A.INDEX_NAME = B.INDEX_NAME AND
A.TABLE_NAME = 'IDX_INVOICE_ITEMS'
ORDER BY A.INDEX_NAME, A.COLUMN_POSITION;


/* create bitmap index - table is fairly static, and has less than 1000 distinct values in the indexed column */
CREATE BITMAP INDEX BIX_INVOICE_ARCHIVE
ON INVOICE_ARCHIVE (SALES_ID)
TABLESPACE PROD_IDX_01;


4. Creating constraints

/* primary key constraint */
ALTER TABLE EMPLOYEE (
CONSTRAINT EMP_PK
PRIMARY KEY (EMP_ID));


ALTER TABLE  REPORT_FORMAT
ADD CONSTRAINT PK_REPORT_FORMAT PRIMARY KEY(REPORT_ID)
USING INDEX TABLESPACE PROD_IDX_01;


/* foreign key constraint */
ALTER TABLE EMPLOYEE ADD (
CONSTRAINT EMP_LOC_ASSIGN_FK
FOREIGN KEY (EMP_ID,
LOC_CD)
REFERENCES LOC_REGISTRY (
EMP_ID,
LOC_CD));


5. Creating and using a sequence.

/* create a sequence for employee ids */
CREATE SEQUENCE EMP_ID_SEQ
INCREMENT BY 1
NOMINVALUE
NOMAXVALUE
NOCYCLE
CACHE 20
NOORDER ;


/ * use the next emp id, and increment the sequence */
INSERT INTO EMPLOYEE(EMP_ID, LNAME, FNAME)
VALUES (EMP_ID_SEQ.NEXTVAL, 'SMITH', 'JIM');


/* get the current value of the sequence */
INSERT INTO EMPLOYEE(EMP_ID, LNAME, FNAME)
VALUES (EMP_ID_SEQ.CURRVAL, 'SMITH', 'JIM');


6. Creating triggers.

The example below illustrates versioning of the EMP_RESUME table, which contains a blob field.

CREATE OR REPLACE TRIGGER EMP_RES_INS_TR
AFTER INSERT ON EMP_RES
FOR EACH ROW
DECLARE
VER1 NUMBER ;
EBLOB BLOB ;
VBLOB BLOB ;
BEGIN
EBLOB := EMPTY_BLOB();

SELECT (COUNT(*) + 1) INTO VER1
FROM VEMP_RES
WHERE EMP_ID =:NEW.EMP_ID ;

VBLOB := :NEW.RESUME ;

INSERT INTO VEMP_RES
( EMP_ID, DOC_URL,
A_USERID, D_MODIFIED, VER_NO, RESUME)
VALUES (
:NEW.EMP_ID, :NEW.DOC_URL,
USER, SYSDATE, VER1, EBLOB ) ;

SELECT RESUME
INTO EBLOB
FROM VEMP_RES
WHERE EMP_ID =:NEW.EMP_ID AND
VER_NO = VER1
FOR UPDATE ;

UPDATE VEMP_RES
SET RESUME = VBLOB
WHERE EMP_ID =:NEW.EMP_ID AND
VER_NO = VER1 ;
END;



7. Renaming a table.

RENAME EMPLOYEE TO MANAGER;


8. Synonyms and Database Links.

/* Synonym Creation */
GRANT SELECT ON USER5.COMPANY TO USER6 ;
CREATE SYNONYM USER6.COMPANY5 FOR USER5.COMPANY;


/* Database Link */
CREATE DATABASE LINK ARCHIVE_DATA CONNECT TO
USER5 IDENTIFIED BY TIGER USING 'SERVER5';


/* user within this system can now reference tables using ARCHIVE_DATA.tablename */

9. Changing a column's type or name.

/*Change Type*/
ALTER TABLE CORPORATION MODIFY (COMPANY_NM VARCHAR2(100));


ALTER TABLE employee MODIFY(last_name varchar2(40));


/*Change Name*/
ALTER TABLE EMPLOYEE RENAME COLUMN LAST_NAME TO LNAME;


10. Moving a table.

ALTER TABLE COMPANY MOVE
STORAGE (
INITIAL 200K
NEXT 200K
PCTINCREASE 0
MAXEXTENTS 50 )
TABLESPACE TS_01;


11. Partitioned Tables.

Table partitioning is the best feature ever added to the Oracle RDBMS.
Chunks of data can be appended, replaced, or purged very easily when
using table partitioning. When you have more than 20 million rows in a
non-static table, partitioning is recommended. We found that bitmap
indexes work better than standard indexes on partitioned tables.

/*Add a partition*/
ALTER TABLE PHONE_DATA ADD PARTITION
p2004JUL VALUES (200407) TABLESPACE TS01 ;


/*Populate a partition, replaces existing data, if it exists*/
ALTER TABLE PHONE_DATA EXCHANGE PARTITION
p2004JUL WITH TABLE TMP_SWITCH_DATA ;


/*Move a partition*/
ALTER TABLE PHONE_DATA MOVE PARTITION 
P2004JUL TABLESPACE TS01 NOLOGGING;


/*Truncate a partition*/
ALTER TABLE PHONE_DATA TRUNCATE PARTITION;


/*Drop a partition*/
ALTER TABLE PHONE_DATA DROP PARTITION p2004JUL 
update global indexes;


/*Get partition information*/
SET PAGESIZE 0
SET LINESIZE 120
SELECT TABLE_NAME, PARTITION_NAME, BLOCKS, TABLESPACE_NAME
FROM USER_TAB_PARTITIONS
ORDER BY TABLE_NAME, PARTITION_NAME;


/*Create a local partition index*/
CREATE BITMAP INDEX BIX_PHONE_DATA ON PHONE_DATA
(PERIOD_KEY)
TABLESPACE TS02
LOCAL;


/*Rebuild*/
ALTER TABLE PHONE_DATA MODIFY PARTITION
p2004JUL REBUILD UNUSABLE LOCAL INDEXES;

Saturday, January 26, 2008

Wishful Thinking

How I wish I could go on a cruises vacation like cruisecheap.com is offering. My last vacation was far from being comfortable. I had to go on a 24-hour trip via bus. The waiting and the long bus trip will just drain your energy away.

Well, maybe if my online business picked up, then I'll be able to afford to travel via plane back and forth everytime I go home for a vacation and avoid wasting my vacation time on a bus. And maybe I'll go on a cruise vacation with my wife, who knows. (^_^)

How to Easily Clear the Texts in Textbox or Combobox in Visual Basic

Ever done a program wherein you have to clear all the texts in textboxes and/comboboxes every time you need to input something? If you reference each control by it's name and then clearing the text one by one, that will result to more lines of codes. And in programming, more lines of codes means more complications.

Good thing is, you don't have to write several lines of source codes, the function below will do just that.

This visual basic function will clear texts any control with text property or a list-index property in the form.

Public Sub ClearAllControls(frmForm As Form)
Dim ctlControl As Object
On Error Resume Next
For Each ctlControl In frmForm.Controls
ctlControl.Text = ""
ctlControl.LISTINDEX = -1
DoEvents
Next ctlControl
End Sub

Wednesday, January 23, 2008

A Payroll System Source Codes in C/C++

I wrote this Payroll System in C/C++ for our final project requirement in college. It uses array of structure to save the employees information. Check it out.

#include<stdio.h>
#include<process.h>
#include<ctype.h>
#include<string.h>
#include<dos.h>
#include<conio.h>
#define PAUSE 10000

void addEmp();
void viewEmp();
void addDed();
void viewDed();
void exitSys();
void linefill(int start);

struct employee{
char code[10];
char fname[15];
char lname[15];
char mname[5];
char sex[10];
char status[15];
char ded_name1[15];
char ded_name2[15];
char ded_name3[15];
float grossPay;
float netPay;
float tax;
float ded_n1;
float ded_n2;
float ded_n3;
}empRec[50];

char ch,ID[10];
int x,cntrX,idCheck;

void main()
{
int start=16,end=20;
textattr(9+(1<<4)); clrscr(); cntrX=0;
while(1 == 1)
{
window(1,1,80,25);
linefill(start); textattr(10+(1<<4));
gotoxy(20,3); cprintf("Ûßßß Ü ÛßßÛ ÜÜÜÜ Û ");
gotoxy(20,4); cprintf("ÛÛßß Ü ÛÛ Û ÜÜÜÛ ÛÛ ");
gotoxy(20,5); cprintf("ÛÛ Û ÛÛ Û ÛÜÜÛ ÛÛÜÜ");
textattr(6+(1<<4));
gotoxy(42,3); cprintf("Üßßßß Û Û Üßßßß");
gotoxy(42,4); cprintf(" ßßßÜ ßÛß ßßßÜ");
gotoxy(42,5); cprintf("ßßßß ß ßßßß ");
textattr(15+(1<<4));
gotoxy(60,3); cprintf("TM ");
gotoxy(23,7); cprintf(" Final Project ");
gotoxy(23,8); cprintf(" by: Joel Badinas ");
gotoxy(23,9); cprintf(" October 2001 ");
textattr(2+(4<<4));
gotoxy(29,14); cprintf(" >> M A I N M E N U << ");
textattr(2+(1<<4));
gotoxy(25,15); cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
gotoxy(33,16); printf("Add new employee");
gotoxy(33,17); printf("View employee");
gotoxy(33,18); printf("Add deduction");
gotoxy(33,19); printf("View deduction");
gotoxy(33,20); printf("Quit");
gotoxy(25,21); cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
textattr(14+(1<<4));
gotoxy(2,25); cprintf("FiNaLSYS Ver 1.0");
gotoxy(63,25); cprintf("Copyright(c) 2001");
ch=getch();
if(ch==72)
{
textbackground(1); textcolor(9);
gotoxy(31,start); cprintf(" ");
start = start -1;
if(start < 16)
{
start = end;
}
textbackground(1); textcolor(9);
gotoxy(31,start+1); cprintf(" ");
linefill(start);
}
if(ch==80)
{
textbackground(1); textcolor(9);
gotoxy(31,start); cprintf(" ");
start = start + 1;
if(start > 20)
{
start = 16;
}
textbackground(1); textcolor(9);
gotoxy(31,start-1); cprintf(" ");
linefill(start);
}
if(ch == 13)
{
if(start == 16)
{
addEmp(); textattr(9+(1<<4));
window(1,1,80,24); clrscr();
}
if(start == 17)
{
viewEmp(); textattr(9+(1<<4));
window(1,1,80,24); clrscr();
}
if(start == 18)
{
addDed(); textattr(9+(1<<4));
window(1,1,80,24); clrscr();
}
if(start == 19)
{
viewDed(); textattr(9+(1<<4));
window(1,1,80,24); clrscr();
}
if(start == 20)
{
exitSys(); exit(0);
}
}
}
}

void addEmp()
{
float pay1;
char name1[15],name2[15],name3[5],name4[10],name5[15];
ch=0;
while(ch != 'N')
{
window(8,4,72,22);
textattr(2+(0<<4)); clrscr(); textattr(7+(0<<4));
while(1 == 1)
{
idCheck=0;
gotoxy(6,3); cprintf("Enter code : "); scanf("%s",&ID);
for(x=0;x<cntrX+1;x++)
{
if(strcmp(empRec[x].code,ID)==0)
{
idCheck=1;
}
}
if(idCheck==1)
{
gotoxy(23,3); printf(" ");
gotoxy(2,19); cprintf("Code no. already exist! ");
delay(PAUSE);
gotoxy(2,19); printf(" ");
}
else
{
break;
}
}
gotoxy(6,8); cprintf("Last Name : ");
gotoxy(6,9); cprintf("First Name : ");
gotoxy(6,10); cprintf("Middle Initial : ");
gotoxy(6,11); cprintf("Sex : ");
gotoxy(6,12); cprintf("Status : ");
gotoxy(6,13); cprintf("Monthly Pay : ");

gotoxy(23,8); scanf("%s",&name1);
gotoxy(23,9); scanf("%s",&name2);
gotoxy(23,10); scanf("%s",&name3);
gotoxy(23,11); scanf("%s",&name4);
gotoxy(23,12); scanf("%s",&name5);
gotoxy(23,13); scanf("%f",&pay1);
gotoxy(2,19); cprintf("Save this entry? (Y/N) ");
ch=0;
while(ch != 'Y'&& ch != 'N')
{
ch=toupper(getch());
}
if(ch=='Y')
{
cntrX++;
strcpy(empRec[cntrX].code,ID);
strcpy(empRec[cntrX].fname,name1);
strcpy(empRec[cntrX].lname,name2);
strcpy(empRec[cntrX].mname,name3);
strcpy(empRec[cntrX].sex,name4);
strcpy(empRec[cntrX].status,name5);
empRec[cntrX].grossPay = pay1;
empRec[cntrX].tax = (.12)*pay1;
empRec[cntrX].netPay = empRec[cntrX].grossPay-empRec[cntrX].tax;
gotoxy(2,19); cprintf("Saving entry... ");
delay(PAUSE);
}
else
{
gotoxy(2,19); cprintf("Saving cancelled... ");
delay(PAUSE);
}
gotoxy(2,19); cprintf("Save entry again? (Y/N) ");
ch=0;
while(ch != 'Y'&& ch != 'N')
{
ch=toupper(getch());
}
}
}

void viewEmp()
{
ch=0;
while(ch != 'N')
{
idCheck=0;
window(8,4,72,22);
textattr(2+(0<<4)); clrscr(); textattr(7+(0<<4));
gotoxy(6,3); cprintf("Enter code : "); scanf("%s",&ID);
for(x=0;x<cntrX+1;x++)
{
if(strcmp(ID,empRec[x].code)==0)
{
gotoxy(6,8); cprintf("Last Name : ");
gotoxy(6,9); cprintf("First Name : ");
gotoxy(6,10); cprintf("Middle Initial : ");
gotoxy(6,11); cprintf("Sex : ");
gotoxy(6,12); cprintf("Status : ");
gotoxy(6,13); cprintf("Net Pay : ");

gotoxy(23,8); printf("%s",empRec[x].fname);
gotoxy(23,9); printf("%s",empRec[x].lname);
gotoxy(23,10); printf("%s",empRec[x].mname);
gotoxy(23,11); printf("%s",empRec[x].sex);
gotoxy(23,12); printf("%s",empRec[x].status);
gotoxy(23,13); printf("%.2f",empRec[x].netPay);
idCheck=1; break;
}
}
if(idCheck==0)
{
gotoxy(2,19); cprintf("Employee record not found... ");
delay(PAUSE);
}
gotoxy(2,19); cprintf("View employee again? (Y/N) ");
ch=0;
while(ch != 'Y'&& ch != 'N')
{
ch=toupper(getch());
}
}
}

void addDed()
{
char nameded1[15],nameded2[15],nameded3[15];
float amount1,amount2,amount3;
ch=0;
while(ch != 'N')
{
window(8,4,72,22); idCheck=0;
textattr(2+(0<<4)); clrscr(); textattr(7+(0<<4));
gotoxy(3,2); cprintf("Enter code : "); scanf("%s",&ID);
for(x=0;x<cntrX+1;x++)
{
if(strcmp(ID,empRec[x].code)==0)
{
idCheck=1;
gotoxy(3,6); cprintf("Name : ");
gotoxy(3,7); cprintf("Monthly Pay : ");
gotoxy(46,6); cprintf("Sex : ");
gotoxy(46,7); cprintf("Status : ");

gotoxy(17,6); printf("%s %s %s",empRec[x].fname,empRec[x].lname,empRec[x].mname);
gotoxy(17,7); printf("%.2f",empRec[x].grossPay);
gotoxy(55,6); printf("%s",empRec[x].sex);
gotoxy(55,7); printf("%s",empRec[x].status);

gotoxy(16,10); cprintf(" Type of Deduction ³ Amount");
gotoxy(16,11); cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
gotoxy(17,12); cprintf("1)"); gotoxy(36,12); cprintf("³");
gotoxy(17,13); cprintf("2)"); gotoxy(36,13); cprintf("³");
gotoxy(17,14); cprintf("3)"); gotoxy(36,14); cprintf("³");

gotoxy(20,12); scanf("%s",&nameded1);
gotoxy(39,12); scanf("%f",&amount1);

gotoxy(20,13); scanf("%s",&nameded2);
gotoxy(39,13); scanf("%f",&amount2);

gotoxy(20,14); scanf("%s",&nameded3);
gotoxy(39,14); scanf("%f",&amount3);

gotoxy(2,19); cprintf("Save this entry? (Y/N) ");
ch=0;
while(ch != 'Y'&& ch != 'N')
{
ch=toupper(getch());
}
if(ch == 'Y')
{
for(x=0;x<cntrX+1;x++)
{
strcpy(empRec[x].ded_name1,nameded1);
strcpy(empRec[x].ded_name2,nameded2);
strcpy(empRec[x].ded_name3,nameded3);
empRec[x].ded_n1 = amount1;
empRec[x].ded_n2 = amount2;
empRec[x].ded_n3 = amount3;
empRec[x].netPay = empRec[x].grossPay-empRec[x].tax-amount1-amount2-amount3;
}
gotoxy(2,19); cprintf("Saving entry... ");
delay(PAUSE); break;
}
else
{
gotoxy(2,19); cprintf("Saving cancelled... ");
delay(PAUSE); break;
}
}
}
if(idCheck==0)
{
gotoxy(2,19); cprintf("Employee record not found... ");
delay(PAUSE);
}
gotoxy(2,19); cprintf("Add deduction again? (Y/N) ");
ch=0;
while(ch != 'Y'&& ch != 'N')
{
ch=toupper(getch());
}
}
}

void viewDed()
{
ch=0;
while(ch != 'N')
{
window(8,4,72,22); idCheck=0;
textattr(2+(0<<4)); clrscr(); textattr(7+(0<<4));
gotoxy(3,2); cprintf("Enter code : "); scanf("%s",&ID);
for(x=0;x<cntrX+1;x++)
{
if(strcmp(ID,empRec[x].code)==0)
{
idCheck=1;
gotoxy(3,5); cprintf("Name : ");
gotoxy(3,6); cprintf("Monthly Pay : ");
gotoxy(46,5); cprintf("Sex : ");
gotoxy(46,6); cprintf("Status : ");

gotoxy(17,5); printf("%s %s %s",empRec[x].fname,empRec[x].lname,empRec[x].mname);
gotoxy(17,6); printf("%.2f",empRec[x].grossPay);
gotoxy(55,5); printf("%s",empRec[x].sex);
gotoxy(55,6); printf("%s",empRec[x].status);

gotoxy(16,9); cprintf(" Type of Deduction ³ Amount");
gotoxy(16,10); cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");
gotoxy(17,11); cprintf("1)");
gotoxy(17,12); cprintf("2)");
gotoxy(17,13); cprintf("3)");
gotoxy(17,14); cprintf("4)");
gotoxy(36,11); cprintf("³");
gotoxy(36,12); cprintf("³");
gotoxy(36,13); cprintf("³");
gotoxy(36,14); cprintf("³");
gotoxy(36,16); cprintf("³");
gotoxy(16,15); cprintf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ");

gotoxy(20,11); printf("Salary Tax");
gotoxy(20,12); printf("%s",empRec[x].ded_name1);
gotoxy(20,13); printf("%s",empRec[x].ded_name2);
gotoxy(20,14); printf("%s",empRec[x].ded_name3);
gotoxy(20,16); printf("Net Pay");

gotoxy(39,11); printf("%.2f",empRec[x].tax );
gotoxy(39,12); printf("%.2f",empRec[x].ded_n1 );
gotoxy(39,13); printf("%.2f",empRec[x].ded_n2 );
gotoxy(39,14); printf("%.2f",empRec[x].ded_n3 );
gotoxy(39,16); printf("%.2f",empRec[x].netPay);
}
}
if(idCheck==0)
{
gotoxy(2,19); cprintf("Employee record not found... ");
delay(PAUSE);
}
gotoxy(2,19); cprintf("View deduction again? (Y/N) ");
ch=0;
while(ch != 'Y'&& ch != 'N')
{
ch=toupper(getch());
}
}
}

void linefill(int start)
{
textattr(0+(7<<4));
gotoxy(31,start); cprintf(" ");
}

void exitSys()
{
window(8,4,72,22);
textattr(7+(0<<4)); clrscr();
gotoxy(16,10); printf("Please wait while system exits... ");
delay(PAUSE);
}

Tuesday, January 15, 2008

I'm on a Vacation Leave

This blog will become idle for about a week as I take my much awaited vacation leave from work.

I'll be going to my hometown, Gen. MacArthur, E. Samar, to attend the anniversary of Nanay when she was taken by the Lord.

I will be back early next week to post more programming source codes and tutorials and pictures of our hometown.

Until then...

Automatically Search ListBox Using API in Visual Basic

Using API, this codes automatically searches the listbox for whatever you type in the textbox.

To use this codes, add a ListBox, named List1 and a TextBox, named Text1 into your project and copy and paste the codes to your project.

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Integer, _
ByVal lParam As Any) As Long

Const LB_FINDSTRING = &H18F

Private Sub Form_Load()
With List1
.AddItem "Computer"
.AddItem "Screen"
.AddItem "Modem"
.AddItem "Printer"
.AddItem "Scanner"
.AddItem "Sound Blaster"
.AddItem "Keyboard"
.AddItem "CD-Rom"
.AddItem "Mouse"
End With
End Sub

Private Sub Text1_Change()
Index = SendMessage(List1.hwnd, LB_FINDSTRING, -1, _
ByVal CStr(Text1.Text))
If Index < 0 Then Exit Sub
List1.ListIndex = Index
Text1.Text = List1.List(Index)
End Sub

Saturday, January 12, 2008

How to Make Context Menu (Pop up) Using API in Visual Basic

This is a very good example on how to make context menu or pop-up menu using API.

Context menu (pop up menu) is useful for your program, specially if it's heavy in graphic. A program with context menu far more user-friendly than one which has not.

In my case at work, are program usually deals with map (autoCAD maps), so context menu is very important. Fortunately, Visual Basic 6 has APIs to do just that.

Copy and paste the source codes below into your VB project and you're ready to go.

Private Enum BTN_STYLE
MF_CHECKED = &H8&
MF_APPEND = &H100&
TPM_LEFTALIGN = &H0&
MF_DISABLED = &H2&
MF_GRAYED = &H1&
MF_SEPARATOR = &H800&
MF_STRING = &H0&
TPM_RETURNCMD = &H100&
TPM_RIGHTBUTTON = &H2&
End Enum

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function TrackPopupMenuEx Lib "user32" (ByVal hMenu As Long, _
ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, _
ByVal HWnd As Long, ByVal lptpm As Any) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _
(ByVal hMenu As Long, _
ByVal wFlags As BTN_STYLE, ByVal wIDNewItem As Long, _
ByVal lpNewItem As Any) As Long
Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim hMenu As Long

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Dim Pt As POINTAPI
Dim ret As BTN_STYLE

If Button = vbRightButton Then
hMenu = CreatePopupMenu()
AppendMenu hMenu, MF_STRING, 1, "New"
AppendMenu hMenu, MF_STRING, 2, "Open"
AppendMenu hMenu, MF_SEPARATOR, -1, "Add"
AppendMenu hMenu, MF_STRING, 3, "Exit"
GetCursorPos Pt
ret = TrackPopupMenuEx(hMenu, TPM_LEFTALIGN Or TPM_RETURNCMD, _
Pt.X, Pt.Y, Me.HWnd, ByVal 0&)
DestroyMenu hMenu

If ret = 1 Then
MsgBox "New"
ElseIf ret = 2 Then
MsgBox "Open"
ElseIf ret = 3 Then
MsgBox "Exit"
End If
End If
End Sub

Friday, January 11, 2008

10 Type Of Girls in the IT World

Do you have women in your IT department? See if she belongs to any of the list below.

1. HARD DISK GIRLS: she remembers everything, and FOREVER.

2. RAM GIRLS: she forgets about you the moment you turn her off.

3. WINDOW GIRLS: everyone knows that she can't do a thing right, but no one can live without her.

4. SCREENSAVER GIRLS: She is good for nothing but at least she is fun.

5. INTERNET GIRLS: Difficult to access.

6. SERVER GIRLS: Always busy when you need her.

7. MULTIMEDIA GIRLS: She makes horrible things look beautiful.

8. CD-ROM GIRLS: She is always faster and faster.

9. EMAIL GIRLS: For every ten things she says, eight are nonsense .

10. VIRUS GIRLS: Also known as "wife'' when you are not expecting her, she comes, install herself and uses all your resources. If you try to uninstall her, you will lose something, if you don't try to uninstall her, you will lose everything...

Have you ever come across with this types of girls at your workplace? Well. I'm lucky enough, there's no girl in our team (gay maybe). It would have been more difficult. (^_^)

See also:
Top 25 explanations by programmers

Thursday, January 10, 2008

Accessing MySQL Database Using PHP

Accessing MySQL database is one of the best uses of PHP. In fact, the PHP's support for MySQL has been included since the first public usable version of the language. PHP and MySQL are like blood-brother, as some programmers say.

This PHP source code shows how to access a MySQL database and display the result. This example assumes the you're running PHP and MySQL in your local PC. If you don't have PHP and MySQL, you can download the XAMPP installer. XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. I use this a lot.

In your MySQL, create a database named "company" and a table named "employee". See the SQL DDL below.
create table employee(
id smallint(5),
name varchar(35),
email varchar(35));


Connect to database, where;

"localhost" is you database server
"un" is the username defined in your database
"pw" is the password for the username

$db = mysql_connect("localhost", "un", "pw") or
die("Cannot connect to the database");


Select the database

mysql_select_db("company");


Set up the SQL statement and query the employee table

$result = mysql_query("SELECT id, name, email FROM employee") or
die(mysql_error());


Loop & display the resultset

while($rows = mysql_fetch_assoc($result))
{
echo "<b>ID</b>".$rows["id"]."<br>";
echo "<b>Name</b>".$rows["name"]."<br>";
echo "<b>Email</b>".$rows["email"]."<br><br>";
}


Summing it all up

<?php
$db = mysql_connect("localhost", "un", "pw") or
die("Cannot connect to the database");
mysql_select_db("company");

$result = mysql_query("SELECT id, name, email FROM employee") or
die(mysql_error());

while($rows = mysql_fetch_assoc($result))
{
echo "<b>ID</b>".$rows["id"]."<br>";
echo "<b>Name</b>".$rows["name"]."<br>";
echo "<b>Email</b>".$rows["email"]."<br><br>";
}
?>


Note: You can use print instead of echo.

Tuesday, January 08, 2008

PHP Basics: A Simple Tutorial on PHP

I'm a self-teach PHP developer, and being one, I know how self-teach programmer who likes to have grapple the basics of PHP, need to have a good, yet simple tutorial on the language.

I made this PHP tutorial as simple as possible for you to grapple the basics of the PHP programming language. You can also use this as a good reference of the basics of PHP. So I suggest you bookmark this post and come back here whenever you need. You are most welcome. (^_^)

1. Basic Syntax

A PHP scripting block always starts with <?php and ends with ?>. It can be placed anywhere in the document.

You can also use the shorthand symbol, <? and end with ?>, on servers with shorthand support enabled

However, it is recommended that you use the standard form (<?php) rather than the shorthand form (<?) for maximum compatibility,

Example:

<?php
echo "Hello World";
?>


2. Comments

Use // sign to make a single-line comment or /* and */ signs to make a large comment block.

Example;

<?php
//This is a comment

/*
This is
a comment
block
*/
?>


3. Variables

In php, variables start with a $ sign symbol. Variables may contain strings, numbers, or arrays but should start with a letter.

Rule:
* A variable name must start with a letter or an underscore "_"
* A variable name can only contain alpha-numeric characters and
underscores (a-Z, 0-9, and _ )
* A variable name should not contain spaces. If a variable name should be more
than one word, it should be separated with underscore ($my_string),
or with capitalization ($myString)


Valid: $a, $name, $name1
Invalid: $3, $3name

Example

<?php
$text="Hello World";
echo $text;
?>


4. Operators

Arithmetic Operators

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (division remainder)
++ Increment
-- Decrement


Assignment Operators

Operator Example The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y


Comparison Operators

Operator Description
== is equal to
!= is not equal
> is greater than
< is less than
>= is greater than or equal to
<= is less than or equal to


Logical Operators

Operator Description
&& and
|| or
! not


5. Conditional Statements

if...statement

<?php
$d=date("D");
if ($d=="Fri")
{
echo "Have a nice weekend!";
}
?>


The If...Else Statement

<?php
$d=date("D");
if ($d=="Fri")
{
echo "Have a nice weekend!";
}
else
{
echo "Have a nice day!";
}
?>


The ElseIf Statement

<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>


The Switch Statement

<?php
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>


6. Arrays

Indexed Array

$names = array("Babyrose", "Kabalweg");

or

$names[0] = "Babyrose";
$names[1] = "Kabalweg";


Associative Arrays

$age = array("Babyrose"=>27, "Kabalweg"=>28);
$ages["Babyrose"] = "27";
$ages["Kabalweg"] = "28";


Multidimensional Arrays

$families = array
(
"Badinas"=>array
(
"Joel",
"Kabaleg"
),
"Aranas"=>array
(
"Rosalina",
"Babyrose"
)
);


7. Looping

while loop

<?php
$x=1;
while($x<=10)
{
echo "The number is " . $x . "<br />";
$x++;
}
?>


do...while loop

<?php
$x=1;
do
{
echo "The number is " . $x . "<br />";
$x++;
}
while ($x<10);
?>


for loop

<?php
for ($x=1; $x<=10; $x++)
{
echo "The number is " . $x . "<br />";
}
?>


foreach loop

<?php
$arr=array("one", "two", "three", "four", "five");
foreach ($arr as $value)
{
echo "Value: " . $value . "<br />";
}
?>
</pre>


8. Functions

Simple

<?php
function sayMyName()
{
echo "You are Joel Badinas";
}
?>


Parameterized

<?php
function sayMyName($name)
{
echo "You are ".$name;
}
?>


Returning Values

<?php
function sayMyName()
{
$name = "You are Joel Badinas";
Return $name;
}
?>

Monday, January 07, 2008

Bill Gates Will Resign from Microsoft

If you still haven't heard of it, Bill Gates will retire as Chief Software Architect and Chairman of Microsoft this coming July 2008. He will be working part-time for Microsoft while working full-time for the foundation he and his wife Melinda founded. He announced his resignation last week in a press conference.

As of July 2008, Gates will transition from his day-to-day role as Chief Software Architect and Chairman of Microsoft to just being the Chairman. Chief Technical Officer Ray Ozzie will immediately assume the title of Chief Software Architect and begin working side by side with Gates on all technical architecture and product oversight responsibilities while Chief Technical Officer Craig Mundie will immediately take the new title of Chief Research and Strategy Officer.

"I don't know what it's going to feel like not to come in every day and work 10 hours," Gates said. "I have a sense of what it's like to do foundation work because I've squeezed that in part time, but I think it will probably take me a while, just like six years ago when I switched off from CEO. It might take me a year and a half to get used to my role. That's a little bit of an unknown now and because I've got two years, I don't even really want to go there now, because I'll figure it out when I get there."

Sunday, January 06, 2008

Warning for RealPlayer 11 Users, You are Vulnerable to Hacker Attack

If you a RealPlayer user, this is for you.

Experts in the field of internet security issued a warning saying that RealPlayer is vulnerable exploitation. The flaw of the recent version of the product, the RealPlayer 11, could allow hackers to remotely control a PC if successfully exploited.

This security flaw was discovered by Evgeny Legerov, of Russian security firm GLEG.

Webuser reports:
As yet unpatched by Real Networks, the vulnerability "is caused due to an unspecified error and can be exploited to cause a buffer overflow," according to an advisory from a separate security company, Secunia.

Secunia also warned surfers not to open untrusted media files or browse unfamiliar websites, rating the vulnerability "highly critical".

How to Check if Email Address is Valid in PHP

If your website is accepting email address as input, it is always wise to check of it's validity as some users, especially spammers, have a habit of inputing garbage text in email fields. If you don't check it, you end up saving invalid email.

The PHP funtion below checks for the validity of the email address passed to it.

PHP function
function isValidEmail($address)
{
return preg_match("/^[a-z0-9._\-]+[@]([a-z0-9\-]+[.])+([a-z]{2,4})\$/i",
$address);
}


Using the function
if(!isValidEmail($_POST["email_address"]))
echo "Please input a valid email address.";
else
echo "Your email is valid";

New Year's Resolution from the Adsense Blog

Still at a lost this New Year? Well, if you're an Adsense publisher, the Adsense Blog listed some New Year's resolution you could choose from. Although a little late, it's worth the try. (^_^)

1. Turn my custom channels into ad placements, complete with descriptive details to attract placement-targeting advertisers.

2. Regularly check my sites for compliance with the AdSense program policies.

3. Keep my address and tax info up to date so that my payments are accurate and timely. (And sign up for EFT if it's available to me!)

4. Place more of my ad units above the fold and on my homepage for increased visibility -- and advertiser appeal.

5. Share my AdSense expertise with other publishers in the AdSense Help Forum.

6. Opt in to text and image ads to make the most of the available ad inventory for my content.

7. Use the Manage Ads feature to experiment with removing the borders from my ad units.

8. View the Payments Demo and payments schedule with rapt attention so I'll always know when to expect my next payment.

Saturday, January 05, 2008

How To Pair a Single Quote, Useful for SQL Queries and Statements

This function will ensure that a single qoute(') is paired. This is useful when executing SQL queries because an unpaired qoute(') will spit an SQL error in all database engine.

This source codes is written in Visual Basic 6.

Public Function BalanceQoute(sText As String) As String
Dim sSavar As String, i As Integer
sSavar = ""
For i = 1 To Len(Trim(IfNull(sText)))
If Mid(sText, i, 1) <> "'" Then
sSavar = sSavar + Mid(sText, i, 1)
Else
sSavar = sSavar + "''"
End If
Next i
ChkValue = sSavar
End Function

Thursday, January 03, 2008

Top Ten Useful Google Search Tricks

Google is really a big machine that has many uses. Some are known, some aren't. Good thing that Lifehacker listed some of it for us to know and use the tricks such as below.

1. Make Google recognize faces
2. ID people, objects, and foreign language words and phrases with Google Image Search
3. Find music and comic books
4. Find related terms and documents
5. Remove affiliate links from product searches
6. Use Google as a free proxy
7. Compare items with "better than" and find similar items with "reminds me of"
8. Convert currency, metrics, bytes, and more
9. Track flight status
10. Get the local time anywhere

Read more here.

Visual Basic: How To Automatically Search Text in a Listbox

This codes searches the list for whatever you type in the textbox that matches the text in it.

To use this codes, add a ListBox, named List1, and a TextBox, named Text1 into your project and copy and paste the codes bleow to your project.

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F

Private Sub Form_Load()
With List1
.AddItem "Computer"
.AddItem "Screen"
.AddItem "Modem"
.AddItem "Printer"
.AddItem "Scanner"
.AddItem "Sound Blaster"
.AddItem "Keyboard"
.AddItem "CD-Rom"
.AddItem "Mouse"
End With
End Sub

Private Sub Text1_Change()
Index = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
If Index < 0 Then Exit Sub
List1.ListIndex = Index
Text1.Text = List1.List(Index)
End Sub

Great Resource for Pet Lovers

Here's another good online resource when buying dog supplies, the JeffersPet.com website.

This website is your best source for discount pet supplies. They have been in operation since 1975.

JeffersPet.com brings that same dedication to providing the best discount pet supply selection to our online pet supply store. We strive to offer the latest discount pet supplies and pet vaccines with the best customer service available anywhere.

Whether you have one dog or ten, a few farm animals or a whole farm, Jeffers Pet has the products you need to keep your animals safe, healthy and happy. Our online pet supply store is constantly updated with the products you tell us you need — and all at great prices.

Recent Post