Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 1st, 2009, 12:46 PM
bobmarley bobmarley is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 bobmarley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 59 sec
Reputation Power: 0
Error: Object reference not set to an instance of an object.

An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.

I'm trying to make a game for this class I'm taking. I started getting this error after trying to make an array of objects.
In the game you're a tornado chaser, so I have a class for city and a class for the tornado. I'm not going to post my main form unless someone wants me to but it creates ten instances of city.

Public Class City
Public cityName As String
Public cityNum As Integer
Public temperature As Integer
Public windSpeed As Integer
Public nTemperature As Integer
Public nWindSpeed As Integer
Public sTemperature As Integer
Public sWindSpeed As Integer
Public wTemperature As Integer
Public wWindSpeed As Integer
Public eTemperature As Integer
Public eWindSpeed As Integer
Public weatherType As Integer = CInt(2 * Rnd() + 1)
Public tornadoN(cityNum) As Object
Public tornadoS(cityNum) As Object
Public tornadoE(cityNum) As Object
Public tornadoW(cityNum) As Object

Public Sub New(ByVal name As String, ByVal num As Integer)
cityName = name
cityNum = num
set_weather_type()
End Sub

Sub set_weather_type()

If weatherType = 1 Then
set_weather1()
ElseIf weatherType = 2 Then
set_weather2()
ElseIf weatherType = 3 Then
set_weather3()
End If
End Sub

Sub set_weather1()
temperature = CInt(90 * Rnd() + 70)
windSpeed = CInt(5 * Rnd())
nTemperature = CInt(90 * Rnd() + 70)
nWindSpeed = CInt(5 * Rnd())
sTemperature = CInt(90 * Rnd() + 70)
sWindSpeed = CInt(5 * Rnd())
wTemperature = CInt(90 * Rnd() + 70)
wWindSpeed = CInt(5 * Rnd())
eTemperature = CInt(90 * Rnd() + 70)
eWindSpeed = CInt(5 * Rnd())
End Sub


Sub set_weather2()
temperature = CInt(60 * Rnd() + 40)
windSpeed = CInt(18 * Rnd() + 1)
nTemperature = CInt(60 * Rnd() + 40)
nWindSpeed = CInt(18 * Rnd() + 1)
Dim tornadoN(cityNum) As Tornado
tornadoN(cityNum).set_tornado(weatherType)
sTemperature = CInt(60 * Rnd() + 40)
sWindSpeed = CInt(18 * Rnd() + 1)
Dim tornadoS(cityNum) As Tornado
tornadoS(cityNum).set_tornado(weatherType)
wTemperature = CInt(60 * Rnd() + 40)
wWindSpeed = CInt(18 * Rnd() + 1)
Dim tornadoW(cityNum) As Tornado
tornadoW(cityNum).set_tornado(weatherType)
eTemperature = CInt(60 * Rnd() + 40)
eWindSpeed = CInt(18 * Rnd() + 1)
Dim tornadoE(cityNum) As Tornado
tornadoE(cityNum).set_tornado(weatherType)
End Sub

Sub set_weather3()
temperature = CInt(50 * Rnd() + 35)
windSpeed = CInt(30 * Rnd() + 5)
nTemperature = CInt(50 * Rnd() + 35)
nWindSpeed = CInt(30 * Rnd() + 5)
Dim tornadoN(cityNum) As Tornado
tornadoN(cityNum).set_tornado(weatherType)
sTemperature = CInt(50 * Rnd() + 35)
sWindSpeed = CInt(30 * Rnd() + 5)
Dim tornadoS(cityNum) As Tornado
tornadoS(cityNum).set_tornado(weatherType)
wTemperature = CInt(50 * Rnd() + 35)
wWindSpeed = CInt(30 * Rnd() + 5)
Dim tornadoW(cityNum) As Tornado
tornadoW(cityNum).set_tornado(weatherType)
eTemperature = CInt(50 * Rnd() + 35)
eWindSpeed = CInt(30 * Rnd() + 5)
Dim tornadoE(cityNum) As Tornado
tornadoE(cityNum).set_tornado(weatherType)
End Sub

End Class




Public Class Tornado

Dim fLevel As Integer
Dim speed As Integer
Dim size As Integer

Sub set_tornado(ByVal type)
If type = 2 Then
set_tornado2()
Else
set_tornado3()
End If
End Sub

Sub set_tornado2()
fLevel = CInt(3 * Rnd() + 1)
If fLevel = 1 Then
speed = CInt(90 * Rnd() + 70)
size = CInt(80 * Rnd() + 60)
ElseIf fLevel = 2 Then
speed = CInt(70 * Rnd() + 50)
size = CInt(60 * Rnd() + 40)
Else
speed = CInt(50 * Rnd() + 30)
size = CInt(40 * Rnd() + 20)
End If

End Sub

Sub set_tornado3()
fLevel = CInt(5 * Rnd() + 4)
If fLevel = 4 Then
speed = CInt(120 * Rnd() + 90)
size = CInt(110 * Rnd() + 80)
Else
speed = CInt(175 * Rnd() + 120)
size = CInt(150 * Rnd() + 110)
End If
End Sub

End Class

Reply With Quote
  #2  
Old November 1st, 2009, 04:34 PM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 1,081 June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 14 h 55 m 48 sec
Reputation Power: 225
What is your question? What is not working? Any error message? What line is the error on? Step debug.

Reply With Quote
  #3  
Old November 1st, 2009, 04:46 PM
bobmarley bobmarley is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 bobmarley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 59 sec
Reputation Power: 0
An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.


That is the error message i get. It doesn't tell me what line its on. In debug on the error list it says 0. I know it has something to do with the parts of the code where I make objects of the Tornado class, because it worked till I put those in there:

Dim tornadoN(cityNum) As Tornado

TornadoN(cityNum).set_tornado(weatherType)

Reply With Quote
  #4  
Old November 1st, 2009, 10:21 PM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 1,081 June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 14 h 55 m 48 sec
Reputation Power: 225
Sorry, now I see the first line in your post does cover the error info. Hope someone else responds to your issue. I have no experience with user-defined classes and have absolutely no idea what 'Exception.InnerException' means, looking at MS help on the topic didn't clarify for me.

Reply With Quote
  #5  
Old November 2nd, 2009, 12:09 PM
bobmarley bobmarley is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 bobmarley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 59 sec
Reputation Power: 0
I think I might know the problem. Is it possible to make an object within an object. because my program makes a city object in the main form then the city makes a tornado object.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Error: Object reference not set to an instance of an object.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek