|
-
Feb 15th, 2001, 11:06 AM
#1
I have 96 blank labels on my form.
(label106 to lable201).
I want to use arrays to generate numbers to be randomly filled in these labels.
How can I go about doing this.
Thank you.
-
Feb 15th, 2001, 11:14 AM
#2
Retired VBF Adm1nistrator
Well, you shouldnt have the labels named like that.
They should be label(106) to label(201).
To fill with random numbers do :
Code:
Dim i As Long
For i = 0 to 95
Label(106 + i).Caption = Rnd
Next i
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 15th, 2001, 11:14 AM
#3
Retired VBF Adm1nistrator
Well a faster loop would be this I'd imagine :
Code:
Dim i As Long
For i = 106 to 201
Label(i).Caption = Rnd
Next i
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 15th, 2001, 11:18 AM
#4
Addicted Member
First, i think you will ither have to delete all of your label controls, copy one of them and paste it, answering YES to the popup box, asking about making a control array.
the other way i think would to rename them all... and make them into an array manualy that way,
dunno tho.... im probly missing an easyer meathod, but thats the only way ive known
then you would just go ......
Const LowNumber = 1
Const HighNumber = 50
Private Sub Command1_Click()
For i = 1 To 96
Label(i).Caption = Int((HighNumber - LowNumber + 1) * Rnd + LowNumber)
Next
End Sub
-
Feb 15th, 2001, 11:20 AM
#5
Addicted Member
err... change the line
For i = 1 To 96
to
For i = 0 To 95
arrays start at 0 :P
-
Feb 15th, 2001, 11:22 AM
#6
Retired VBF Adm1nistrator
You should convert (via renaming or deleting or whatever) all of the labels, and make a control array.
But there is another way.
If you use the scripting control, it allows you to add arbitrary code to your app at runtime.
So you could actually do something like :
"Label" & (106 + i) & ".Caption = Rnd"
Then you'd execute the code at runtime, and it'd work.
Trust me 
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 15th, 2001, 11:22 AM
#7
Hi,
Thanks but how do I get it to print the values on the form in each of the labels.
The form just has labels on it and I need numbers to be displayed on the labels.
the labels are named label106 all the way to label206.
thank you.
-
Feb 15th, 2001, 11:24 AM
#8
Retired VBF Adm1nistrator
Originally posted by Ph34R
err... change the line
For i = 1 To 96
to
For i = 0 To 95
arrays start at 0 :P
This one doesnt 
Code:
Dim var_string(25 To 100) As String
Dim i As Long
For i = 25 To 100
var_string(i) = "osajdoiasjosdiaj"
Next i
God I'm really annoying arent I 
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 15th, 2001, 11:25 AM
#9
Retired VBF Adm1nistrator
Shu.
Delete all of your labels.
Add a new label.
Copy and paste it.
Allow it to use a control array.
The use our code.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 15th, 2001, 11:30 AM
#10
plenderj,
I can't create a control array for my labels because this is just part of my application and I need the labels to be seperate.
Isn't there any way that I could display blank labels on a form with with random numbers.
thank you.
-
Feb 15th, 2001, 11:35 AM
#11
Retired VBF Adm1nistrator
Well yeah, you could just simply do this :
Code:
Label106.Caption = Rnd
Label107.Caption = Rnd
Label108.Caption = Rnd
Label109.Caption = Rnd
Label110.Caption = Rnd
Label111.Caption = Rnd
Label112.Caption = Rnd
Label113.Caption = Rnd
'...
Label201.Caption = Rnd
Except a control array would be much slicker.
Also, as I said you could use the microsoft scripting engine, but thats another story.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|