Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing form controls in vb6

Tags:

controls

vb6

We have an in house button control, and quite frankly it sucks. I'd like to replace it but I don't want to go onto every form in our project and delete/add a new control. It seems to me that if I design a new button that has all the same properties as the old one then I ought to be able to give it the same name as the old one and just replace all the reference lines in the vbp files to point to the new control.

Has anyone tried this (better yet have you heard of a tool that will do it for you) and if so what 'gotchas' should I be on the look out for?

Thanks!

like image 695
Brandon Moore Avatar asked Aug 07 '26 13:08

Brandon Moore


2 Answers

The *.vbp files are one place you'll need to change. There are also references to the used control libraries in the files containing GUIs -- that's form (*.frm), control (*.ctl), and property page (*.pag) files. These files are in a plain text format and you can see the references at the top. They look like this:

Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"

Those refs will need to be added or updated in all relevant files if the new control is a compiled OCX. If it's in the same project I don't think it needs any reference there, and if it's in a different project in the same project group I'm not sure. Save a test form with the new control to see.

Note that you don't have to keep the same control class name. Inside the *.frm/ctl/pag files, instances of individual controls on them are represented by a simple format like this:

Begin VB.CommandButton Command2 
   Caption         =   "Cancel"
   Height          =   375
   Left            =   2460
   TabIndex        =   1
   Top             =   2400
   Width           =   1455
End

The syntax of the first line there is "Begin LibraryOrProjectName.ClassName NameOfThisInstance". So, provided the offending control's name is distinctive it should be easy to search & replace references to it both in the BASIC source and in the GUI layouts. You might want a plain text editor that can perform search and replace across multiple files (Notepad++ is one).

Some control properties are stored like this:

   Picture         =   "frmMain.frx":292F

These correspond to the *.frx, *.ctx, and *.pgx files, which contain binary data for the values of certain control properties. I don't think these files should need altering or cause any problems. They don't appear to contain control names.

Use a full compile (Ctrl+F5) to be sure no problems linger in parts of the source afterward.

Never tried it. Good luck.

like image 119
Boann Avatar answered Aug 10 '26 14:08

Boann


There is only one tip to be added to the accepted answer.

If you need to replace any generic VB control with 3rd party or custom ActiveX control you must replace the:

BeginProperty Font

with

BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}

Omiting to do so results with run-time error 713 when trying to edit/open the form.

If there is no BeginProperty statement in the block then control uses default font and this replacement is not needed.

like image 35
Milan Oparnica Avatar answered Aug 10 '26 13:08

Milan Oparnica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!