Difference Between A Private, Public, Shared Functions/Sub/Variables?

Jul 22, 2009

give me a good resource that explains the difference between a Private, Public, Shared Functions/Sub/Variables? I normally use Public for Subs/Functions inside of Modules I call from other parts of the program. But I'd like to get more of an understanding of how and when to use them. I want as little as impact to a system that is running my programs as possible, so i guess the key here is I'm trying to just get more proficient in my coding.

View 8 Replies


ADVERTISEMENT

VS 2008 - Difference Between Public, Private, Protected When Declaring Functions And Subs?

Jul 19, 2009

i have have a few questions about the syntax of the lan.:

1) What is the 'Get' statement and when do you use it?

2) Whats the difference between public, private, protected etc... when declaring functions and subs.

3) When would you use the overrides property?

View 4 Replies

Difference Between Public Sub And Private Sub And Private Function And Public Function And Sub And Shared Function?

May 31, 2011

explain me the difference between them? I'm new to visual basic, and I need to know the very basic things in Visual Basic allowing me to become a professional User

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

Private / Public - Subtracting Variables

Mar 11, 2010

I am a little new to .NET Developing, and have learned a great deal recently, but I'm stuck with something. I come from an ASP Background, I'm trying to subtract 2 variables, but they don't seem to 'see' one another.

[Code]...

View 6 Replies

Public Shared SqlConnection - Used In Multiple Functions

Jan 29, 2010

I have an asp.net web app. It has a shared class, and I want to have the connection string the same through out the site. My string is in my web config, but I don't want to type this all over the place:

View 3 Replies

Private Shared Variables Vs Local / Namespace Performance

Jun 8, 2009

I came across a number of new Private Shared variables (of type Hashtables(Of String), initialized in the declaration) added to a partial class for a very large (DataContext-derived) class. This seems sensible to me in one sense because they never change, and making these shared variables ensures that they won't get re-initialized every time a function is called. However, these variables are only used within the scope of one function in the class, and I fear the private namespace of this DataContext-derived class is getting rather polluted, and having these sorts of things exposed at such a high level might be confusing to others reading the code in the future.

Would there be negative performance impact to making these local variables within the function where they are used, or is there some better way to handle this? Basically we are using these 3 hashtables to determine whether anything within particular subsets of properties changed (using GetModifiedMembers and then using the Overlaps function of the hashset to see if any of the modified members correspond to members we care about).

