473,785 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create a random aray for displying a mesage in a label

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//
Nov 21 '05 #1
4 1401
On Tue, 14 Sep 2004 19:33:02 -0700, Dennis W wrote:
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.


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.getupperboun d(0))

messagebox.show (ms(i))
--
Tom Shelton [MVP]
Nov 21 '05 #2
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" <De*****@discus sions.microsoft .com> wrote in message
news:BD******** *************** ***********@mic rosoft.com...
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//

Nov 21 '05 #3
On Tue, 14 Sep 2004 21:04:29 -0600, Tom Shelton wrote:
On Tue, 14 Sep 2004 19:33:02 -0700, Dennis W wrote:
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.


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.getupperboun d(0))

messagebox.show (ms(i))


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.getupperboun d(0,ms.getupper bound(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_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #4
In article <zb************ *************** **@40tude.net>, Chris Dunaway wrote:
On Tue, 14 Sep 2004 21:04:29 -0600, Tom Shelton wrote:
On Tue, 14 Sep 2004 19:33:02 -0700, Dennis W wrote:
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.


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.getupperboun d(0))

messagebox.show (ms(i))


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.getupperboun d(0,ms.getupper bound(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.


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

--
Tom Shelton [MVP]
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2300
by: Jon Whittlestone | last post by:
hi there. I am getting two > characters and i really can't understand why they are there - see http://www.jonwhittlestone.co.uk/portfolio%20files/wminproperty/landlordAddProperty.php It is driving me mad - here is all the code, sorry it's long I'd appreciate it so much if someone would tell me why i'm getting
5
11026
by: John Morgan | last post by:
In a 'Top n' type statement I wish to be able to insert the n value from a parameter, within a stored precedure eg Having declared @pageSize as a parameter I want to run the following type of query : SELECT DISTINCT TOP @pageSize routeID, routeName FROM tblRoute_Header When I attempt to do so I get an error mesage indicating incorrect
23
4204
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you initialize it with the same parameter. Can this be done with JavaScript? I couldn't find anything in the documentation. Basically, what I want to achieve is to obtain always the same sequence of random numbers for the same given initialization...
5
2194
by: Haydnw | last post by:
Hi, I have the code below as code-behind for a page which displays two images. My problem is with the second bit of code, commented as " 'Portfolio image section". Basically, the SQL query gets details of a random image from an access database. I know this works because when I run the query in access, it picks a different image each time (or close enough). However, when I view the .aspx page that this code-behind is for, it always picks...
0
1333
by: XML newbie: Urgent pls help! | last post by:
Hi, I am getting the error: Value of type 'String' cannot be converted to '1-dimensional array of Long'. in the following line for TextBox2.Text field : doc.LoadXml(EDP.ExportPositions(TextBox1.Text, cmbStartDateandTime.SelectedText, cmbEndDateandTime.SelectedText, TextBox2.Text)))
7
3243
by: Roemer | last post by:
Hi all I stumbled over a new problem: I have a programm with just a class that is asynchronous listening for network connections. As soon as someone connected, a new form needs to be created. The Form gets created but hangs after creation. I'ts logical that that happens because the new Form doesn't get a Message Loop. The Message Loop is created on Application.Run() on the Main Method on the Main Thread. The Callback is (normally)...
1
5717
by: ohagna | last post by:
in oracle form devoloper i tray to connect but get this error mesage : error mesage NO ORA12636 please what that mean ? ?
1
1396
by: Aray | last post by:
There were some different type elements. each of the type has arbitary amount of Elements, and all those Elements is in ramdon order, How Can I write the Schema file?
0
912
by: sweatha | last post by:
Hi Friends I have designed a form with a label box named 'Label30' and text box named 'TextBox21'. Then I have generated the random number in the label box using the coding in form load event as Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here str = "user id=sa;password=;data source=AURO-RA4;initial...
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.