Variable 'Random Number' is used before it has been assigned a value.
Variable 'RandomNumber' is used before it has been assigned a value. A new reference exception could result at runtime.
Code:
Code:
Sub RandomizeConLandLaunch(ByRef con As Integer)
Dim RandomNumber(,) As Integer
ConLandLaunch(con) = RandomNumber(1, 30000)
End Sub
what should i do ?
Re: Variable 'Random Number' is used before it has been assigned a value.
Have you run that code?... what happen when you do?
Re: Variable 'Random Number' is used before it has been assigned a value.
Have you run that code?... what happen when you do?
this line
Code:
Dim RandomNumber(,) As Integer
creates a 2 dimensional array of integers, but since you did not supply values to indicate the size of the array, the array does not exist. When you do this...
Code:
ConLandLaunch(con) = RandomNumber(1, 30000)
you are assigning the value that resides at the 1,30000 position of the RandomNumber array, but that value does not exist, so your code will (should) error
What are you trying to do?
Re: Variable 'Random Number' is used before it has been assigned a value.
> What are you trying to do?
----------------------------
Fix that warning out...?
Re: Variable 'Random Number' is used before it has been assigned a value.
Quote:
Originally Posted by
kebo
this line
Code:
Dim RandomNumber(,) As Integer
creates a 2 dimensional array of integers
Actually it doesn't, and that's the problem. Your implication is correct but your terminology is not. That code just declares a variable that CAN refer to an array but it doesn't actually create any array. As such the variable is Nothing, i.e. it doesn't refer to an object. Variables and objects are two different things. Variables are declared and objects are created.
Re: Variable 'Random Number' is used before it has been assigned a value.
Unless I'm mistaken, it looks like you are trying to get a random value between 1 and 30000. If that's the case, then use an instance of the Random class and call Next.
Re: Variable 'Random Number' is used before it has been assigned a value.
Quote:
Originally Posted by
jmcilhinney
Actually it doesn't, and that's the problem. Your implication is correct but your terminology is not. That code just declares a variable that CAN refer to an array but it doesn't actually create any array. As such the variable is Nothing, i.e. it doesn't refer to an object. Variables and objects are two different things. Variables are declared and objects are created.
thanks for the clarification
Re: Variable 'Random Number' is used before it has been assigned a value.
I asking, because i got "1 WEEK OF EXPERIENCE" in VB 6.0, but i really didn't like VB 6.0, so i try to fix the code by the very useful help of "VBUC", from VB 6.0 to Microsoft Visual Studio 2008.
Now the code are "fixed", but not at 100% ..
I got this warning and just ask how to fix it..
If any1 knows, just post:
------------------------
Dude, your code:
IS WRONG ..
You have to change it like this:
Im absolute beginner, so i need really basic explanation =))
Thanks.
Re: Variable 'Random Number' is used before it has been assigned a value.
The first thing you need to answer is what you are trying to do, and I don't mean 'get rid of the warning'. Are you trying to generate a random number? Do you actually want a multi-dimensional array of that length?