473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA user, first time on Vbasic. Need help referencing a control

BRIEF EXPLANATION:
I have 6 TextBoxes named LIS1, LIS2, LIS3, ... LIS6. I want to be
able to reference them using a For/Next loop and either read ot write
to them. In VBA I would use something like this:
for i = 1 to 6
me.controls("LI S" & i).Value = ""
next i

Nedless to say, the Controls("LIS" & i).text doesn't work...

What do I need to do differently?

ALSO, in VBA if I wanted an expression to be resolved before being
addressed by the rest of the line I could enclose it in [ ] or use
evaluate(). Is there something similar in VBasic, or is this limited
to script based languages?

I am trying to turn processes I have written in Excel using VBA and
UserForms into stand-alone programs. I am using VisualBasic 2005
Express Edition.

---

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 .

Oct 11 '07 #1
4 1892
Adam,

Will you first give us an impression what you mean by Vbasic, it does not
exist like that. I assume you mean a Visual Basic variant, however for that
there are even more variants then for the C language.

The answer on your question is in fact yes, however it is by instance in
Visual Basic for Net completeley different from Visual Basic 6.

The best newsgroup for the first is:
news:\\Microsof t.public.VB.gen eral.discussion s

While for the latter it is:
news:\\Microsof t.public.dotnet .languages.vb

Cor

Oct 11 '07 #2
First, you must understand that VB .NET is not just "the new version of VB
6". It is entirely new and opererates very differently from the VB of days
gone by. Also, just to get your terminology right, VBA is not a scripting
language, VBScript is.

The reason your attempt doesn't work is because in .NET, it's all about
"types", so this code:

("LIS" & i)

would be processed as the String type, who's variable pointer is "LIS"
should be concatenated with the Integer type, who's variable is 1 - 6 (based
on your code).

Well, you probably don't have a string variable called "LIS" and
concatenating (which, by definition is for String types), it with a number,
would return a new String type reference called, say, "LIS1", now you do
have a Textbox type with a variable of "LIS1", but you don't have a String
with a variable of "LIS1", so your code fails. Even if you did happen to
have a String type with a variable of "LIS1", strings don't have a .value
property, so the rest of your code would cause the line to fail.

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
<ad*********@ho tmail.comwrote in message
news:11******** **************@ o80g2000hse.goo glegroups.com.. .
BRIEF EXPLANATION:
I have 6 TextBoxes named LIS1, LIS2, LIS3, ... LIS6. I want to be
able to reference them using a For/Next loop and either read ot write
to them. In VBA I would use something like this:
for i = 1 to 6
me.controls("LI S" & i).Value = ""
next i

Nedless to say, the Controls("LIS" & i).text doesn't work...

What do I need to do differently?

ALSO, in VBA if I wanted an expression to be resolved before being
addressed by the rest of the line I could enclose it in [ ] or use
evaluate(). Is there something similar in VBasic, or is this limited
to script based languages?

I am trying to turn processes I have written in Excel using VBA and
UserForms into stand-alone programs. I am using VisualBasic 2005
Express Edition.

---

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 .


Oct 11 '07 #3
Just a correction...
("LIS" & i)

would be processed as the String literal type, who's value is "LIS"
should be concatenated with an Integer type, who's variable is 1 - 6
(based
on your code).

Oct 11 '07 #4
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 <NAMEwould 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-...@nospam.nosp amwrote:

<<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...@ho tmail.comwrote in message

news:11******** **************@ o80g2000hse.goo glegroups.com.. .
<<<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 -

Oct 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1798
by: badz | last post by:
Hi there I have one problem regarding broken image.. The problem is quite mystery.. It's happen to other user pc only (the page that we browse reside at the same server)..not at my pc.. it never happen.. When other user go to the url. the face the broken image at the first time and need to refresh their browser .. in order to see the image..
1
7585
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
3
1543
by: Philip Poole | last post by:
Hello everyone, Please help with this as it is driving me up the wall and it is urgent i finish this page, this is the first time I have used User Controls and I think I must have completly misunderstood a basic point. I have a number of user controls which are used to make up my page. One control is a series of tabs which are created dynamically from a database. When someone clicks on a tab, the page reloads and the tabs that was...
2
2495
by: Alan Silver | last post by:
Hello, I'm having rather a problem with user control. It is a fairly simple affair (see my other threads for more details) that shows a date and time in five drop down controls. I had private member variables for the day, month, year, hour and minute, and the public property that sets the DateTime simply stored the relevant numbers in these variables.
16
2600
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a gradual upgrade of my web programming skills from Classic ASP / VBS to ASP.NET / VB.NET. While the study of the language differences and all the new features in .NET has so far not been a traumatic experience, I am a bit shell-schocked after
0
1319
by: Lucas Tam | last post by:
Hi all, I am dynamically loading user controls after a postback. Within the User Control, how do I check if it is being loaded for the first time? With a regular ASPX page I can check If Not Page.IsPostback, however, since these controls are loaded AFTER postback, this won't work. I tried using Viewstate, but since I'm swapping multiple controls, I'll
3
1811
by: PKin via DotNetMonster.com | last post by:
Hi, I have a web page with a radioButtonList with 3 buttons (B1,B2 and B3) and a placeholder. B1 will put an .ascx file (Pl1.ascx) in the placeHolder, B2 will do the same with Pl2.ascx and B3 with Pl3.ascx. Each .ascx file has controls that can fire som events(button, dropList...). When I start the page, B1 is default and every control on Pl1.ascx work very fine. When I choose B2 or B3 the .ascx file is loaded in the placeholder but no...
2
2288
by: majestic12 | last post by:
This is the first time I've tried to use mysql/phpmyadmin and I'm having trouble. I'm using a geocites pro account and I got both installed and it set up a database call mysql and the user yroot. It asked me to make my own user name, which I did, and had me create a password as well. When I went into phpMyadmin I was able to create a new database but I cant really do anything with it. When I go into privileges I get this warning: Warning:...
3
5399
by: rajkpy | last post by:
Please note: I am urgently in need of a solution to this question, for that i have posted this question in different forums so that i can get an answer as quickly as possibly. Please accept my apologies for any inconvenience caused. Hi experts, I have a application which consists of a login page and other application specific php file. At present the users are able to access the application files directly through the url. Now I want to...
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.