Use Of Shared Variable In .net?

Mar 5, 2009

What is the use of shared variable in vb.net?

View 3 Replies


ADVERTISEMENT

Asp.net - Public Shared Variable Shared Between Users?

Mar 30, 2012

I've taken over the maintenance of the website (ASP.NET VB) and on one particular page I noticed the below code

Inherits System.Web.UI.Page
Public Shared UserNumber As String
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

[Code]....

My question is whether the variable UserNumber can be accessed or changed by any other user than the current one?

View 2 Replies

Create A "shared" Variable That Is Shared With All Instances Of A Class?

Jan 14, 2011

I seem to be drawing a blank. I'd like to create a "shared" variable that is shared with all instances of a class but not classes that inherit from it. For example.Class A: Shared list As New List(Of String): list.Add("A")

Class B Inherits A: list.Add("B")Class C Inherits B: list.Add("C")The end result I'd like is that any instance of A has just A in the list. Any instance of B has A and B in the list. Any instance of C has A, B, and C in the list. I can accomplish it by creating Instance variables, but I have to construct the list for each instance of a class. I'd like to construct it once for a specific point in the Hierarchy and then share it accross other instances of that class.

View 12 Replies

C# - Shared / Static Variable Should Be Nothing?

Jan 6, 2011

I have the following code:
Public Class TestClass
Public Sub Main()
If theGlobal IsNot Nothing Then Throw New Exception("What gives!")
End Sub
Private Shared theGlobal As Object = Nothing
[Code] .....
Why is theGlobal object NOT Nothing?

View 2 Replies

How To Dispose Shared Variable

Apr 12, 2011

How to dispose the shared variable in vb.net.i am using shared object of Asterisk.NET Manager Variable, i assigned it in form load and i dispose it in main form closing, My problem is after closing the application, application.exe keeps live in task manager, if i not initializing the shared object in form load there is no problem,[code]

View 3 Replies

Public Shared Variable Ref?

Jun 29, 2011

I have an arraylist in a user form (Mainform) that I would like to be able to share among multiple forms and edit the contents. Using the Public Shared method I have been able to view and even edit the arraylist, but it does not seem to be changing it back on the main form. I can give more detail if needed.

View 9 Replies

.net - ASP.NET Shared Variable For An Error Handler

May 28, 2012

I am planning to use a shared variable to implement a logging facility. Have a look at the code below:

Imports System.IO
Public Class TestClass
Public Shared objError As New StreamWriter("C:Test.txt")
End Class

[Code]....

I think I have found my answer here: [URL] "A static variable continues to exist and retains its most recent value. The next time your code calls the procedure, the variable is not reinitialized, and it still holds the latest value that you assigned to it. A static variable continues to exist for the lifetime of the class or module that it is defined in."

I am not convinced that this is the best way to create a logging facility.

View 2 Replies

C# - Does Session Variable Shared Across Different Browser

May 24, 2012

Does session variable shared accross different browser? If not is there away that I can share information accross browser similar to the functionality of caching but the scope is wider.

View 3 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

Shared Variable For Multiple Loading

Jul 22, 2011

I need some tips for shared variable to share the information for multiple running application. For example, the value of variable become 1 when a user run the first instance(execution), and become 2 when the user executes the second(in sames OS or through network).

View 3 Replies

Accessing A Public Shared Variable From A Different Class?

Jan 10, 2012

I currently have two forms, and I need to share the value of a variable in one of them.

I declared the variable to be 'Public Shared', and assigned a value to it. However,

when I inspect the value it appears as 'Nothing'. Here is the snippet:

Public Class A
Public Shared sVar As String = Nothing
Private Sub A_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code]....

View 4 Replies

Create A Shared Project Wide Variable

Aug 3, 2010

I've been looking at using PROPERTIES [URL] but frankly I don't understand it that well. Before I invest the time to read, understand, and truly comprehend this, I want to make sure it's the best way. My intended goal is to create my database connection string in a function/sub somewhere, then assign it to this project wide string variable, then I can use it in any form, project wide without having to recreate it.

[Code]...

View 7 Replies

IDE :: Checking Shared Variable Values During Debugging?

Feb 20, 2009

I have declared a class in VB.NET using VS2K5 with some shared variables and made that class a dllI made use of that dll in another project and tried to make use of those variables. Even though I can able to make use of them, Im unable to view the values of those variables like the values of normal variables when Im debugging. Is there any way that I can watch the values of those shared variables during debugging.

View 1 Replies

Declare A Variable To Be Shared By 2 Forms (classes) In The Same Project?

Jan 1, 2011

I've gone brain dead and can't remember how (where) to declare a variable to be shared by 2 forms (classes) in the same project.

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

Release Public Shared Variable After Form Close?

Mar 4, 2010

shared variables of particular form in vb.net 2005

View 1 Replies

Access A Class Variable Inside Shared Method (JSON)

Jun 20, 2012

Inside my .aspx I have some JSON code that looks like this:

[Code]....

Basically what I'm doing is pulling text from two labels on one page, and sending them to another page by calling the "doIt" function which looks like this:

[Code]....

Just so I'm clear, the "doIt" function and the JSON call are on two separate web forms. My problem is that with the "doIt" function being Shared, I can't access any global variables of the class. And if I remove the Shared, my JSON doesn't execute.

View 1 Replies

Error: Reference To A Non-shared Member | Constructor; Pass Variable

Mar 13, 2010

I've been trying implement Constructor method in passing variable between two forms.Just a rough user interface guide - issue Invoice. User would type in all the Customer Name, Document Number. Once he reached Item Details, a Child Form would pop-up for the User to select/search the Invoice's Item; Once selected, the selected item would showed in the primary Form.

What I had tried is, the Constructor method worked perfectly when it is self-contain in a new project, yet to be implement in my application.But when I implemented, there is an error: Reference to a non-shared member requires an object reference.

[Code]...

View 6 Replies

Local Variables In Shared Method Work Like Static Variable In C?

Aug 23, 2011

Will the list in this shared method keep its state throughout the life of the method? Or will a new list be created every time this method is called?

[Code]...

View 3 Replies

.net - Why Can't Call Private Shared Methods From A Public Shared Method

Aug 25, 2011

I have a class like this:

[Code]...

It works, when I make getBar methods public, but I don't want to expose these unneccessarily. Why I can't call private shared methods from a public one in the same class is over my head. I'm using .net framework 4.0 in a web application.

View 1 Replies

Shared Method Not Calling Shared Constructor

Aug 12, 2009

Given in the following language specification, for me at least, calling Db.Foobar() [In the following code] does not indeed call off to the Shared Constructors of the base classes. I am curious as to a) is this my own fault for doing something wrong or b) is this an error in the language specification[code]...

View 2 Replies

Use Derived Class Shared Variables In Shared Methods Of Base Class?

Jun 4, 2010

I am trying to add shared members in derived classes and use that values in base classes...

I have base

class DBLayer
public shared function GetDetail(byval UIN as integer)
dim StrSql = string.format("select * from {0} where uin = {1}", tablename, uin)
end function
end class

[Code]..

currently there is error using the tablename variable of derived class in base class but i want to use it i dun know other techniques if other solutions are better then u can post it or u can say how can i make it work? confused...

View 2 Replies

VS 2008 Error: Range Variable 'sender' Hides A Variable In An Enclosing Block Or A Range Variable Previously Defined In The Query Expression

Mar 25, 2010

I am getting the error:"Range variable 'sender' hides a variable in an enclosing block or a range variable previously defined in the query expression."for this

Imports System.Data.SqlClient
Imports System.Linq
Public Class Form1

[code]....

I can select any other item from the table without the error. "sender" has the same properties as "receiver" in the SQL table.

View 2 Replies

Variable Error "Variable 'reader' Hides A Variable In An Enclosing Block"

Aug 23, 2011

I receive the error -

[Code]...

View 10 Replies

Difference Between Shared Events And Non-shared Events?

Dec 16, 2009

is there a difference between shared events and non-shared events?

Private Shared Event EVENT_something_changed()
Private Sub SUB_handles_something_changed() Handles Me.EVENT_something_changed
End Sub

no errors with this code, but how is Me possible since the Event is shared. it seems like there's no errors between switching shared with un-shared and switching Me with Myclass, all 4 combinations seem to work, isn't that weird

View 18 Replies

Program Function - Says, "The Type For Variable [variable] Will Not Be Inferred Because It Is Bound To A Field

May 18, 2012

Public Class Form1
Dim x, c, number(0 To 19) As Integer
Dim s As Integer

[CODE]...

The variables in the brackets [example] do not actually have brackets in them in the original code. These are where the issues are. For both variables, it says, "The type for variable [variable] will not be inferred because it is bound to a field in an enclosing scope. Either change the name of [variable], or use the fully qualified name (for example, 'Me.[variable]' or 'MyBase.[variable]')." Now, I'm not entirely sure if this is a stupid question or not, as I'm used to VB '98 because that's what we use in my programming class at High School. let me know why this won't work.

-Note: The intention of this program is to continually loop the generation of numbers for this list until I tell it to stop. Button1 ends the program, Button2 generates the list one time only, Button3 is supposed to loop the generation of the list, and Button4 is supposed to end the loop, but not the program.

View 9 Replies

VS 2010 Compiler Creates New Variable Automatically When Use If Statement Without Strictly Declared Variable?

Jan 10, 2011

Say that i have the following code that parse about 20k records from the DB.

Code #1

vb.net While reader.Read()
list.Add(If(Integer.TryParse(reader(0).ToString, 0), Integer.Parse(reader(0).ToString), 0))
End While

And then another code which does the very same thing but it seems to be a little cleaner.

Code #2

vb.net While reader.Read()
Dim storeowner As Integer = 0
Integer.TryParse(reader(0).ToString, storeowner)
list.Add(storeowner)
End While

This is what i am confused about; does the compiler creates a new variable automatically when i use the if statement without strictly declared variable? What approach is better in sense of performance?

View 2 Replies

Variable Naming Conventions To Illustrate Variable Type And Where Variables Are Declared

Aug 24, 2009

I am looking for a good resource on variable naming conventions to illustrate variable type and where variables are declared. So I will have public variables, Private variables, private or local variables. I also may want to declare variables with the same name in different class code (i.e. in the code behind different forms). I am assuming good coding would dicatate a prefix for declaration location.

View 4 Replies

Import Text File : Object Variable Or With Block Variable Not Set

Mar 28, 2011

i have this error in the line of with xl.active......Object variable or With block variable not set.

Dim xl As Object
xl = CreateObject("Excel.Application")
With xl.ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:Documents and SettingsUserDesktop429MEDICA2.TXT", _ Destination:=xl.Range("$A$1"))

[code]....

View 4 Replies

Object Variable Or With Block Variable Not Set - From Property Get With Bindingsource.current?

May 31, 2012

Now I have the need to get a current value from a bindingsource in a property of a user control.In a previous thread I had tracked down the "Object variable or With block variable not set" to the return in the Get block of a property. At the time I was only using the Set so I just commented out the offending code until I needed it.

[Code]...

The error does not occur during a system compile, only upon saving the container object of the user control. As I said the Set works correctly, only the Get causes the error.I would like to know what I am missing/misunderstanding and am open to other suggestions of handling retrieving the current value of a bindingsource in a user control.

View 2 Replies







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