Tag Archives: vb

How to add font selector property to User-control in VB6


Adding a property to a user control in VB6 requires 4 subroutines to be filled, the Let/Set, Get and property Bags respectively.

Let and get have the variant as return type as an argument, which means any value can be accessed through the property.

Public Property Get Interval() As Variant

Interval = Timer1.Interval

End Property

Public Property Let Interval(ByVal vNewValue As Variant)

Timer1.Interval = vNewValue

PropertyChanged “Interval”

End Property

Suppose you want to change how do you get the Font Dialog within the Property Window. This can be possible with use of stdfont  in place of Variant as follows

Public Property Set Font(ByVal Nfont As StdFont)

Set lbl_Time.Font = Nfont

Refresh

PropertyChanged “Font”

End Property

Public Property Get Font() As StdFont

Set Font = UserControl.lbl_Time.Font

End Property

The complete VB6 Stopwatch Project can be accessible in my GitHub repository

VB6: List all printers using code in Windows


Listing all printers with name, Port in VB6 is simple as listing default printer port using Kernel32 library . Today we going show you how to do this.

As usual we start with function declaration, then define a new function which add all information into a list box. Here we goes

Kernel32 GetProfileString method

Declare Function GetProfileString Lib “kernel32.dll” Alias “GetProfileStringA” (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long

Add printer information into a list box

Public Sub GetPrinterList(lstPrinter As ListBox)Dim PrintData As PrinterDim defprinterpos%

For Each PrintData In Printers

‘ Add printer name and port to list

lstPrinter.AddItem PrintData.DeviceName & ” at: ” & PrintData.Port

‘ Check for default printer

If PrintData.DeviceName = Printer.DeviceName Then defprinterpos = lstPrinter.NewIndex

Next

lstPrinter.ListIndex = defprinterpos%

End Sub

This sub procedure will take list box as argument, and add printer to this list box.

Call the sub

The final line of code just invoke the procedure and see what we have.

Happy coding

Add new fields to Access table using VB6


Let me show how to add a new field into an existing access database using Visual Basic 6.0.Using the tableDef and Filed object you can create new fields. Firstly, you need to create Database and Recordset object, mke sure the DAO access object library. Continue reading

How to auto complete text box in VB6


How to add a auto complete feature in Microsoft Visual Basic 6 ?

With the help of some creepy code, we can save the entry into a data file temporarily and later we can use them as input for auto complete the name/place/text.

The code is work with Text box as well as Combo box. Drop the following code to a module call the methods defined. Continue reading