473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to select randomly Single String from multiple Strings in VB Script

144 100+
Hi Friends,

I am trying in VBScript. I have names "Orange","Red","Blue","Yellow". I need any one of this names to be displayed randomly in MSGBOX. How can I do that. I tried the below code but it is not working. Can you correct it if it is wrong.

Expand|Select|Wrap|Line Numbers
  1.  <html>
  2. <head>
  3. <script type="text/vbscript">
  4.  
  5. Dim first() as String = {"Orange","Red","Blue","Yellow"}
  6. MsgBox(first(Rnd))
  7.  
  8. </script>
  9. </head>
  10. </html>
  11.  
Feb 16 '11 #1
6 2424
yarbrough40
320 100+
the Rnd function only returns a number from 0 to 1. try something like:

Expand|Select|Wrap|Line Numbers
  1. Dim first() As String = {"Orange", "Red", "Blue", "Yellow"}
  2.         Dim random As New Random()
  3.         MsgBox(first(random.Next(4)))
Feb 16 '11 #2
davidson1
144 100+
I tried this below Code..But it is not working..Any other alternate code

[code]

<html>
<head>
<script type="text/vbscript">

Dim first() As String = {"Orange", "Red", "Blue", "Yellow"}
Dim random As New Random()
MsgBox(first(random.Next(4)))

</script>
</head>
</html>

[\CODE]
Feb 16 '11 #3
yarbrough40
320 100+
try
Expand|Select|Wrap|Line Numbers
  1. Dim first() As String = {"Orange", "Red", "Blue", "Yellow"}
  2. Dim Random As Integer = CInt(Int((4 * Rnd()) + 0))
  3. MsgBox(first(Random))
Feb 16 '11 #4
davidson1
144 100+
I tried this below code. But still it is not working. Any other code?

[code]
<html>
<head>
<script type="text/vbscript">
Dim first() As String = {"Orange", "Red", "Blue", "Yellow"}
Dim Random As Integer = CInt(Int((4 * Rnd()) + 0))
MsgBox(first(Random))
</script>
</head>
</html>
[\CODE]
Feb 16 '11 #5
yarbrough40
320 100+
can you be more specific as opposed to just "it's not working"? : ) are you getting compilation errors / runtime errors? if so what do they say?

I am a vb.net guy so you may just need to do some googling for "vbscript random function"
Feb 16 '11 #6
davidson1
144 100+
The message box is not coming with that Random name. It just executes and shows a Blank Page.No Error.
Feb 16 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Maury Markowitz | last post by:
I have a byte returned from a DLL that contains n c-style strings inside it. Any suggestions on how to easily pull them out into a string? Encoding helps with a single byte array (although easily...
4
by: Patrick F | last post by:
how do i select a single node value from the list? ive tried with this, but it dosent work =/ private string FetchFieldFromXml(string strId) {
2
by: John | last post by:
Hi I have an email column in a table. How can I turn values in the column for all records into a single string with each email separated by a ;? Thanks Regards
6
by: HeEm | last post by:
In my 100 level CS course, I was asked to create multiple lines of output within a single string. Of course I know how to: print "I am" print "a python" print "newbie." How can I get this...
1
by: gwigg | last post by:
Hi, I am trying to match multiple strings per line from a file and extract them into an array. Apparently the first match is assigned $1, how do I know what the last match is ie $last?? I would like...
3
by: jc | last post by:
I might be able to do this in t-sql, but is there an easy way to do this in vb.net/ado.net? Say my function looks like this: Public Function GetDataSet(ByVal sql As String) As DataSet If...
3
by: Scott Sharkey | last post by:
Hi All, I have a need to determine whether a passed variable is a single string, or a list of strings. What is the most pythonic way to do this? Thanks. -Scott
4
by: Polarism | last post by:
Hello, I am very new to perl and I am having trouble figuring out how to replace multiple strings in a single file. The file has something around 750k instances that need to be replaced with 350...
4
Markus
by: Markus | last post by:
Hi, guys. I'm receiving a dynamic amount of strings and from these strings I need to make a single string containing them all. However, I need to preserve the NULL characters to separate the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.