|
-
Aug 25th, 2009, 08:19 PM
#1
Thread Starter
New Member
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 ?
-
Aug 25th, 2009, 08:25 PM
#2
Re: Variable 'Random Number' is used before it has been assigned a value.
Have you run that code?... what happen when you do?
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 25th, 2009, 08:29 PM
#3
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?
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 25th, 2009, 08:34 PM
#4
Thread Starter
New Member
Re: Variable 'Random Number' is used before it has been assigned a value.
> What are you trying to do?
----------------------------
Fix that warning out...?
-
Aug 25th, 2009, 08:34 PM
#5
Re: Variable 'Random Number' is used before it has been assigned a value.
 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.
-
Aug 25th, 2009, 08:35 PM
#6
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.
-
Aug 25th, 2009, 08:37 PM
#7
Re: Variable 'Random Number' is used before it has been assigned a value.
 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
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 25th, 2009, 08:45 PM
#8
Thread Starter
New Member
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.
Last edited by neothod; Aug 25th, 2009 at 08:49 PM.
-
Aug 25th, 2009, 08:50 PM
#9
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|