Creating A Shared Instance Of An Object?

Feb 13, 2012

I would like to create a global instance of a User Class that can be referenced by all the forms in my MDI application.This object may be set during the login procedure by the Login form but the user attributes are to be available for other forms. For example, MyUser.ID will be required for meeting the audit requirements whenever data is changed.

View 14 Replies


ADVERTISEMENT

Moving Large Instance Method To Shared And Creating Stub?

Jun 5, 2011

If I have a very large function/sub in a class that is an instance method (i.e., not Shared), do I gain or lose anything by moving that to a shared method and then declaring a small stub method for the instance use?

I.e., I go from this:
Public Sub MyBigMethod(ByVal Foobar As String)
If String.IsNullOrWhitespace(Foobar) Then
Throw New ArgumentNullException("Foobar")
End If
[Code] .....

My thinking is I save on memory size per each instance of the object. Because each instance only has to lug around the stub method which handles calling the shared version and passing an instance of itself to the shared method so that it can do whatever it needs to do. But I'll wager that I sacrifice a very teensy amount of speed because of the added function call overhead.

View 1 Replies

Sql Server - Access A Shared Function From An Instance Of An Object?

Dec 28, 2010

The context of this question is that I am trying to debug performance issues (apart from the obvious ones I already know about and can find).I inherited a code base (VB.NET) for an ASP.NET app. This is an app that was developed way back in .NET 1.1 days, and was the first .NET app for a lot of the developers who worked on it.

In this code base is a class called DatabaseUtility that contains several Shared Public methods as well as non-Shared Public Functions and Subs for CRUD operations to the database (SQL Server).

It is common in my "BL" that a method creates an instance of the DatabaseUtility which essentially figures out what the connection string should be and opens a connection, as well as giving the developer a handle to the other methods contained within it.Dim utility as New DatabaseUtility()

Once I have that, I start to create parameters that I am going to pass to one of the methods in DatabaseUtility (like GetDataSet). There is a Shared method in my DatabaseUtility called CreateParameter which does essentially that. It creates a SqlParameter object so I can add it to a Parameters collection.

Now, the code base is littered with a lot of this:

utility.CreateParameter(...)However, because CreateParameter is a Shared method, I am not sure what is going on behind the scenes. I know because it is a Shared member that an instance of the DatabaseUtility is not created when I call it like this:DatabaseUtility.CreateParameter(...)

However, because I am calling it from an instance (utility), does that change the behavior at all?

View 1 Replies

'Object Reference Not Set To Instance Of An Object' While Creating Pivot In Excel

Jun 23, 2012

I'm trying to create a pivot table by opening an Excel file from my drive.But I'm receiving the error saying "Object reference not set to an instance of an object".[code]

View 1 Replies

Error - Creating The Form - Object Reference Not Set To An Instance Of An Object

Apr 13, 2012

I'm having this problem with my code and cannot seem to get past it although it was working fine before. The error is "An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object." The code is:

CODE:

I am trying to get information to be pulled out of a database and show in text boxes on another form (frmviewsdets). The error occurs when it gets to the line frmviewsdets.txtsnumber.Text = rdr("StudentNumber") and even when a breakpoint is applied there it just moves on to the next and so on.

I have tried to show frmviewsdets before I pull the data out of the database beut I get the same message.

View 14 Replies

Creating A New Instance Of An Object?

Apr 24, 2011

Suppose a click event is fired and a particular gridview datasource is set in the code behind page by retrieving a data table from a business logic class.

So programmatically speaking, what is the main difference between the two set of code listed below.
Private Sub btnGetGridViewData_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim myBLL as New BusinessLogicClass

[code]....

I guess my main question is, what is the purpose of creating a new instance of an object in the above scenario?

View 3 Replies

Object Is Not Creating An Instance

Apr 9, 2010

My project is done on vb,net& sql2000 but it is not running and showing error -

" object is not creating an instance " what to do ?

View 3 Replies

.net - Creating A New Instance Of A Class Object Box()

Sep 29, 2011

my aim is to create a new instance box at the push of a button, the box has strings name and Id to be filled concatenating the auto generated ID i.e. 0 to 210 plus a string "Box" added by the user. I had problems earlier creating a structure within the class box, frankly I am not sure if the code below will work, as i try to run it in VB I get an error indicating that I am using the variables strBoxPositions() and strBoxNumbers() without assigning a value to it. The thing is the strBoxPositions() should automatically be filled by arrPosition() which will be created at the same time the new object box is created and the strNumbers() will be created with empty strings to be filled at latter stage by the used as and when necessary.

how could I initialise those arrays to get the program to run and perhaps ill be able to see if the code works or not, or just correct this code with a better way of code with comments, also if possible some indication on how could I update the strNumbers array inputing the strings one at a time on a text box field.

Public class form1
Public Class Box
Public intBoxID As Integer

[Code].....

View 2 Replies

An Error Occurred Creating The Form. See Exception.InnerException For Details. The Error Is: Object Reference Not Set To An Instance Of An Object?

Apr 30, 2009

WTF, here's my code...

Public Class Form1
Dim BIT01 As Integer = BIT_01.Text
Dim Value As Integer = TB_OutPut.Text

[code].....

View 1 Replies

Asp.net Mvc - Creating A List (of String) Giving Error" Object Reference Not Set To An Instance Of An Object"

Nov 1, 2011

MVC 3 razor VB.NET project. I have resorted to manual building a list for a drop down box so I can insure certain values are available in the select list and also to control what the first item is in the list. The below is my code snippet for the part that is giving me problems..

[Code]...

View 2 Replies

Get "Object Reference Not Set To An Instance Of An Object" Error When Trying To Find An Instance In A String?

Jan 23, 2009

I am using the IndexOf function of the string class to find a specific instance of a string. And based on that I have a logic to do something. Below is the example of what I am doing. The code is in production and is working fine. But for some instance I am getting an "Object reference not set error". Yeah its intermittent.The requestXML is a string of xml data passed in as a paramter to a subroutine. I am fetching the xml string as a form post in a request object. The only thing I could think of getting this kind of error is when the requestXML string varia

