Link to home
Start Free TrialLog in
Avatar of GBSW
GBSW

asked on

VBInstance (VB IDE Add-in) info

How do I change a value in the Project Properties using the VBInstance object. I want to update the major/minor/revision value.  Can't find any documentation
Avatar of poneill011098
poneill011098

(assumes VB5)
Firstly, you need to include a reference to Microsoft Visual Basic 5.0 Extensibility.  Now you will be able to see the object model for the IDE.


I used the VB Addin example code for my first steps, which gave me a Connect class, which:

1. Defines an instance of the IDE as:
    Public VBInstance As vbide.VBE

and

2. initialises it as part of your Connect class in the IDTExtensibility_OnConnection event:
    Set VBInstance = VBInst

You will have access to the ActiveProject property as VBInstance.ActiveProject

If the properties you want to change are not explicit properties of the project, use the Read/WriteProperty methods to see if they exist - to determine names, I typically populate all fields with values I can identify then use ReadProperty to document them.

Regards
Paul

Hmm.
Avatar of GBSW

ASKER

I should have been more clear, I suppose.  Getting to the ActiveProject with ReadProperty was the easy part as that is well documented (although Poneill's response is very well written).  The documentation states that .ReadProperty used for "custom" properties, which isn't clear if that includes the items in the standard properties area of the .vbp file.  I've used it to store and fetch stuff in the latter portion of the .vbp file, but I can't figure out how to get the main stuff.  The part I am trying to figure out is how to change MajorVer, MinorVer, and RevisionVer from the main .vbp file.  The syntax is .ReadProperty(Section,Key).  The Key will be something like "MajorVer" or "MinorVer", but what is Section?  I've tried PROJECT, MAIN, MAINPROJECT, VBPROJECT, etc, to no avail.  The only other solution I've thought of is to read in the .vbp file as a standard text, modifiy, and write out again, a pretty lame solution.
If you look in the object browser, the Section in ReadProperty refers to the section in the VB project file (which happens to follow the same format as an INI file).

(It's defined as
    Function ReadProperty(Section As String, _
                          Key As String)  As String
)

Unfortunately, the section containing MajorVer, MinorVer, RevisionVer, etc. has no section name so you shoud probably try something like ReadProperty("", "RevisionVer")

Open your VBP file using Notepad to see a list of all the properties you can get at.

Regards
Paul

Avatar of GBSW

ASKER

Thanks.  null was one of the values I had already tried and it simply fails.  I also already tried reviewing the .vbp file and there is no heading to use as a reference.  You'd think this wouldn't be that complicated considering how friendly most of VBE is.

Any guesses at what Section might be would be appreciated.
Null won't work as a reference (but I'm assuming you meant Null (read: empty) string) as the declaration states "As String"

The only other thing I can think of would be to read the entire file into a string:

hFile = FreeFile
Open MyProject.vbp For Input as #hFile
tProjectFile = Input(LOF(hFile), #hFile)
Close hFile

then extract the stuff you want

iIndex = Instr(tProjectFile, "MajorVer")
If iIndex > 0 Then
    tMajorVer = Mid(tProjectFile, iIndex+9) ' Chars + "="
    iIndex = Instr(tMajorVer, vbCR)
    tMajorVer = left(tMajorVre, iIndex) - 1
End If

though writing this back is a damn sight harder ....



Avatar of GBSW

ASKER

Thanks.  I've actually already tried both null and checking the .vbp (neither worked  8-(.  You'd think this would be easier considering how simple the rest of the VBE is.

Any guesses for other values to try for Section would be welcomed and point worthy.
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial