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, 01: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, 05:34 PM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 536 June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 13 h 58 m 7 sec
Reputation Power: 124
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, 05: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, 11:21 PM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 536 June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 13 h 58 m 7 sec
Reputation Power: 124
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, 01: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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





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