Sunday, December 27, 2009

Form control inv VB 6.0

What is a (MDI) Form object in visual basic?

A windows form is the basic visual element and place holder for other controls in any windows application. Without Forms we can not provide GUI (Graphical User Interface) in any applications. In VB projects there are two types of Forms. An MDI (Multiple documents Interface) and simple form.

MDI Forms are container / parent form for all other child forms in an Application. Normally a windows application needs several child forms for various functions. These forms will open inside an MDI parent window. A good example for MDI application is Microsoft office word, in which all word documents are opened inside the parent window. We can use Tile Horizontally, Tile Vertically, Cascade functions to arrange the child forms inside the MDI parent form.

In order to create an MDI application you have to add atleast one MDI form to your application. The select the child form, in the properties window, set 'MDI child' property 'true'. Otherwise you will get error 'No MDI form available to load'.

To add a form open project explorer, by pressing ctrl+R or View -> Project Explorer menu. Then right click Forms Folder, click Add, Click form, Mdi form etc.

Now we will see some important properties, events and methods supported by the form object.

BackColor: Set the background colour of the form.
Caption: This is used to set the Window's Title bar text.
BorderStyele: Set the appearance of the border. 0-None: No border, 1-Fixed Single, 2-Sizable,3-FixedDialog, 4-FixedToolWindow,5-SizableToolWindow
ClipControls: Determines whether graphics methods in paint events repaint an entire object or newly.
ControlBox: Returns a value indicationg whether a Control-Menu box is displayed on a form at run time. (True/False)
Font: Set the font name size, Bold Italic etc.
Height: Height of the form
KeyPreview: Returns/sets whether keyboard events for an object are invoked before keyboard events for controls on that object.
Left: Returns/sets the distance between the internal edge of an object and the left edge of its container. Typically the left determines the distance from the screen's left edge to the form's left edge in twips unit.
MaxButton: Set to true if you want to display the Maximize button otherwise set to false.
MDIChild: Set to true if the form is an mdi child displayed inside an Mdi parent window.
MinButton: Set to true to display the minimize button
StartupPosition: Returns or sets a value specifying the position of a form when it first appears. The constants are 0-manual, 1-centerowner, 2-centerscreen, 3-Windows default.
Width: Width of the form in twips
Windowstate: Returns/sets the visual state of a frm window at run time. 0-normal, 1-minimized, 2-maximized.

The important events of the form are Initialize, Load, Activate, Unload, Terminate. While opening the form Initialize event will occur first. In this portion you will write the code to initialize form variables set properties etc. Then load event will occur. Activate event occur next. Activate will occur every time the form becomes an active form. That mean if you minimized the form for some time and maximize it again the activate event will occur. Initialize and load will occur only once. While closing the form Unload will fire first then Terminate event. Write your clean up code in unload. Destroy/free any global variables here.

Method / functions supported by VB Forms

Visual basic forms support the following methods. The most common are show, hide, and refresh. We will use show() method to display a form. This will load a form and display it on the screen. Hide will hide the form. Refresh will repaint the form and updates display. PrintForm method is used to print the form using printer.

So we have learned the basics of Windows Forms creation in VB. Just open a standard exe project and play with these properties, methods and events to familiarize with them. We will move on to the next level.

What is possible with Vb and .net?

Vb .net, limitless possibilities

Vb 6.0 or the advanced version, vb .net offers limitless possibilities to programmers, end-users, companies and enterprises. Due to its RAD (Rapid Application Development) features, quick language learning curve, fully documented online support from Microsoft's MSDN library, support for wide array of databases including MS-SQL server, MS-access, Oracle Database Server, Foxpro, Mysql, Dbase, etc., Availability of third party components and Activex controls the possibilities with vb .net is limitless. From small-to-medium business to large ERP Solutions anything can be done with visual basic.

With the introduction of ASP (Active server pages) technology from Microsoft, vb is not only a windows programming language, it can be used to create powerful web applications as well. With the introduction of ASP .NET and dot net Framework, the next dimension to classic VB Microsoft revolutionized the web application development. The seagate crystal reports has been the default reporting technology with Visual Basic. It can be used to create powerful reports with charts and graphs. You can easily call Win32 API from inside the vb code. Just include a library function and call it within your program. You create easy applications to shutdown your PC, communicate over network, control hard disk drives, create multimedia audio-video applications, control Graphics etc.

