Home | Services | Software Approach | Who We Are |
Resources | Testimonials | Contact Us | Products |
Visual Basic Tips & Tricks #31 - Creating An Active-X Control
The ability to create a custom OCX can be a very useful feature and not as hard to do as you might think. For example, for one application I created a control array so I did not have to create it for each form. Since the buttons on most of the forms are very similar I can encapsulate those features within the control. I also established properties that allow the user of the control, me in this case, to override these properties.
I will give you the steps to create a simple control in this tip. Suppose you are writing an application and your users want all the command buttons to be light blue. You could create buttons using the standard Microsoft command button. You can then change the properties each time or cut and paste the completed button. This gets old pretty quickly.
Thats it for now.There will be more on creating an Active-X control in the next tip.Be sure to save everything before exiting.
Visual Basic Tips & Tricks #32-Adding Properties to your Active-X Control
Open the project group that you created for Tip #31 called BlueButton.vbg.Set the Project TestButton as the default project.To do this right-click on TestButton within Project Explorer then choose Set as Startup. If you look at the button on the form, you will see that there are very few properties.You cannot change the caption on the button; or the width or height of the button.This limitation can be solved by adding properties to the custom control that you created.
For example, here is how to add a caption property to the button.
1)Double click on the BlueButton control in the MyBlueButton project.Add this code.
Public Property Get Caption() As String
msCaption = MyBlueButton.Caption
End Property
Public Property Let Caption(ByVal psCaption As String)
MyBlueButton.Caption = psCaption
End Property
Also add
Dim msCaption As String
To the Declaratives.
2)Now return to the form in the TestButton project, you will see that there is now a Caption properties on the BlueButton1 control. It can be change at design or runtime just like a normal VB button.
The next tip will show you how to register you custom control.
Visual Basic Tips & Tricks #33-Registering your Active-X Control.
Now you can use the OCX just like any Microsoft or Third-Party Control.
One final point, if you change your OCX after you compile it, be sure to use Binary Compatibility with the prior version.This option can be found under Project, Properties, Component. Click on binary compatibility and use the Explorer-like process to find your prior version.If you do not do this, you may have to re-link all projects that use the OCX.Note: binary compatibility is not possible if any Public Properties or Methods have been added or changed parameters.
MetaPro Systems Inc. Visual Basic Tips & Tricks #34 - Avoid Using Integer
Although the Visual Basic (VB) documentation indicates that the integer data type is 16-bit (2-byte) for numbers ranging in value from -32,768 to 32,767, you should almost always avoid using Integer and use Long instead. Long is more efficient. All variables in VB6.0 and earlier versions are stored on a full word boundary. So, if you defined two variables as follows:
Dim iNumber1 as Integer
Dim iNumber2 as Integer
The definition will require 8 bytes. Likewise, defining the two variables using Long will require the same amount of space:
Dim lNumber1 as Long
Dim
lNumber2 as Long
So, Integer does not save you any space. Additionally, VB is forced to mask the second two bytes, which means that more overhead is required to do arithmetic with integers than with longs. The only case where Integer can take less space is when the Type construct is applied. For example: Type MyRecord Field1 as Integer Field2 as Integer End Type This will all change in VB.NET. In that new release Integer will be 4 bytes and Long will be 8 bytes. There will be a wizard that will convert your VB6.0 Longs to VB.NET Integers.
MetaPro Systems Inc. Visual Basic Tips & Tricks #35 - ASP for VB Developers
While there is still plenty of work for Visual Basic developers in desktop and client-server applications, the wave of the future is Web based applications. Accordingly, many VB developers would like to reinvent themselves as Web developers. I recommend learning ASP as the logical step towards achieving this goal.
ASP is like HTML on steroids. It utilizes VBScript, a subset of VB, to generate HTML depending on user responses and database information. The main distinction between VBScript and native VB is that VBScript does not allow typing of variables. For example you type "Dim iNumber" instead of "Dim iNumber as Integer". ASP has a few constructs of its own, but for the most part it is derived from VBScript and HTML. If you know VB and HTML you're well on your way to learning ASP.
If you have Studio 6.0, you can use Visual Interdev to develop your ASP pages. While ASP development is more cumbersome than developing in native VB, Microsoft is promising a big improvement with Studio.Net, which will include VB.NET and ASP.NET.
MetaPro Systems Inc. Visual Basic Tips & Tricks #36 - Hints on ASP for VB Developers
When you begin using ASP you should leverage your Visual Basic skills as much as possible. Here's one way to do this:
- Put as much of the functionality that is not screen related in custom DLLs.
- Test the custom DLLs in VB by creating an executable driver.
- Test them in ASP. An example of code to define a DLL within ASP is:
Set Session("gcloAPICalls") = Server.CreateObject("msiAPICalls.clsAPICalls")
Set mcloAPICalls = Session("gcloAPICalls")
msExecuteDir = mcloAPICalls.sGetEnvironmentVariable(msEnvironmentVariable)