.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification