Re: VBA user, first time on Vbasic. Need help referencing a control
- From: "Scott M." <s-mar@xxxxxxxxxxxxx>
- Date: Thu, 11 Oct 2007 11:22:38 -0400
Hi Adam,
Your approach *can* work, but you are still using legacy VB 6 techniques,
rather than a .NET OO approach with the use of the "right()" function. In
..NET, most of the VB 6 functions have been replaced with a more OO way of
doing things.
When you refer to: ctrl.Name, you are getting back a String object and
String objects (like any other object) have properties and methods. Using
these properties and methods, you can extract any portion of a string you
need to.
Will the .NET approach require more code compared to the VB 6 approach which
you have learned and are already comfortable with? Yes, and this makes
using VB .NET counter-intuitive and cumbersome at first, but once you make
the mental "leap" to OOP (VB 6 was NOT OOP!), you begin to understand how
much more sense your code makes and how much more powerfull you can be as a
programmer.
Using this OO approach, if the lables you need to find will always be the
same group, why not put them all into a collection object early on in your
code, then you could just loop through your collection, rather than
me.controls and you wouldn't have to test to see if they are the ones you
want. This would give you comprable results to a VB 6 control array.
-Scott
<adam_kroger@xxxxxxxxxxx> wrote in message
news:1192102002.373378.186350@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Scott:
Thank you for your answer. Unfortunately that method won't solve all
my difficulties. In addition to the Masked TextBoxes I also need to
be able to find 31 Labels out of 55 and alter their .Text value. The
controls that need to be altered all have the same naming convention
<NAME># where <NAME> would be one of the followinng (LIS, ENRS, ENRE,
ESS, ESE, DAYS, MONTHS, or GAP). would something like this work
(though it seems inefficient):
dim ctrl as control, i as integer
for i = 1 to 6
for each ctrl in me.controls
if right(ctrl.name, 1) = i then
ctrl.txt = ""
endif
next
next
Is there not a way to locate the control without having to loop
through every control on the form, every time? Your right I am goinng
to have to unlearn severral thought processes, this seems like it
should be such a simple task, to programicly determine which control
needs to be accessed and then do so.
On Oct 10, 11:43 pm, "Scott M." <s-...@xxxxxxxxxxxxx> wrote:
<<snip>>
There are advanced ways of making your code work using the same concept as
what you are trying here, but why not just go down an eaiser path:
Dim myTextBox As Textbox
For Each myTextBox In Me.Controls
myTextBox.Text = ""
Next
Also, notice that I'm not trying to access the data in the Textbox via
the
"value" property? That's becaue, in VBA and in .NET, textboxes have a
Text
property (as do pretty much everything that displays text (labels,
buttons,
etc.) - - The "caption" property is gone. The only time you'd use
"value"
is in client-side code referring to HTML form fields.
Good luck & stick with it - - .NET is worth the time it takes to
understand
it. Just remember that you'll need to "unlearn" much of what you have
learned!
-Scott
<adam_kro...@xxxxxxxxxxx> wrote in message
news:1192073166.994164.300130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<<<SNIP>>>
MORE DETAILED EXPLANATION ON PROJECT:
The program determines the gaps between dates and gives the results in
months. The interface has 22 Masked TextBoxes (forcing Date entries)
in groupings of 6,5,5,2,2 and 2 singles, also 31 Labels (for reporting
results) in groups of 5 + 1 for the total; using naming conventions as
specified above. I need to be able to cycle through them to either
read the data into array variables for manipulations and comparisons,
or to "reset" them to blank. I could probably get by on this project
with naming them absolutely, but in my next project, it won't be
anywhere near as straightforward.- Hide quoted text -
- Show quoted text -
.
- References:
- VBA user, first time on Vbasic. Need help referencing a control
- From: adam_kroger
- Re: VBA user, first time on Vbasic. Need help referencing a control
- From: Scott M.
- Re: VBA user, first time on Vbasic. Need help referencing a control
- From: adam_kroger
- VBA user, first time on Vbasic. Need help referencing a control
- Prev by Date: Which VB.NET books do you recommend??? (was 'Transitioning from VB6 to VB.Net')
- Next by Date: Re: Pass parameter to a delegate
- Previous by thread: Re: VBA user, first time on Vbasic. Need help referencing a control
- Next by thread: add control onto ToolBox palette
- Index(es):