Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi
I have this code

VB
Dim time As New Random()
Dim number As Integer = Random(Label1, Label2)


However i get

'Random' is a type an cannot be used as an expression :(

any suggestions please how i can sort this please.
Posted

1 solution

IF you read the documentation youll find something like this:
http://msdn.microsoft.com/en-us/library/system.random.aspx[^]

And the code:
Dim bytes1(99), bytes2(99) As Byte 
Dim rnd1 As New Random()
Dim rnd2 As New Random()

rnd1.NextBytes(bytes1)
rnd2.NextBytes(bytes2)

Console.WriteLine("First Series:")
For ctr As Integer = bytes1.GetLowerBound(0) to bytes1.GetUpperBound(0)
   Console.Write("{0, 5}", bytes1(ctr))
   If (ctr + 1) Mod 10 = 0 Then Console.WriteLine()
Next 
Console.WriteLine()
Console.WriteLine("Second Series:")        
For ctr As Integer = bytes2.GetLowerBound(0) to bytes2.GetUpperBound(0)
   Console.Write("{0, 5}", bytes2(ctr))
   If (ctr + 1) Mod 10 = 0 Then Console.WriteLine()
Next  

Trick is to use the Random.Next etc.
 
Share this answer
 
Comments
[no name] 23-May-13 12:58pm    
could i use this instead?

Dim number As Integer = Random.Equals(Label1, Label 2)
Sergey Alexandrovich Kryukov 23-May-13 13:00pm    
Sure, 5ed.
—SA
[no name] 23-May-13 13:05pm    
ok slightly off topic but i am now trying to display the variable 'number' in a label and i have this code

label11.Text = Convert.ToString(number)

and it just doesnt do anything any suggestions please
Sergey Alexandrovich Kryukov 23-May-13 13:18pm    
string someText = number.ToString(); or
string someText = number.ToString(formatString); /...
—SA
Dave Kreskowiak 23-May-13 13:27pm    
You REALLY need to stop what you're doing and pickup a beginners book on VB.NET and work through it. You're missing or misunderstanding so many core concepts that it's nearly impossible for anyone to post the simplest code with the assumption that you would understand what it's doing and why.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900