Edit: I caved and took the time to write my own test program, which confirmed that there is a cost to using local variables (which I assume applies generally to all cases -- I doubt there's any case where a shared variable would be slower unless using the shared variable requires some additional logic to do so properly): [Code]

So in this particular case, using the local variable costs about 200%. But in most cases (including my own), the time is probably negligible compared to the overall task. So I guess the question now becomes, how do people generally feel about improving code maintainability at the cost of negligible but known performance impacts?

View 3 Replies

Copying A Set Of Private Variables Into Corresponding Public ReadOnly Properties?

Oct 18, 2011

I have a bunch of private variables I've typed out and I want to put all of my corresponding Public ReadOnly Properties in a bunch below them.Is there some way of copying ten lines of

Private _myVar As String

and pasting in ten sets of

Public Readonly Property MyVar As String
Get
Return _myVar[code]....

I'm currently copying the whole bunch of variable declarations, Find+Replacing Private _ into Public ReadOnly Property then going line-by-line expanding the definitions and writing return statements.how to avoid all this nonsense in the future, as I'm developing on a virtual terminal server, and the input lag on my little copy/paste/type operations on the code is driving me up the wall.

View 1 Replies

VS 2008 - Comparing Variables In Private Sub With Public Class

Nov 11, 2009

I have these list of RS-232 strings declared in my public class
Public Class TouchInterface
Dim WatchTVbtnCmd As String = "rs232command1"
Dim VolUpbtnCmd As String = "rs232command2"
Dim VolDownbtnCmd As String = "rs232command3"
Dim SystemOffbtnCmd As String = "rs232command4"
Dim RadiobtnCmd As String = "rs232command5"
Dim MusicbtnCmd As String = "rs232command6"

I then have this private sub. For the sake of this thread, what I would like to do is get the name of the label that was clicked which in the code below is already done, convert it to string (not sure if this needs to be done), this is also done in the code below. Next I want to compare the labelnamestring to all the variables in the public class to find out which one it is equal to and then disply that variable which should be my rs232 string in the message box. I have also added "Cmd" to the variable names above so I also need to work out how to add the text "Cmd" to the string to properly compare.

Private Sub Musicbtn_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WatchTvbtn.Click, VolUpbtn.Click, VolDownbtn.Click, SystemOffbtn.Click, Radiobtn.Click, Musicbtn.Click, GardenVolUpbtn.Click, GardenVolDownbtn.Click, GardenRadiobtn.Click, GardenOffbtn.Click, GardenMusicbtn.Click, GardenMediaCenterbtn.Click
Dim labelname As Label = DirectCast(sender, Label)
[Code] .....

View 6 Replies

Difference Between Static And Shared Variables In .NET?

Jun 22, 2009

exact diff b/t Static v/s Shared variables in VB.NET?

View 3 Replies

[2005] SyncLock And Multithreading - Public Class Utilities With A Many Shared Functions

Feb 11, 2009

I am trying to get a handle on SyncLock and multithreading, but I am having some trouble wrapping my head around exactly how it should be implemented. I have a Public Class Utilities with a many Shared Functions. I want to make sure that each function can only be executed when there are no other concurrent calls to the same function. So If I have 2 functions, A and B in a Public Class Utilities, what is the syntax so that a function "locks" while it is being executed, preventing any subsequent calls until the "locking" thread has completed?

CODE

Public Class Utilities

Public Shared Function A (ByRef i As Integer) As Integer

[CODE].............................

I know I need to wrap the statements of execution in a SyncLock block, but I am unsure of the scope of the parameter used with SyncLock...is it private to the function, class, etc? Can the same object be used to lock both functions if they are independent?

View 36 Replies

Accessing Variables From A Public Shared Subroutine?

Feb 15, 2009

I have created a public shared subroutine in a class file in asp.net 2 (vb.net) web site app_folder.The subroutine retrives some values from a sql database via an sql query and assigns the datareader field values to several variables The problem is I can't seem to assign the variables from the subroutine to the variables and textbox controls in the asp.net page I am calling the subroutine from. The textbox text value just appear blank.By the way, if I response.write the variables in the subroutine they appear populated by the sql data reader.

View 9 Replies

Lifespan And Scope Of Shared Variables And Functions?

Jul 31, 2010

Are the following three the same upon compilation

dim x as new assigningfunction
dim x as new assigningfunction()
dim x as assigningfunction = new assigningfunction()

[code].....

View 4 Replies

Arguments / Parameters And Variables Inside Shared Functions

May 19, 2011

Well I am a new to VB.NET, converting a legacy system to .NET world. Recently I have been reviewing the already existing code since I joined the project quite late in the team. I find that there are many shared functions (not shared class) inside many classes. I doubt this may create some problem if two requests ( i.e two different HTTP request to the same method as it's a WCF application, of course exposed methods are not shared but internally called methods are shared) comes to the same shared method and both the calls to the method may have different method parameters/arguments, overwriting each other's arguments. In short, if shared method has a list of arguments which is going to be processed, is there any chance of inconsistencies in the light of multiple access to the shared method via two http requests.

View 2 Replies

Declare Public Variables, Constants, Functions In A Proper Way?

Jan 13, 2011

I'd like to get a more refined programming style and I was wondering if any of you might give me a hand...(How to declare public variables, constants, functions...in a proper way),is there any useful link or pdf document I could have a look in order to improve my style?

View 5 Replies

VS 2010 - Public Variables, Functions Are Not Visible In Form2

Jun 26, 2011

I've got a program that runs from one Windows form, Form1, with stuff declared all in that class: public variables, public functions, subs, etc. I decided that the form was getting cluttered, so I added one button to bring up a new form, Form2, and I put some of the buttons & check boxes for testing over there, so that Form1 can be more visually clean. Problem: when I go to put the code for the tests into the buttons on Form2, none of the public variables or subs or functions that reside in Form1 are visible in Form2. What statement/s do I need to add (and where) so that the public "stuff" that's declared in the class for Form1 is visible within Form2, please?

View 6 Replies

VS 2008 : Have A Class Where The Functions Of The Same Name Are Both Instance Functions And Shared Functions?

Dec 6, 2010

What I am trying to do is have a class where the functions of the same name are both instance functions and shared functions.

Public Shared Function Get...(byval xx as xx)

and

Public Function Get...

The Public Function uses a Property xx created in the constructor, whereas the Shared Function has the parameters (byval xx as xx).

View 1 Replies

VS 2008 Sharing Variables - Private Sub Could Use The Variable Created On Private Sub

Jul 23, 2010

if for example i have two private sub I declared a local variable on private sub a... is there a way that private sub b could use the variable created on private sub a? Im asking because im in a problem in my app were using global variable is not an option to make the long story short

View 5 Replies

Asp.net - Access A Module Or A Public Class With Public Shared Members From Inline Vb Code <% .. %>?

Feb 10, 2011

I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.

View 2 Replies

Can't Make Difference Between Public Class And Private Class And Friend And Protected Friend Class

May 15, 2009

I can't make difference between public class and private class and friend and protected friend class.

View 1 Replies

What’s The Difference Between Private Sub And Private Function

Dec 14, 2011

I am completely lost on procedures. Whats the difference bewteen Private sub and private function?

View 1 Replies

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

Generate Public Private Key?

Apr 12, 2010

How to generate public private key VB.net code...

View 1 Replies

Calling Private Shared Methods?

Aug 8, 2011

I have a form (frmMain) that contains a custom control (con class). frmMain contains a combo box control and when the user selects a value from it, I pass this value to a sub routine within con class (see red line below). This purpose of the sub routine is to populate a set of comboxes contained in con class according to the value that is passed in.

Private Sub cboGuidelines_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboGuidelines.SelectedIndexChanged
If bChanged = True Then

[code].....

View 6 Replies

C# - When Should Use Public / Private / Static Methods

Apr 27, 2009

I'm new to C#.Till this moment I used to make every global variable - public static.All my methods are public static so I can access them from other classes. I read on SO that the less public static methods I have,the better.So I rewrote my applications by putting all the code in one class - the form class.Now all my methods are private and there's no static method.

My question: What should I do,keeping everything in the form class is dump in my opinion. When should I use public,when private and when static private/public? I get the public methods as a 'cons' ,because they can be decompiled,but I doubt that.My public methods can be decompiled too.What is so 'private' in a private method? EDIT: I'm not asking how to prevent my program to be decompiled,I'm asking whether I should use static,private and public.And also : Is there are problem in putting all the code in the form class so I dont have to use public methods?

View 6 Replies

Convert From Private/public .pem File?

Jul 27, 2010

It is possible convert a private / public rsa key from a .pem file in vb.net ? to xml file.

View 1 Replies

Have The Get Part Of A Property Available As Public But Keep The Set As Private?

Sep 22, 2009

is there a way to have the Get part of a property available as public, but keep the set as private?Otherwise I am thinking I need two properties or a property and a method, just figured this would be cleaner.

View 3 Replies

Make A Dataset From Private To Public?

Jul 5, 2011

basically how do I make my dataset public so I can access it on another form.

Dim ds As New DataSet("Dataset1")
Dim filePath As String
OpenFileDialog1.ShowDialog()
filePath = OpenFileDialog1.FileName
ds.ReadXmlSchema(filePath)

[Code]...

View 2 Replies

Make A Property Public Get But Private Set?

Apr 25, 2009

I just stumbled over this in some C# code...:public Foo Foo { get; private set; }

View 2 Replies

Private And Public Interface Implementation In VB Not In C#

Oct 27, 2009

Private Sub ActivateMe(ByVal active As Boolean) Implements IGraphicControl .ActivateMe compiles.How is possible in VB.NET? A private method can be an interface implementation. VB.NET... a lot of compliments to this language and IDE..

View 6 Replies







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