create a random aray for displying a mesage in a label
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Dennis W (VIP)
I want to display a differnt message evry time a button is clicked. so I set
up a aray of ms(12) so that I can asign 12 differnt strings to a labelbut I
get a error . First of all can I asign a string value to a label? Im new to
vb . I 'm still trying to shake the happits of basica or gwbasic trobo basic.
You get the Idea. So can someone get me on the right path here.
--
//Bart//
Reply to this message...
 
    
Tom Shelton
On Tue, 14 Sep 2004 19:33:02 -0700, Dennis W wrote:

[Original message clipped]

Actually, in VB.NET (and VB6 too, unless you had option base 1 set) that
would have 13 items :) But anyway...

Dim ms() as string = {"first", "second", "third", "fourth", "fifth"}
dim rand As new Random()
dim i as integer = rand.next (0, ms.getupperbound(0))

messagebox.show (ms(i))

--
Tom Shelton [MVP]
Reply to this message...
 
    
Chris Dunaway
On Tue, 14 Sep 2004 21:04:29 -0600, Tom Shelton wrote:

[Original message clipped]

Just to point out one thing. The rand.next function that you show will get
a random number from 0 to 3. It does not include the upper bound. You
need to specify ms.getupperbound(0,ms.getupperbound(0) + 1).

From the docs:

Return Value
A 32-bit signed integer greater than or equal to minValue and less than
maxValue; that is, the range of return values includes minValue but not
MaxValue. If minValue equals maxValue, minValue is returned.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Reply to this message...
 
    
Tom Shelton
In article <zbt4opwhpn1v.1j5bkdav5zx97$.Click here to reveal e-mail address>, Chris Dunaway wrote:
[Original message clipped]

Yes, your correct... I always forget that. Actually, an easier
solution, would just to use ms.getupperbound(0, ms.length).

--
Tom Shelton [MVP]
Reply to this message...
 
    
One Handed Man \( OHM - Terry Burns \)
Additionally to Tom's comments, you say you cannot assign to a label?, the
answer is yes

myLabel.Text = "YourString"

or

myLabel.Text = yourArray(index)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Dennis W" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I want to display a differnt message evry time a button is clicked. so I
set
> up a aray of ms(12) so that I can asign 12 differnt strings to a labelbut
I
> get a error . First of all can I asign a string value to a label? Im new
to
> vb . I 'm still trying to shake the happits of basica or gwbasic trobo
basic.
[Original message clipped]

Reply to this message...
 
 
System.Random




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com