requestXml = Request("requestXML")
SubmitRequest(requestXml)
Private
Sub SubmitRequest(ByVal requestXml

[code]....

View 5 Replies

Use Shared Vs Instance References?

Mar 3, 2010

As I stated before in my Sorting questions.When is it advisable to use Shared Functions vs Instance Functions References.The problem I posed was that in a threaded application if I was sorting an array of 999999999 elements I typically want to call a shared function that handles this; however in .NET the way to sort is through a .Sort method which you pass an array to be sorted and a function handler; or Comparisson(t of).

My impression is that if in order to do a ClosestToN Sort I would have to calculate the value of N in the array first; then sort and then subtract the value of N from the sorted array.JohnH suggested passing the value of N as a Property in a Class that contained a reference to a sort Algorithm.The benchmark suggested in a 1 thread model it would work faster (which I knew that it would through math, but the accessors I was speculative on; I turned out to be wrong it worked fine either way).

My issue is in a Multi-Thread application creating instances for an accessor may cause memory to fill quickly if I am dealing with 1000's of threads.Is it better in this case to use a slower Shared function, then a faster Instance Function?

View 5 Replies

Access Of Shared Member Through Instance

Nov 6, 2009

After I formatted my laptop and reinstalled Visual Studio 2005, I receive a lot of same error as below message.
"Access of shared member through an instance; qualifying expression will not be evaluated"
If I click the error, it direct me to the line and all 102 error suggest me to add "Windows.Forms." before "DialogResult.OK". Should I add something on "Reference"?

View 4 Replies

How Many Instance Will A Shared Variable Be Created

Apr 7, 2010

How many instances of a shared variable will be created in a class? just one? correct

[code]...

So, in other words, the DocumentDelivery class will only have one instance of RenderList, correct? can somebody confirm?

View 3 Replies

Ajax - Passing Instance To Shared Method In .NET?

Nov 4, 2010

I have been thrown in at the deep end with an existing VB.NET project at work. I have never used VB.NET before so I am struggling a little. Does anyone know how to solve the following.I need to pass an instance to client side and then pass it to a shared method in order to access instance methods from when the shared method.The starting point is a fileupload control within the HTML of my Contacts.aspx file:

<asp:FileUpload ID="DocUpload1" runat="server" onchange="CallMe();" />

The onchange event calls a javascript method, see below, this uses AJAX PageMethods to called a Shared method in my code behind This is the script code which is in my Contact.aspx file

[Code]...

If anyone knows the solution please could they update the code as I probably won't be able to understand if you just give a description. I just hope I am along the right tracks.

View 1 Replies

VS 2010 : Exposing An Instance Property As Shared?

May 24, 2010

Suppose I have a class of objects called Porky with a property called IsHuge:

Public Class Porky
Public Property IsHuge As Boolean
End Class

Now I want to make a special kind of Porky -- let's call it UberPorky -- for which I want to change ALL instances to either IsHuge or not IsHuge. What I'd like to do is this:

Public Class UberPorky
Inherits Porky
Public Overrides Shared Property IsHuge As Boolean

[code]....

The trouble is, I can't do that. I'm not allowed to reference MyBase or Me in a Shared property.

View 17 Replies

.net - Prohibit An Instance From Calling Shared/Static Method?

Aug 27, 2010

Is it possible to prohibit an instance of a class from calling a shared/static method?

For example:

I want to allow this:

ClassName.MethodOne()

But I want to disallow this:

Dim A As New ClassName
A.MethodOne()

The reason this is desirable is that in this case it is semantically confusing if an instance can call the method.

View 2 Replies

C# - Access A Shared/static Member Through An Instance Variable?

Mar 3, 2011

Here's an example of what I'm talking about...

Public Class Sample1

Public Shared Function MyValue() As Integer
Return 0
End Function
Public Sub Code()

[Code]...

Me.MyValue gives a warning in VB.NET and (the equivalent code gives) an error in C#. Is there a particular reason for this? I find it more intuitive/natural to access the shared function using 'Me.MyValue' - but I avoid it to keep my warnings at 0. Did someone else just decide 'Nah, it makes more sense to do it the other way' or is there some technical reason I don't understand?

EDIT: I was thinking of it wrong, more like a 'sub class' in OOP. Even if something is declared in the base class, you access it through the instance you have. But that relationship is not the same with shared or static.

View 6 Replies

Overload Shared Methods On Non-instance Types Using Extensions?

May 14, 2012

I want to extend the BitConverter class with an overload of ToString() that takes a parameter of type Char, representing a value delimiter.Why? By default, the ToString() call returns a string representation of a byte array, delimited by dash symbols. The signature does not allow you to specify a different delimiter, which I find very unfortunate.Now because this is not an instance type, or maybe because I'm overloading a shared method, I'm having a hard time finding the proper syntax to define my extension method.What am I doing wrong here, causing the overloads to not show up in IntelliSense:

Imports System.Runtime.CompilerServices
Module BitConverterExtensions
<Extension()>

[code].....

View 1 Replies

Purpose Of Using Shared Methods That Return An Instance Of A Class?

Oct 11, 2010

What is the purpose of using shared methods that return an instance of a class, as opposed to a constructor?

ie: in VB.net, the system.drawing.color class has shared method "FromArgb(int, int, int) as color". This is different from java's implementation which simply is a constructor that takes three ints. Why the decision to do one or the other?

View 1 Replies

Creating Single Instance Form In MDI Application - Check Whether Form's Instance Created Or Not?

Feb 8, 2012

creating single instance form in MDI Application. How to check whether form's instance created or not?

View 6 Replies

Very Simple Ssis Script Transformation Giving Object Reference Not Set To An Instance Of An Object

Mar 1, 2012

I have an ssis package that takes a flat file and dumps it to SQL. During that process, 150 columns need to have '-' and '.' removed from them. I have done this using a Script Transformation.

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim column As IDTSInputColumn90
Dim rowType As Type = Row.GetType()

[code]....

Edit I've discovered that this line is the problem

Dim strCol As String = columnValue.GetValue(Row, Nothing).ToString()

View 1 Replies

.net - Process.start System.nullreferenceexception: Object Reference Not Set To An Instance Of An Object

Oct 16, 2011

I am trying to start the process with the following parameters When I try to start it though I get an System.nullreferenceexception: Object reference not set to an instance of an object

Dim exepath As String = Application.StartupPath + "inffmpeg.exe"
Dim sr As StreamReader
Dim cmd As String = " -i """ + input + """ -ar 22050 -y """ + output + """"
Dim ffmpegOutput As String

[code]....

View 16 Replies

Asp.net - Checking For A Session Variable... Returns (Object Reference Not Set To An Instance Of An Object)

Jan 12, 2011

In the Session_Start of the Global.asax i have

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("login") = False

[code]....

Why i am getting error the error Object reference not set to an instance of an object. at line

If Current.Session("login") Is Nothing Then

while checking for the login state as follows?

If GetLogin = False Then
'Do something
End if

I mean i have already created the instance on the Session_Start... Haven't i?

View 1 Replies

Error System.NullReferenceException Occurred - Object Reference Not Set To An Instance Of An Object

Jan 12, 2010

i am using VB.net 2003 and i am trying to get the number of rows of a dataset from form1 into form2 in order to use it for something else and i am getting the error"System.NullReferenceException occured...Additional information: object reference not set to an instance of an object"...my code is like this:in form1:Public x as integer= me.dataset.table.rows.count here it gives me the error

in form2:
dim frm as new form1
msgbox(frm.x)

View 1 Replies

Error: System.NullReference Exception: Object Reference Not Set To An Instance Of An Object

Jan 5, 2010

I am getting this error when I try to print my report. Here is my print code.

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim Print_Dialog As New PrintDialog

[code].....

Here is my error: System.NullReference Exception: Object reference not set to an instance of an object.

View 1 Replies

Format Date In Data Grid View Object Not Set To An Instance Of An Object?

Jan 29, 2012

I'm trying to set the format of a column in a datagridview.When I put the format statement in the on load event for the form, it has no effect. When I put it in the cellformatting event I get the "Object reference not set to an instance of an object" error. I checked the column name. What I am doing wrong?

This is the code:Private Sub MeetingTblDataGridView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles MeetingTblDataGridView.CellFormatting
Me.MeetingTblDataGridView.Columns("Starttime").DefaultCellStyle.Format = "HH:mm:ss"
End Sub What I'm trying to do is get rid of the date part of a Date/Time field (stored in an Access database) in a datagridview column.

dp.SyntaxHighlighter.ClipboardSwf = '/dp.SyntaxHighlighter/Scripts/clipboard.swf'
dp.SyntaxHighlighter.HighlightAll('09dde30f062e451a854266e66205b1cf')

View 10 Replies

Line Of Code Is Generating This Error - Object Reference Not Set To An Instance Of An Object?

Aug 14, 2010

with datagridview1

while looping through all the cells

i am trying to allot a cell value to another cell value basing on some conditions
& finally delete one column.my code is as fallows

Dim i, x As Integer
i = 0
x = Me.DataGridView1.Rows.Count[code]....

error i am getting is : Object reference not set to an instance of an object.it is extremely surprising for me the same code has worked nice for me but why & how the same line of code is generating this error.

View 10 Replies

Object Reference Not Set To An Instance Of An Object When Searching For User In Active Directory?

May 8, 2012

I tryed searching for an user in active directory using the code below but it gives me the error in the title of this post above:

AD = New DirectoryEntry("LDAP://OU=SchoolOUhere,OU=Staff,DC=garrard,DC=ketsds,DC=net", "", "", AuthenticationTypes.Secure)
AD2 = New DirectoryEntry("LDAP://OU=_Groups,OU=Staff,DC=garrard,DC=ketsds,DC=net", "", "", AuthenticationTypes.Secure)

[Code]...

Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to[URL]...

View 4 Replies

Object Reference Not Set To An Instance Of An Object With A Class With An Array Of Classes As A Member?

Aug 6, 2010

Here is the structure that I have:

Friend Class StandardFormatFile
Friend fileType As String
Friend numberOfSeries As Integer

[code].....

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved