473,385 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Object reference not set

Can someone point me the small error I have made here?
Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &= "\"
gstrBestand &= "beginner.txt"
End Sub
The error is:
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

The line with the error is:
gstrBestand = Programma.UserAppDataPath

I thought it was enough to do "Dim Programma As Application"
Apparently not?

--
localghost
Nov 20 '05 #1
23 1076
Dim Programma As New Application

Regards - OHM

localhost wrote:
Can someone point me the small error I have made here?
Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &=
"\" gstrBestand &= "beginner.txt"
End Sub
The error is:
An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

The line with the error is:
gstrBestand = Programma.UserAppDataPath

I thought it was enough to do "Dim Programma As Application"
Apparently not?


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #2
* localhost <lo*******@localdomain.org> scripsit:
Can someone point me the small error I have made here?

Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &= "\"
gstrBestand &= "beginner.txt"
End Sub


Skip the 1st line and use this:

\\\
gstrBestand = Application.UserAppDataPath
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
???

I'm just working on this one, 'twas my first try too but the constructor for
"Application" is private.
Hex.

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dim Programma As New Application

Regards - OHM

localhost wrote:
Can someone point me the small error I have made here?
Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &=
"\" gstrBestand &= "beginner.txt"
End Sub
The error is:
An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

The line with the error is:
gstrBestand = Programma.UserAppDataPath

I thought it was enough to do "Dim Programma As Application"
Apparently not?


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #4
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in news:
#M**************@TK2MSFTNGP09.phx.gbl:
localhost wrote:
Can someone point me the small error I have made here?
Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &=
"\" gstrBestand &= "beginner.txt"
End Sub

Dim Programma As New Application

Regards - OHM


I already guessed, thanks anyway. By the way, .NET added paranthesis after
Application.

But now I get "Overload resolution failed because no 'New' is accessible."

--
localghost
Nov 20 '05 #5
hi***************@gmx.at (Herfried K. Wagner [MVP]) wrote in
news:u4**************@TK2MSFTNGP09.phx.gbl:
* localhost <lo*******@localdomain.org> scripsit:
Can someone point me the small error I have made here?

Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &= "\"
gstrBestand &= "beginner.txt"
End Sub


Skip the 1st line and use this:

\\\
gstrBestand = Application.UserAppDataPath
///


No, same error again. Now on this new line you suggested.
:(

--
localghost
Nov 20 '05 #6
Not totally confident on why your solution doesn't work but for the
meantime, try

Public Sub InitBestand()
' Dim Programma As Application
' gstrBestand = Programma.UserAppDataPath
gstrBestand = Application.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &= "\"
End Sub

Hexathioorthooxalate
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dim Programma As New Application

Regards - OHM

localhost wrote:
Can someone point me the small error I have made here?
Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &=
"\" gstrBestand &= "beginner.txt"
End Sub
The error is:
An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

The line with the error is:
gstrBestand = Programma.UserAppDataPath

I thought it was enough to do "Dim Programma As Application"
Apparently not?


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #7
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:
???

I'm just working on this one, 'twas my first try too but the
constructor for "Application" is private.
Hex.


I'm not as good as most people here, but is "private constructor for
Application" just another way of saying you cannot use "New"?

PS: until a week ago I dabbled around in VB6, so bear with me. :)

--
localghost
Nov 20 '05 #8

"localhost" <lo*******@localdomain.org> wrote in message
news:rO**********************@phobos.telenet-ops.be...
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:
???

I'm just working on this one, 'twas my first try too but the
constructor for "Application" is private.
Hex.
I'm not as good as most people here, but is "private constructor for
Application" just another way of saying you cannot use "New"?


Yes.

It is odd you are getting this error. Both your original solution, and the
one I posted a few minutes ago, work fine for me (VS2003, .NET 1.1).

PS: until a week ago I dabbled around in VB6, so bear with me. :)

--
localghost

Nov 20 '05 #9
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

"localhost" <lo*******@localdomain.org> wrote in message
news:rO**********************@phobos.telenet-ops.be...
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:
> ???
>
> I'm just working on this one, 'twas my first try too but the
> constructor for "Application" is private.
> Hex.


I'm not as good as most people here, but is "private constructor for
Application" just another way of saying you cannot use "New"?


Yes.

It is odd you are getting this error. Both your original solution, and
the one I posted a few minutes ago, work fine for me (VS2003, .NET
1.1).


I am using VS2002 and .NET 1.0.
Could that be the root cause of all evil?

--
localghost
Nov 20 '05 #10
Just to so we'll all looking at the same picture, create a new WinForms
application with a single form (called Form1), pop a button on the form
(called Button1), and paste in the following.

When you click the Button, do you get the same error?
Option Strict On
Option Explicit On

Public Class Form1
Inherits System.Windows.Forms.Form

'[+]Windows Form Designer Code

Public Sub InitBestand()
Dim gstrBestand As String = Application.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &= "\"
MsgBox(gstrBestand)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call InitBestand()
End Sub
End Class

"localhost" <lo*******@localdomain.org> wrote in message
news:cT**********************@phobos.telenet-ops.be...
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

"localhost" <lo*******@localdomain.org> wrote in message
news:rO**********************@phobos.telenet-ops.be...
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

> ???
>
> I'm just working on this one, 'twas my first try too but the
> constructor for "Application" is private.
> Hex.

I'm not as good as most people here, but is "private constructor for
Application" just another way of saying you cannot use "New"?


Yes.

It is odd you are getting this error. Both your original solution, and
the one I posted a few minutes ago, work fine for me (VS2003, .NET
1.1).


I am using VS2002 and .NET 1.0.
Could that be the root cause of all evil?

--
localghost

Nov 20 '05 #11
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:
Just to so we'll all looking at the same picture, create a new WinForms
application with a single form (called Form1), pop a button on the form
(called Button1), and paste in the following.

When you click the Button, do you get the same error?
Option Strict On
Option Explicit On

Public Class Form1
Inherits System.Windows.Forms.Form

'[+]Windows Form Designer Code

Public Sub InitBestand()
Dim gstrBestand As String = Application.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &= "\"
MsgBox(gstrBestand)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call InitBestand()
End Sub
End Class


Hmmm... that works?
What now? Throw away my old application and copy/paste the code to the new
one?

--
localghost
Nov 20 '05 #12

Hmmm... that works?
What now? Throw away my old application and copy/paste the code to the new
one?

--
localghost


Or go bug hunting!

Glad to be of help.
Hex.
Nov 20 '05 #13
"localhost" <lo*******@localdomain.org> wrote...
Can someone point me the small error I have made here? Public Sub InitBestand()
Dim Programma As Application
gstrBestand = Programma.UserAppDataPath
If Strings.Right(gstrBestand, 1) <> "\" Then gstrBestand &= "\"
gstrBestand &= "beginner.txt"
End Sub I thought it was enough to do "Dim Programma As Application"
Apparently not?


I believe two things are going on here. The first problem is that you are
defining variable as type Application but not assigning it any reference to
an Application. You cannot create an instance of the Application class. So
that's why you are getting the null reference exception, the reference is
null.

Now as to why it doesn't work when you reference Application.UserAppDataPath
directly? Something else is up. When something odd happens I suggest you
simply start over with a new test app and just try to type the single line
Console.Writeline(Application.UserAppDataPath)

You should see UserAppDataPath show up in IntelliSense and of course it
should output the path when you run it.

Tom

Nov 20 '05 #14
* localhost <lo*******@localdomain.org> scripsit:
gstrBestand = Application.UserAppDataPath
///


