Getting Data From Shared Function To Instances

Jan 24, 2011

VB.NET 2010, .NET 4. I am working on an application for controlling an industrial machine composed of many devices attached to the computer. Most if it is reasonable straight forward, but I'm having trouble thinking about the RS-232 devices. One of the RS-232 devices is a fancy power supply with many functions. The ones that are relevant right now are voltage read, voltage write, current read, and current write. The design pattern I'm trying to implement is one in which each attached device is represented by an object that has methods for reading/writing etc and properties for things like COM port etc.

For this power supply, clearly the Port reference should be shared among the instances, so I have a base class (say, PowerSupply) with a Protected Shared Property Port As IO.Ports.SerialPort. Then I have a couple classes that inherit from this class, PowerSupplyVoltage and PowerSupplyCurrent that each define read/write methods and properties for holding the last read/written values. My issue is in parsing the response from the power supply using the Port.DataRecieved event on the shared SerialPort object. The protocol the power supply uses specifies what data it's sending in each response packet.

So, basically, it might say something equivalent to "The voltage is 100V" or "The current is 1A" or "The voltage has been set to 150V" etc. I'm trying to parse this in a shared function. Only during the parsing process would I determine which instance's read/written value to update. I can't access the read/written value properties of the instances from within the shared function. The best I could think of is creating some kind of PowerSupplyCommunicator object that would maintain references to PowerSupplyVoltage and PowerSupplyCurrent instances along with the shared Port and DataRecievedHandler functions.

View 1 Replies


ADVERTISEMENT

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

Shared Property Is Used For All Application Instances?

Mar 17, 2010

i have an multi-threading applicaton. so I am using system.threading.thread class to create thread. each threads call its own class and inside each class i am accessing webservices. I need to have status returned from each webservice. thats why I defined a shared property as list of generic object which will be updated within each class called its thread. but I have an hesitation that when I run application on the server. this shared object will be used by all instances of web application. Is it true or shared properties is used only for its own instance?

View 5 Replies

Accessing The Shared Function?

Mar 1, 2011

i have a function that i have in my data access class now i want to access it then declare and assign parameters and then insert data into database?

'1
'the function
Public Shared Function InsertNewRecord(ByVal myStoredProcedure As String) As Boolean
Dim conn As New SqlConnection

[code]....

View 4 Replies

Finding Basic Shared Function?

May 31, 2009

i am beginner about general programming. Please give me basic shared functions .

I only know few functions such as : Public Shared Function lon(ByVal a As Integer, ByVal c As Integer) As String Public Shared Sub trung()

View 1 Replies

LoadControl In Static / Shared Function

Dec 30, 2009

how I can dynamically load a control inside of a shared/static function?The function itself is inside of a mustinherit/abstract class.(It's an ASP.NET project in VB) I want to do something like this:[code]I'm getting "Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.",but I don't understand this error.I understand what it means, I just don't understand why calling LoadControl isn't seen by the compiler as being an explicit instance of the class. What's not explicit about using LoadControl to create a new control from a file? I tried creating a new user control and initializing it, then setting it to a different control with LoadControl to no avail.I also don't want to do a DirectCast because I'm trying to put this in a shared, mustinheret (abstract) class, which therefore doesn't have an .aspx file to write in a <%@ Reference Control="~/SomeControlPath.ascx" %>, so the class name is unavailable.What I'm trying to do is write a static function that takes some value and returns a control based only on that control's source file location.The end result is a user-modifiable list of controls.They get a column of controls that they freely add, remove, or reorder based on a static list of available child controls that I specify.

View 4 Replies

Make A Shared Function Generic?

Feb 16, 2011

I can create classes that use generics, however I was wondering if it is possible to apply this to a shared method rather than rely on the caller casting to the correct type.This is the method:

Public Shared Function DeserializeObject(ByVal serializedXml As String, ByVal givenType As System.Type) As Object
Dim serializer As New XmlSerializer(givenType)
Return serializer.Deserialize(New IO.StringReader(serializedXml))
End Function

I'm pretty sure this can't be done, but thought I'd check (if so Extra points will be awarded if someone can technically explain why the compiler can't do this)..

View 3 Replies

Public Shared Function Continued?

Aug 6, 2009

I made the changes from this:

[code]...

to this:(the 'End Function' says "Function 'GetFolderPath' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."

[code]...

View 4 Replies

Select Case Shared Function?

Mar 29, 2010

xplain to me or give me an example of using a select case in a shared function

View 2 Replies

What's Advantage Of Declaring A Function As 'Shared'

Jan 27, 2009

What's the advantage of declaring a function as "Shared"? I've noticed that it doesn't require you to instantiate an object to use the method when it declared as "Shared". Is that the only upside?

View 3 Replies

Accessing Public Shared Function From Another Form

Mar 1, 2011

[Code]...

i have a function that i have in my data access class now i want to access it then declare and assign parameters and then insert data into database.

View 4 Replies

Asp.net - Calling Other Functions From A Shared (or Static) Function

Aug 20, 2010

I get this error: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _

[Code]....

I know it has something to do with the fact that the first function is shared and the second function should probably be Public as well but I don't fully understand the reason behind it. Probably not relevant but I'm calling the web method from some javascript.

View 1 Replies

How To Call Function Inside Private Shared Sub

Jan 24, 2012

I have as sub that is triggered from the file system watcher when the new file is created in spec. directory.I need to call some function to do something with that file. [code]

View 6 Replies

Shared Function And Mysql Stored Procedure?

May 11, 2012

i created a dll file using vb.net then it has a shared function that will execute a stored procedure of mysql but my code is something long and when accessing it, it has a big risk that it can produce an error if there is an incorrect string input, i am asking an advice how i can make it much better or can point me something much better than my code as my reference.here is my codefirst i created a function named mysqlParamDatatype wiith 1 parameter, this function will detect the mysqldatatype of the mysql sproc parameter so it can pass the value with the correct datatype. but it is to long.

Shared Function mysqlParamDataType(ByVal i As Integer) As MySqlDbType
If i = 1 Then
Return MySqlDbType.Binary

[code].....

View 1 Replies

.NET Shared Function If Called Multiple Times Simultaneously?

Mar 25, 2010

Consider I have a shared function:Public Shared Function CalculateAreaFromRadius(ByVal radius As Double) As Double

[Code]...

If I have two or more threads in the same vb .net app and each of them calls the shared function at the same time with different RADIUS, will they each get their own AREA? I want to know for each call to the function if it is using same local variables or each call creates new instances of local variables?Will the answers to above questions be same If I have multiple (2+) single threaded apps and they all call the function at the same time with different RADIUS value?

View 2 Replies

Asp.net - Accessing Httpcontext In Shared Function Thread Safe?

Jan 5, 2012

Im having a problem understanding if accessing httpcontext inside a shared function, without passing in the httpcontext as a parameter is thread safe?

Are the 2 functions in the util class equally thread safe?

Class foo
Sub main()
Dim qs1 = util.getQS(HttpContext.Current)

[Code]....

View 2 Replies

Asp.net - AutoCompleteExtender WebService Fail To Be Called When Function Is Shared?

Oct 25, 2011

I had a problem (which is now fixed) but I've no idea why.I have an Ajax AutoCompleteExtender with a WebService method to populate like <WebMethod()> _
Public Shared Function populateACE(prefixText As String) As List(Of String) However this didn't work - I put a breakpoint in, and it didn't even get hit. However... <WebMethod()> _ Public Function populateACE(prefixText As String) As List(Of String) does work (the only difference being not Shared).

Fair enough, but why? If you have an instance of a class then you can access Shared methods of it; if you don't have an instance of a class then you can access Shared methods of it. So what is going on behind the scenes?

View 1 Replies

Get A Query String From A Shared Function In A Code-behind Model

Dec 10, 2009

I'm trying to get a query string from a shared function in a code-behind model using VB.NET. You have to use HttpContext.Current.Request.QueryString("Query") in order to get it from a shared function, however doing HttpContext.Current.Request.QueryString.Count gives back 0, which obviously isn't right in my case as there's many that exist. Is there some sort of issue with using this static call from a shared function?

View 1 Replies

Passing/Infering Type Through Shared Function Calls?

Dec 6, 2010

how to pass system.type or a generic without much luck. I have two functions below one that works and the other that doesn't. I can't seem to make heads or tails of the VB syntax required for doing what I want to do.

' This function does not
'
' Also attempted it like this

' Public Shared Function UnserializeFromJSON(ByVal obj As String, ByRef ty As System.type)[code].......

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

Threading In Shared Function GetCurrentThreadId Obsolete/deprecated?

Aug 13, 2007

Here is a VB.NET Console module I'm testing to understand how Multi-Threading/Threads work.

Imports System
Imports System.Threading
Module Module1
Public Class SimpleThread
Public Sub SimpleMethod()

[Code]...

View 3 Replies

API Function To Find Username Of Shared Files Or Folders On Network In C# Or .net?

Nov 19, 2010

With the help of NetFileEnum or Openfiles.exe of system32, we can get the username who has opened the shared files. Is there any API function or any exe files in any programming language like c#, vb.net, visual c++ to find out who is the user to create, rename, or delete shared files or folders on the network?

View 1 Replies

Windows - Difference Between (Protected / Partial) And (Friend / Shared) And (Sub / Function) On .NET?

Jun 4, 2012

When I find examples online of VB.NET watch some functions use:

(Protected / Partial) & (Friend / Shared) & (Sub / Function) exp()
End (Sub / Function)

what is the difference?

View 1 Replies

Sync Data Between Two Instances?

Sep 13, 2010

I have a small "Clinic Application" that runs on two machines. (Receptionists & Doctors)

Same application is installed at both the computers, and they access the same SQL Server 2008 Data at a 3rd macine.

When the application is started, the local datasets are filled with the data from the 3rd machine (using tableadapter.fill).

Whenever the Receptionist adds a Patient in DataGrid,and saved it, it should show in Doctors DataGrid. and whenever Doctor adds something, the receptionists dataGrid should show it.

to accomplish this I have set a timer that keeps Filling datasets.

the task is successfully accomplished, but....

View 12 Replies

Make A Shared Function For Form Load In A Separate Class File?

Jan 9, 2012

i would like to have a shared function in a separate class file to address the form location . but i dont know how can i get this to work. if i use this below code in my form its working . but i cannot move this to a class file.

Shared Sub Formlocation()
Me.StartPosition = FormStartPosition.Manual
Me.Location = Screen.GetWorkingArea(Me).Location
End Sub

View 2 Replies

Shared Functions - Two Threads Both Calling A Normal Function At The Same That Appends Strings

Dec 6, 2009

If I have two threads both calling a normal function at the same that appends strings, sometime the output string is a combination from both threads as the function had not finished executing the code before it was called again... Would a shared function wait to finish first?

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

DB/Reporting :: Updating Client Data Tables When Data Table On Shared Drive Is Updated?

Sep 28, 2009

I would like to know the best, or standard, way to accomplish real-time client updates in a small multi-user application using an access data table as a data source.Specifically, this application will be used by 3-4 people. It uses a datatable which is filled on form load and bound to a datagrid at design time. The datatable is stored on a shared drive. The data table on the shared drive is updated in two ways:

1) Users can update the datagrid which then updates the datatable on the shared drive via the data adapter's Update method.

