Replies: 3 comments
-
based on the answer Mohammad gave me earlier, and assuming I have 5 labels (label1, label2... label5) identified with a certain number at the end of the name, I made this little routine to write to a certain label based on a result. Is there a better or more elegant way to access and write to it? num = Math.GetRandomNumber(5)
Next |
Beta Was this translation helpful? Give feedback.
0 replies
-
For short, you can use:
`If _Label.Name = "Label" & Num Then`
as sVB makes the necessary type conversions.
But here is another version of the code that doesn't require a special naming pattern for labels:
Num = Math.GetRandomNumber(5)
N = 0 ' represents the found label count
ForEach _Label In Me.Controls
If _Label.TypeName = ControlTypes.Label Then
N = N + 1
If N = Num Then
_Label.Text = "ok label - " & Lblnum.Text
_Label.FitContentWidth()
EndIf
EndIf
Next
…________________________________
From: Drugo67 ***@***.***>
Sent: Tuesday, October 22, 2024 3:42 PM
To: VBAndCs/sVB-Small-Visual-Basic ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [VBAndCs/sVB-Small-Visual-Basic] another problem with controls and arrays (Discussion #91)
based on the answer Mohammad gave me earlier, and assuming I have 5 labels (label1, label2... label5) identified with a certain number at the end of the name, I made this little routine to write to a certain label based on a result. Is there a better or more elegant way to access and write to it?
num = Math.GetRandomNumber(5)
ForEach _label In Me.Controls
If _label.Name = "Label" & Text.ToStr(num) Then
_label.Text = "ok label - " & Lblnum.Text
EndIf
Next
—
Reply to this email directly, view it on GitHub<#91 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ALQ5MVVMULRXAEDZMDELWELZ4ZW7TAVCNFSM6AAAAABQIL5QYOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMBRHEYTANY>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank You Mohammad!!! Good to know! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone! I had already asked a question regarding control arrays and in fact I was partially answered but now I have another problem. Being used to the good old VB6 I often used arrays of controls. But with sVB this is not possible, so if I have for example 25 labels on the form (label1, label2... label25) and I had to change the text of only one of them depending on a number (such as math.GetRandomNumber(25)) is there a possibility to do it without doing 25 "If Then" loops? That is, how can I identify a certain label depending on a result? Thanks in Advance
Drugo
Beta Was this translation helpful? Give feedback.
All reactions