Win32 APIs have been replaced by Visual Studio .NETs Built-in assemblies. These assemblies have similar classes that encapsulate those functions. Still Win32 APIs are available with vb .net. For Example Windows Management Instrumentation (WMI) classes are available in .NET to query windows system information, like available space in disk drives, for example.

I started learning VB 6.0 during the year 2001. My father bought me a new HCL busybee for self-study purpose. First i installed Foxpro Dos version. I had developed interest for the Foxpro languages. Foxpro was widely used for business applications like accounting, billing, stock maintenance etc.

Dos version of Foxpro had many limitations. You have to write lines of codes to display a menu item. Soon i installed Visual Studio 6.0 on my computer. Visual studio came with Visual Basic, Visual c++, Visual Foxpro and some other goodies. The visual basic IDE really thrilled me. I was excited when i created my first Windows. In i did nothing to create a Windows form. I just created a new project, a standard EXE project that automatically added a windows form. To do this VC++ i have to write tons of c++ code. I have to call functions like CreateWindowEx() , etc., But vc++ has its own advantages like speed and robustness.

First i learned the usage of controls, basic language, database connectivity. These are essential for creating a useful business application. Most business application need to store data in database table.

I applied these concepts later, to develop commercial applications. I earned my living through VB. The applications include billing, inventory, accounting, etc. I created Astrology software in VB. I created IVRS software in VB. I created weigh-bridge software, Fruitshop, departmental store, hardwares, sizing, cotton mill, Garments ERP and much more software applications using VB 6.0.

I made transition to VB .NET and C# .net at the right time. Now i develop applications using c#. But the good old VB language is still in use. Some of my clients still prefer VB. Some of them have some knowledge in VB. Some customers prefer c#. Many young business owners have basic computer knowledge these days. So they choose their Computer hardware, printer, Operating system etc., Similarly they choose their software applications, language used, database storage etc.,

Ok. so much for introduction. You feel bored? right. We will move on to the next phase.

Saturday, December 26, 2009

VB 6.0 Controls introduction

Common Controls in VB 6.0



Controls are UI elements placed on Windows Forms. Every application has some user input elements in order get some input and provide output. For this purpose visual basic design interface - IDE (Integrated Development Environment) provides some default controls. The controls collection are not limited to the default system controls. The controls can be extened by using activex controls from project -> Components... menu.

The most commonly used controls in vb 6.0 are label, textbox and command button controls. Combobox, listbox, checkbox are other important controls. In this tutorial we will discuss these basic vb control elements. In subsequent lessons i will provide the properties, methods and events for each control with example and sample source code.

PictureBox:

The vb control to display a graphical picture on windows form. You will use picture box's picture proerty to set an image to display. JPEG, BMP, GIF and some other formats are supported.

Label:

The label control is used to display informative text on the windows form. This is commonly descriptive text before each input element. For example, for textbox control for the input of customer name, a label is used before the textbox control with caption 'customer name'. The common property is Caption property used to change the display text. vb .net use 'text' property instead of 'caption'.

Textbox:

Textbox is the most common control used in vb projects. The first controls used on any vb .net project is lable and textbox. Text box supports a number of properties to change the appearance and functionality of the textbox. The most common property is 'text', which represents the displayed text inside the textbox control. BackColor and Forecolor are used change the display color of the control. You can use PasswordChar to hide the character typed with star(*). You can use MultiLine property to type multiple lines inside the textbox. Richtextbox is and activex control that support full text formatting as microsoft word.

Frame:

In vb 6.0, Frame controls are placeholders that group similar controls. Option buttons are commonly put inside frames for similar purpose. Caption is the common property. In vb .net the frame control is called Groupbox. Dot net has some improved functionality.

Checkbox

In vb 6.0 checkboxes are used to give yes or no type inputs. You can tick or untick the checkbox. 'Value' property is the common property. The two values for this property is 1-checked and 0-unchecked.

OptionButton:

Optionbutton is otherwise called radiobutton. In old radio transistors band selection was used with buttons. If you select one button all other buttons are deselected. Radiobutton serve the similar purpose. The common property is 'Value', which is either True or False.

Combobox:

The combobox another good vb 6.0 control used to display a list of values or strings. You can add items in the combobox using the addditem function during run time code or List property during design time. Style is another common property which has 0-Dropdown combo, 1-Simple combo, 2-Dropdown list.

Listbox:

Listbox serves similar purpose as combobox. Combobox occupies a small size on the screen while listbox occupies a lot of space. Both controls supports database connectivity. You can connect to sql, ms-access databases and tables to display field values.

HScrollBar: Horizontal scroll bar

VScrollBar: Vertical Scroll bar

Timer:

Timer control is the non-visibile control added on the windows form. Timer control's timer event will fire at specifed 'interval' in milliseconds.

Drivelistbox:

The drivelistbox control is used to display and select Disk drives mounted on the computer. You need not set any property for this control to work. You just add the control on the form.

DirListbox:

Displays list of directories in the Drive, set in path property.

FileListBox:

Displays list of files in the selected drive and directory.

Image:

Displays graphics images on windows forms.

Data:

Only built-in vb 6 control to fetch data from databases like oledb, odbc, sql, oracle etc. ADODB control is commonly used. sophisticated programs use reference to Microsoft Activex Data object library

Friday, December 25, 2009

Messagebox in vb 6 - msgbox

msgbox in vb 6

How to diplay a message box in Visual Basic?

Message Box is used to display a message to the user. It can prompt the user to do something. It can received inputs like 'Yes' or 'No', 'Ok' or 'Cancel'. It can give warning messages, Exclaimatory messages,

The msgbox function has 5 arguments as follows:

Msgbox(Prompt,[Buttons AS VbMsgBoxStyle=vbOkOnl],[Title],[HelpFile],[Context]) AS VbMsgBoxResult

The first argument (parameter) is the prompt, which is clearly the the prompt text or caption.

The second argument, button constants are VbAbortRetryIgnore, vbApplicationModal, vbCritical, vbDefaultButton1, vbDefaultButton2, vbDefaultButton3, vbDefaultButton4, vbExclamation, vbInformation, vbMsgBoxHelpButton, vbMsgBoxRight, vbMsgBoxRtlReading, vbMsgBoxSetForeground, vbOkCancel, vbQuestion, vbRetryCancel, vbSystemModal, vbYesNo, vbYesNoCancel

The third argument 'Title' refers to the Title bar caption of the Messagebox window. You can type any string here.

Help file refers the location of HTML or windows help file. This argument is applicable if you give vbMsgBoxHelpButton for the second argument (button constant). This will display a 'help' button in the messagebox and if the user click this button the help file will open.

The messagebox result constants are vbAbort, vbCancel, vbIgnore, vbNo, vbOk, vb Retry, vbYes

For example: If the user click yes button on the messagebox the result is vbYes.

Here is an example of typical Msgbox (Messagebox) function with sample source code:

Private Sub cmdDelete_Click()
If MsgBox("Are you sure to delete this record?", vbYesNo, "Confirm Delete") = vbYes Then
'Write code for deletion
End If
End Sub

When the user clicks the Delete button a messagebox is shown as in the picture. When the user click the yes button the code inside the If - then - endif Control structure will be executed. (Write your code for deletion of the record)

For the second argument you can combine visual elements like warning icons to provide the user visual warning for deletion. Here the example code in vb 6.

Private Sub cmdDelete_Click()
If MsgBox("Are you sure to delete this record?", vbExclamation + vbYesNo, "Confirm Delete") = vbYes Then
'Write code for deletion
End If
End Sub

Friday, December 11, 2009

Visual Basic 6.0 Introduction 1

Even after ten years of the release of the classic Visual Basic 6.0 it is still appealing many programmers and coder. Because of its easy and quick learning curve, Rapid Application Programming (RAD) features this Windows Programming Language from Microsoft is a huge success.

I started learning Microsoft Foxpro 2.5 (DOS Version) in the beginning of 2000s. Foxpro is a database engine with options for User Interface (UI) design. It has limited event driven capabilities. We can design Menus, textboxes and other some other input controls. We can design reports using Foxpro. The limitations are, Foxpro was a DOS based program which works on console text mode.

Still Foxpro is used in some legacy applications commercially available. Microsoft's Foxpro was a success, no doubt. With the success of Windows 95 and Windows 98, Microsoft Released Visual Studio 6.0, with Visual Basic 6.0, Visual Foxpro 6.0 and Visual c++ 6.0 and some other tools. Both Visual Basic and Visual C++ are huge success used widely across the globe.

Even a novice programmer can build a realtime windows application using visual Basic. It can connect to a wide variety of databases like Ms-Access, MS -SQL Server 2000, Oracle, Foxpro, MS-Excel and more.

VB supports a popular microsoft specification, Activex Controls, which are prebuilt object readily available for use in your applications. You can use third party controls or readymade controls shipped with VB 6.0.

You can use Win32 APIs (Application Programming Interface) to access various Windows System functions and features. These include Graphics functions, File and Disk management, Networking APIs, Keyboard and mouse APIs, Process management, Printer management, Windows clipboard, Memory Management and more.

For reporting you can use either Data Reports or Seagate Crystal Reports. The syntax of VB language is simple and easy to understand. Variables are not strongly typed. There is a basic error / exception handling function.

Wednesday, December 9, 2009

JetComp.exe- To Repair MS-Access Database


Repairing Ms-Access Database with JetComp


What will happen if your MS-Access (.mdb) database get corrupted, and you are no longer able to open it? How to recover the data table and other database objects? Where to get a tool for this purpose?


There are situation in life, the access database fill will get corrupt and you will receive message while attempting to open the file directly or through software code. You will get message 'Unrecognized database format'. There are many reasons for this error. The most common reasons are power failures while using the database, hard disk failures, multi-user environment where two users attempt to write the same table at the same time. In these situations the database will get corrupt and rendered useless. There is a good tool to rescue you in these situations. This handy tool is called JetComp and released by Microsoft coporation.


Jet Compact Utility can be downloaded from Microsoft website. Open the downloaded file to extract Jetcomp.exe and jetcomp.doc - a readme file with documenation. To use Jetcomp you need any of the following,


Microsoft Office 97 / Microsoft Office 2000 / Microsoft Access 97 / Microsoft Access 2000 / Microsoft Visual Basic® 5.0 / Microsoft Visual Basic 6.0 / A Microsoft Office Developer Edition 97 run-time application that includes the run-time version of / Microsoft Access 97 / A Microsoft Office Developer 2000 run-time application that includes the run-time version of Microsoft Access 2000 / A Microsoft Visual Basic 5.0 run-time application that includes Microsoft Jet database engine 3.5 / A Microsoft Visual Basic 6.0 run-time application that includes Microsoft Jet database engine 3.5 or 4.0


The application has a simple interface that requires few inputs,


Database to compact from (source) : Here you specify the ms-access .mdb file to be repaired.Database to Compact into (Destination): Here you specify the ms-access file name of the repaired file.You can specify the output format as version 4.x or 3.x.Just Click Compact button. If there is any passwords for the source database you need to provide them. Typical user name is 'Admin'.

Saturday, July 25, 2009

All about programming

I started my software programming career years ago. Over the years i gained knowledger in various platforms and languages. I started developing applications in Foxpro. These applications are typically billing, point of sales, payroll, inventory and accounting. I have MCA (Master of computer Applications) degree from Bharathidasan University, Trichy. I finished the course in 1st class. I worked for some local (Coimbatore based) software companies for few years. I started my own company a few years back. We develope applications in Visaual Basic (the famous VB) lanuage using Ms-Access and SQL server as backend storage.

Click Here to view my company blog

Recently i take projects through guru.com and getafreelancer.com. You too can get projects by bidding.

Click Here to view my freelancer's blog.

In this 'Programming made simple' blog i will provide you step-by-step training on various languages like .NET, VB, c#, SQL, PHP, MySQL and web development.

I have some knowledge in Visual c++ programming with MFC and windows API classes. This too will help you to upgrade your skills to compete in the job market.