2) A server application does some work on some text files, periodically updating the data table.

I need the clients to reflect the changes to the data table on the shared drive as closely to real-time as possible. I know that the data table stored in memory on the client is disconnected from the data table on the shared drive, so I must query again to get the updates.

1) Is there an alternvative model I can use which is connected, and which will automatically reflect the updates in the data table on the shared drive?

2) If not, what is the best way to check for changes in the data table (so I can know when to call the data adapter fill method)? I am planning to poll the drive for a change to the .mdb file, raise an event and then fill the data adapter when the event is triggered. I am using this method successfully now to check for changes to a text file in another application, and I know how to implement it?

View 1 Replies

VS 2005 Updating Client Data Tables When Data Table On Shared Drive Is Updated

Sep 28, 2009

I would like to know the best, or standard, way to accomplish real-time client updates in a small multi-user application using an access data table as a data source.

Specifically, this application will be used by 3-4 people. It uses a datatable which is filled on form load and bound to a datagrid at design time. The datatable is stored on a shared drive. The data table on the shared drive is updated in two ways:

1) Users can update the datagrid which then updates the datatable on the shared drive via the data adapter's Update method.

2) A server application does some work on some text files, periodically updating the data table.

I need the clients to reflect the changes to the data table on the shared drive as closely to real-time as possible. I know that the data table stored in memory on the client is disconnected from the data table on the shared drive, so I must query again to get the updates.

I have two questions:

1) Is there an alternvative model I can use which is connected, and which will automatically reflect the updates in the data table on the shared drive?

2) If not, what is the best way to check for changes in the data table (so I can know when to call the data adapter fill method)? I am planning to poll the drive for a change to the .mdb file, raise an event and then fill the data adapter when the event is triggered. I am using this method successfully now to check for changes to a text file in another application, and I know how to implement it

View 5 Replies

Argument Not Specified For Parameter 'test' Of 'Public Shared Function TestThis(test As String)'?

Sep 25, 2010

I don't understand the error, Argument not specified for parameter 'test' of 'Public Shared Function TestThis(test As String)'.

Partial Public Class Form1
Shared Sub ReceiveCallback(ByVal ar As IAsyncResult)
Form1.Invoke(TestThis, New Object(){"test"}) 'error

[code].....

View 6 Replies







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