English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have this code, created in VB.NET 2005

---
Private Sub frmTestAllRows_Load...
RandomizeLBL(Me, "lblLetter*")
End Sub
---
Private Sub RandomizeLBL...
Dim rnd As New Random
For Each ctrl As Control In container.Controls
Dim lblLetter As Label = TryCast(ctrl, Label)
If lblLetter IsNot Nothing AndAlso lblLetter.Name Like pattern Then
lblLetter.Text = Chr(rnd.Next(97, 122).ToString)
End If
Next
End Sub
---

This works for selecting any chara on the keyboard and putting it into a label when the form is loaded. BUT, is there any way to modify this so that it can only select random letters from, for example, the top row of the keyboard. I was hoping i could modify the ascii code to look for, e.g. 97, 103, 107.

Any ideas?

2007-02-20 10:14:31 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

create a string like:
dim strFirstRow as string="qwertyuop"
it's 9 letters.. now generate a random number from 1 to 9 and then get that letter from your string
something like this
Dim strFirstRow As String = "qwertyuop"
Dim myRND As New Random
Dim iNum As Integer = myRND.Next(1, 9)
MsgBox(strFirstRow.Substring(i... 1))

2007-02-28 03:59:41 · answer #1 · answered by Freddy Krueger 3 · 1 0

well, one solution to this would be.

create a string like:

dim strFirstRow as string="qwertyuop"

it's 9 letters.. now generate a random number from 1 to 9 and then get that letter from your string

something like this

Dim strFirstRow As String = "qwertyuop"
Dim myRND As New Random

Dim iNum As Integer = myRND.Next(1, 9)
MsgBox(strFirstRow.Substring(iNum, 1))

2007-02-21 10:48:30 · answer #2 · answered by Zlavzilla 3 · 0 0

fedest.com, questions and answers