No, same error again. Now on this new line you suggested.
:(


Are you using 'System.Windows.Forms.Application' or a user defined
class? Maybe you have to instantiate this class:

\\\
Dim d As New Application()
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #15
hi***************@gmx.at (Herfried K. Wagner [MVP]) wrote in news:
#P**************@TK2MSFTNGP10.phx.gbl:
* localhost <lo*******@localdomain.org> scripsit:
gstrBestand = Application.UserAppDataPath
///


No, same error again. Now on this new line you suggested.
:(


Are you using 'System.Windows.Forms.Application' or a user defined
class? Maybe you have to instantiate this class:

\\\
Dim d As New Application()
///


uhhh... dunno.
I started again with a new app and copied all the code over.
No more problems now...
Nov 20 '05 #16
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

Hmmm... that works?
What now? Throw away my old application and copy/paste the code to
the new one?

--
localghost
Or go bug hunting!


A technique I often use when bug hunting, is putting MsgBox-es all over to
see what is going on. I've learned one thing: NEVER EVER put a msgbox in a
sub that handles the activated event of a form...
form activated --> msgbox pops up --> form is deactivated
close msgbox --> form is activated again --> msgbox popup...

aaaaaargh!
:-@
Glad to be of help.
Hex.


Thanks for giving me a few clues.
Nov 20 '05 #17
"Tom Leylan" <ge*@iamtiredofspam.com> wrote in
news:Op**************@TK2MSFTNGP10.phx.gbl:
Now as to why it doesn't work when you reference
Application.UserAppDataPath directly? Something else is up. When
something odd happens I suggest you simply start over with a new test
app and just try to type the single line
Console.Writeline(Application.UserAppDataPath)


Yup, already did that.
See Message-ID: <n9**********************@phobos.telenet-ops.be>
Nov 20 '05 #18
"Tom Leylan" <ge*@iamtiredofspam.com> wrote in
news:Op**************@TK2MSFTNGP10.phx.gbl:
Now as to why it doesn't work when you reference
Application.UserAppDataPath directly? Something else is up. When
something odd happens I suggest you simply start over with a new test
app and just try to type the single line
Console.Writeline(Application.UserAppDataPath)


Already did that.
See Message-ID: <36**********************@phobos.telenet-ops.be>
Thanks anyway.

--
localghost
Nov 20 '05 #19
localhost <lo*******@localdomain.org> wrote in
news:jn**********************@phobos.telenet-ops.be:
Can someone point me the small error I have made here?


Thanks to everybody who tried to help.

--
Amedee Van Gasse
Nov 20 '05 #20
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

By the way, why do you use [C2S6]6- as a nickname on the usenet?
I know it's something with anorganic salts, but what exactly?

--
Amedee Van Gasse aka localghost
Nov 20 '05 #21
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

By the way, why do you use [C2S6]6- as a nickname on the usenet?
I know it's something with anorganic salts, but what exactly?

--
Amedee Van Gasse aka localghost
Nov 20 '05 #22
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

By the way, why do you use [C2S6]6- as a nickname on the usenet?
I know it's something with anorganic salts, but what exactly?

--
Amedee Van Gasse aka localghost
Nov 20 '05 #23
Just a nomme de plume, currently unique. Unfortunately my joint christian
and surnames are still not unique, and I wouldn't want to use them anyway as
every now and then we all observe newsgroup flaming campaigns. If this were
ever happen to me, I would prefer the anonymity.
Hex

See:

http://groups.google.co.uk/groups?hl...TF-8%26hl%3Den


"Amedee Van Gasse (localghost)" <am****@amedee.doesnotwantspam.be> wrote in
message news:eL**********************@phobos.telenet-ops.be...
"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in
news:10****************@demeter.uk.clara.net:

By the way, why do you use [C2S6]6- as a nickname on the usenet?
I know it's something with anorganic salts, but what exactly?

--
Amedee Van Gasse aka localghost

Nov 20 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris S. | last post by:
I'm trying to make a graphical editor and browser for Pickled files. One aspect I'm not sure about is how to detect multiple references to the same data. For instance, say I had the Pickled...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
29
by: web1110 | last post by:
If I have 2 variables, A and B, referencing the same object and then do a A.Dispose(), what happens to B?
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.