473,396 Members | 1,891 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,396 software developers and data experts.

select label dynamically

Hi All

I have an app that has 64 labels and an array with 64 members. I'm using a
ranom generator to pick a number and put it in the array but then I need to
alter the text of the corresponding label.

So far I've been unable to get the correct label selected based on the
number generated. I'm new to programming so apologies if this is a simple
task, I'd appreciatea point in the right direction.

e.g. of what I'm trying to do:

Dim var1, var2, var3 As Label
Dim i As Short = CInt(Int((4 * Rnd()) + 1))

var(i).Text = "X"

Is this possible to get this working?

TIA
gr

Aug 3 '08 #1
3 1457

"gerryR" <ge****@noSPAM.comkirjoitti viestissä
news:uv**************@TK2MSFTNGP04.phx.gbl...
Hi All

I have an app that has 64 labels and an array with 64 members. I'm using
a ranom generator to pick a number and put it in the array but then I need
to alter the text of the corresponding label.
If you have those labels created in design mode, you could try this:

Dim RandomNumber As New Random
Dim LabelArray As Label() = {Label1, Label2, Label3, Label4}
LabelArray(RandomNumber.Next(0, 3)).Text = "X"

-Teemu

Aug 3 '08 #2

"gerryR" <ge****@noSPAM.comwrote in message
news:uv**************@TK2MSFTNGP04.phx.gbl...
Hi All

I have an app that has 64 labels and an array with 64 members. I'm using
a ranom generator to pick a number and put it in the array but then I need
to alter the text of the corresponding label.

So far I've been unable to get the correct label selected based on the
number generated. I'm new to programming so apologies if this is a simple
task, I'd appreciatea point in the right direction.

e.g. of what I'm trying to do:

Dim var1, var2, var3 As Label
Dim i As Short = CInt(Int((4 * Rnd()) + 1))

var(i).Text = "X"

Is this possible to get this working?

TIA
gr
Yes, it's possible to get it working. You'll have to learn a bit of
programming first. The example code you posted does not compile because you
are using "var" as an array but you haven't defined an array named "var" -
you may think of var1, var2 and var3 as an array but VB.Net does not. If
you change your "Dim var1, var2, var3 As Label" statement to "Dim var(63) as
Label" then you will at least have code which compiles. Note that since
subscripts in VB.Net start at 0, not 1, var(63) does provide an array of 64
elements.

With that change your code will compile but will still not execute, i.e. it
will "throw an exception". I could tell you why but I don't want to deprive
you of a great learning experience. Really. You will learn programming only
by making many mistakes and figuring them out. But here's some information
you'll need before you get this code working. "Dim var(63) as Label" does
not create 64 Labels. It creates 64 REFERENCES TO Labels. You'll have to
actually create a Label before you can set its Text property.

Bob
>

Aug 3 '08 #3
Little addictions.

It creates 64 labels because to keep it compatible with VB versions before
VB6. This was the result of intensive lobying from VB6 developpers. You can
now use the zero as start of an index and the first (like VB6) as start of
an index.

(One of the most confusing and stupid things in VB in my idea).

Cor

Aug 4 '08 #4

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

Similar topics

1
by: JT | last post by:
I have an input form for which I've created a "matrix" for user input. Basically, the user chooses a radio button and then through javascript, a select box is displayed to define a value for that...
4
by: point | last post by:
Hello there... I'm a PHP programmer and starting to learn JS... I have a following problem.... I have 3 select boxes! one is hotel one is destination and one is country... if someone...
5
by: cedawe | last post by:
I have two select boxes. When the user picks a value in the first one it completely re-populates the second one. It works fine, but only generates a standard OPTIONS list and I now want to group...
3
by: Stewart | last post by:
Dear comp.lang.javascript, I have more than once wanted to manipulate the contents of select boxes dynamically, whilst the boxes contain <optgroup> tags. Manipulation of a select box containing...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
2
by: BB | last post by:
Hello, I have a HTML form containing multidimensional selects listing equipments and their quantitites. This allow the users to select the kind of equipment and quantitites they would like to...
0
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select...
4
by: Patrick Nolan | last post by:
I am using javascript to manipulate optgroups in select elements. When the results are displayed in Firefox 2.0 there is an annoying blank line at the top of the multi-line select box. This...
3
by: Ronald S. Cook | last post by:
I would like to put a label (or any control) on a webform all from the code. I.e. something like this: protected void Page_Load(object sender, EventArgs e) { Label TestLabel = new Label();...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.