[python-win32] More VisualBasic

Speers, Ted Ted.Speers at actel.com
Wed Feb 8 20:28:16 CET 2006


 
Thanks for everyone's help with my initial volley of questions.  

I'm sure I'm destined to be a consumer of versus a contributor to this
group's output.

I'd like to get some advice from the group whether I should pursue the
road I'm on ... An appeal to your experience and intuition rather than a
specific question.  Sorry if it is longwinded ... It's a 4 parter
('Punchline:', 'Some background:', 'Where I am:', 'Continuing on:') ...
The punchline is what I'm after from this group, the rest of the stuff
may help you/motivate you to form an answer.

Punchline:

Am I on a fools errand trying to develop an application in Python that
manipulates VBUserForms?  Are these errors that I'm seeing going to be
the bane of my existence due to some inherent flakiness or, through
experience/reading/discussiongroups/magic, will I be able to gain enough
understanding of how things work so that I can consistently avoid these
pitfalls?

Some background:  

I was able to go from knowing nothing about python and win32com to
creating a fairly complex application (which entailed parsing data in
Excel worksheets into a web of classes and then outputting multiple
scenarios back into worksheets) in a matter of a few weeks.  

I then decided that I wanted my worksheet to be more interactive and
dynamic.  I investigated various GUI options with Python and nothing
seemed straightforward so I bought John Walker's book on Excel
programming (BTW, I didn't need a book to accomplish my original Python
goal in two weeks).

For whatever reason, I was much less productive with Visual Basic ...
Getting hammered with type errors and other frustrations.  The whole
time I was thinking how easy it would be to do what I wanted to do with
Python.  I ended up writing Visual Basic classes for things such as
Lists and use them heavily but I'm sure they drag down the performance
of my application which is an issue.

It took months to get my application hammered into anything usable
though fortunately, it was ready in time for me to use it and I think
the work paid off.

I now have a lull and know I could recreate my months of effort in  a
week using Python provided I had  stable/predictable hooks to my
VisualBasic widgets and then be able to improve and maintain my
application much more productively going forward.

Where I am:

I used the help of this group to be able to read and manipulate my
Visual Basic UserForms.  However, knowing almost nothing about the man
behind the curtain, my experience is that what I'm doing is somehow
unstable.  For example, at times my program successfully reads and sets
a Userform Control property ... But bombs occasionally ... Try to follow
this or skip to the punchline:

VBComponents=win32com.client.Dispatch("Excel.Application").Workbooks("my
Book").VBProject.VBComponents

For tmp in VBComponents:
 	VBComponentsDict[tmp.Name]=tmp

MyUserForm=VBComponentsDict['MyUserForm']

For tmp in MyUserForm.Properties:
	MyUserFormPropertiesDict[tmp.Name]=tmp   

--- This appears unstable and sometimes gives me a "pythoncom.com_error"
which I don't know how to except.  I can then go to my VisualBasic
editor and double click on the Userform in the VBAProject window and the
code snippet magically works without the "com_error".  I tried
MyUserForm.Activate which seemed to make things better but the problem
has returned.

Continuing on:

MyUserFormControls=MyUserFormPropertiesDict["Controls"]

For tmp in MyUserFormControls.Object:
	MyUserFormControlsDict[tmp.Name]=tmp

--- I've observed this expression to come up with nothing at times in a
manner that I can't predict ... The .Object is reported as
"non-iterable"

MyUserFormControlsDict['MyControl'].<propertyname>=whatever



Thanks


This information contained or attached to this e-mail may be subject to the Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR) and may require an approved export license prior to its export.  An export can include a release or disclosure to a foreign national inside or outside the United States.  Include this notice with any reproduced portion of this information.


More information about the Python-win32 mailing list