473,379 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Can I combine a Type with a variable?

Hi,

I am taking a beginning VB.Net class and I have a project where I need to check the text of 16 buttons. I can easily do this with If Then statements but I am curious if I could do this by running a For Next loop. Here is the code I have tried:

Expand|Select|Wrap|Line Numbers
  1. Dim btn As Integer
  2. Dim x As String
  3.  
  4.         For btn = 1 To 16
  5.             x = btn
  6.             If Button(x).text = "" Then
  7.                 MsgBox("Everything appears correct except you still have blanks in the puzzle.")
  8.             End If
  9.         Next btn
Unfortunately, I get the following error: 'Button' is a type and cannot be used as an expression.

Can anyone please help a noob and guide me in the right direction? Thanks!
Jul 23 '07 #1
1 1030
Killer42
8,435 Expert 8TB
Hi sinnatra.

This is one case where M$ appear to have taken a big step backward (though presumably they had their reasons).

In VB6 (pre-.Net version, about 9-10 years old) you can just define the controls as a control array. So if your control name was called Button1, for instance, you could refer to the elements of the array as Button1(x).

In VB.Net apparently they have removed this capability. But there are ways to simulate it, or work around the limitation. There is a Controls collection, which I think exists in both VB6 and later versions. You reference the members by name. For example Form1.Controls("Button1"). The implication of this is that you can get close to the functionality of a control array by dynamically building the name in the string. For example, to access a bunch of buttons called Button1 through Button10, you might do something like this (keeping in mind I only know VB6 syntax)...
Expand|Select|Wrap|Line Numbers
  1. Dim I As Long
  2. Dim CtlName As String
  3. For I = 1 to 10
  4.   CtlName = "Button" & Format(I)
  5.   Debug.Print CtlName ; " : "; Form1.Controls(CtlName).Caption
  6. Next
  7.  
If you search through the discussions which have taken place on this topic at TheScripts, you'll also find that I proposed an alternative method some months back, involving the creation of an array in code to represent the controls on the form. I haven't had a chance yet to flesh it out and write it up in the Articles section (assuming it works out). I'm hoping to do so within the next week or two, but things are pretty busy.

Ahah! Found it. Just in case you're interested, here is a link to the original discussion during which I proposed the alternative method.
Jul 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Dave | last post by:
Hello, I'm a somewhat PHP newbie, so please bear with me. Here is what I am trying to do: $foobar = "blah blah"; $a = "foo"; $b = "bar"; $fooboo = "$a" . "$b"; echo $fooboo
5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
3
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
6
by: Gabriel Zachmann | last post by:
Is there a way to combine doxygen comments, like this one ## Documentation for a function. # @var a - variable # More details. def func( a ): pass
3
by: Schroeder, AJ | last post by:
Hello group, I am a relative PHP newbie and I am trying to combine two arrays together, but I also need to keep the keys of one array intact. What I am doing is two SNMP walks against a Cisco...
2
by: niskin | last post by:
Hi I want to combine these variables: char computera; //this variable contains input from the user char path= "\\\\"; char location = "\\C$\\Windows\\System32\\chat.txt"; The order I want...
1
by: David C | last post by:
I have a DataList that displays photos and is bound to a list of files. Is there a way to combine the value of a variable (strpath) with the # Bind(...) in the ImageURL field. Below is what I...
2
denny1824
by: denny1824 | last post by:
Hi everyone, Here is my problem. I have a Table Variable (I could easily turn it into a Temp Table instead) that will sometimes have rows that are identical except for one specific column. The...
3
by: fjm | last post by:
I have one jquery function that submits data via a datastring to my server. This works great. On success, I currently have a little alert box that lets the user know that the data was stored. I...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.