Click here to Skip to main content
15,892,059 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Random letters Pin
harveyhanson6-Feb-07 6:32
harveyhanson6-Feb-07 6:32 
AnswerRe: Random letters Pin
Are Jay6-Feb-07 6:47
Are Jay6-Feb-07 6:47 
GeneralRe: Random letters Pin
harveyhanson6-Feb-07 6:51
harveyhanson6-Feb-07 6:51 
AnswerRe: Random letters Pin
Guffa6-Feb-07 7:38
Guffa6-Feb-07 7:38 
GeneralRe: Random letters Pin
harveyhanson6-Feb-07 8:41
harveyhanson6-Feb-07 8:41 
GeneralRe: Random letters Pin
Christian Graus6-Feb-07 9:39
protectorChristian Graus6-Feb-07 9:39 
GeneralRe: Random letters Pin
Guffa6-Feb-07 10:33
Guffa6-Feb-07 10:33 
GeneralRe: Random letters [modified] Pin
TwoFaced6-Feb-07 12:17
TwoFaced6-Feb-07 12:17 
Just create a function that returns a random letter. You should do this.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    label1.text = RandomLetter()
    label2.text = RandomLetter()
    '...
End Sub

Dim rnd As New Random
Private Function RandomLetter() As String
    Return Chr(rnd.Next(97, 123)).ToString
End Function
Or if you want to dynamically find each label and assign it a random letter use this:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    RandomizeLabels(Me, "Label*")
End Sub

'---Assigns a random letter to each label who's name matches the given pattern---
Dim rnd As New Random
Private Sub RandomizeLabels(ByVal container As Control, ByVal pattern As String)
    For Each ctrl As Control In container.Controls
        Dim lbl As Label = TryCast(ctrl, Label)
        If lbl IsNot Nothing AndAlso lbl.Name Like pattern Then
            lbl.Text = Chr(rnd.Next(97, 123)).ToString
        End If
    Next
End Sub
The above code assumes the labels are on your form and not in another container like a panel. If they are then instead of passing 'me' you should pass the container control like 'panel1'. Also the pattern can be anything. Just give your labels a consistent name such as lblRandom1, lblRandom2...and use a pattern of "lblRandom*".


-- modified at 17:52 Sunday 18th February, 2007
GeneralRe: Random letters Pin
harveyhanson18-Feb-07 11:40
harveyhanson18-Feb-07 11:40 
GeneralRe: Random letters Pin
TwoFaced18-Feb-07 11:47
TwoFaced18-Feb-07 11:47 
GeneralRe: Random letters Pin
harveyhanson18-Feb-07 12:01
harveyhanson18-Feb-07 12:01 
GeneralRe: Random letters Pin
TwoFaced18-Feb-07 19:28
TwoFaced18-Feb-07 19:28 
QuestionDisplay Pin
Misanthropia6-Feb-07 5:53
Misanthropia6-Feb-07 5:53 
AnswerRe: Display Pin
Christian Graus6-Feb-07 9:42
protectorChristian Graus6-Feb-07 9:42 
QuestionListView Pin
CodingYoshi6-Feb-07 4:40
CodingYoshi6-Feb-07 4:40 
AnswerRe: ListView Pin
TwoFaced6-Feb-07 7:20
TwoFaced6-Feb-07 7:20 
GeneralRe: ListView Pin
CodingYoshi6-Feb-07 14:36
CodingYoshi6-Feb-07 14:36 
GeneralRe: ListView Pin
TwoFaced6-Feb-07 16:34
TwoFaced6-Feb-07 16:34 
Questiondelay ? Pin
Narfix6-Feb-07 4:26
professionalNarfix6-Feb-07 4:26 
QuestionHow can i make an installable file...? Pin
fmlove6-Feb-07 4:10
fmlove6-Feb-07 4:10 
AnswerRe: How can i make an installable file...? Pin
Taylor Kobani6-Feb-07 5:21
Taylor Kobani6-Feb-07 5:21 
AnswerRe: How can i make an installable file...? Pin
FeRtoll6-Feb-07 6:21
FeRtoll6-Feb-07 6:21 
GeneralRe: How can i make an installable file...? Pin
fmlove6-Feb-07 22:46
fmlove6-Feb-07 22:46 
GeneralRe: How can i make an installable file...? Pin
FeRtoll7-Feb-07 2:53
FeRtoll7-Feb-07 2:53 
QuestionHow can i make an installable file...? Pin
fmlove6-Feb-07 4:10
fmlove6-Feb-07 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.