.net Store Reference Of Variable In Another Class?

Dec 25, 2011

Class1:

Dim v as integer
public sub storeVar(byval s as integer)
v = s
end sub

[code].....

I need to save a reference of variable s in Class2 in variable v in Class1.(i.e. when the value of s changes v also changes (and vice versa)Is this possible since vb.net doesn't have pointers?Will it work if I change "byval" to "byref"?

View 1 Replies


ADVERTISEMENT

Use CType To Change An Object Variable "obj" To Custom Class That Reference Using A String Variable Like Obj.GetType.Name?

Feb 9, 2011

The code below works for the class that I hard coded "XCCustomers" in my RetrieveIDandName method where I use CType. However, I would like to be able to pass in various classes and property names to get the integer and string LIST returned. For example, in my code below, I would like to also pass in "XCEmployees" to my RetrieveIDandName method. I feel so close... I was hoping someone knew how to use CType where I can pass in the class name as a string variable.

Note, all the other examples I have seen and tried fail because we are using Option Strict On which disallows late binding. That is why I need to use CType.I also studied the "Activator.CreateInstance" code examples to try to get the class reference instance by string name but I was unable to get CType to work with that.When I use obj.GetType.Name or obj.GetType.FullName in place of the "XCCustomers" in CType(obj, XCCustomers)(i)I get the error "Type 'obj.GetType.Name' is not defined" or "Type 'obj.GetType.FullName' is not defined"

'+++++++++++++++++++++++++++++++
Imports DataLaasXC.Business
Imports DataLaasXC.Utilities

[code]....

View 2 Replies

Declaring Class Variable As A Reference?

Apr 5, 2011

I have a class that I would like to link at construction to a given control (say a textbox)

I know I can put a variable into a subroutine referentially but is there a way to store it in the same capacity?

View 1 Replies

Pass Variable By Reference And Set Object To Reference?

May 26, 2010

I pass this class i created a variable by reference and i want that reference to be assigned to m_Text so that when i change m_Text it changes the TextValue variable i passed. Example:

Dim test2 as String = "ok"
Dim test as New GeneTextBox(test2)

'then some one changes the text in the GeneTextBox and i want it to change the test2 string...

Public Class GeneTextBox
Inherits Windows.Forms.TextBox
Private m_Text As String
Public Sub New(ByRef TextValue As String)

[code]....

View 1 Replies

Error - Create A Class Called Invoice - Hardware Store Use To Represent An Invoice For An Item Sold At Store

Apr 15, 2012

"Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables--a part number (type String), a part description (type String), a quantity of the item being purchased (type Integer) and a price per item (Type Integer). Your class should have a constructor that initialize for each of the four instance variables. Provide a property for each instance variable. If the quantity is not positive it should be set to zero. If the price per item is not positive it should be set to zero."

I attached the code I have. obj is underlined and says "Argument not specified for parameter 'Invoice4' of the 'Public Sub New (Invoice1 As Object, Invoice2 As Object, Invoice3 As Object, Invoice4 As Object)' and so the program won't run. What am I doing wrong?

Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim obj1 As New Invoice(Val(TextBox1.Text))
TextBox1.Text &= obj1.Invoice1 & vbNewLine
TextBox1.Text &= obj1.Invoice2 & vbNewLine
TextBox1.Text &= obj1.Invoice3 & vbNewLine
TextBox1.Text &= obj1.Invoice4 & vbNewLine

[CODE]...

View 14 Replies

.net - Variable 'cl' Is Passed By Reference Before It Has Been Assigned A Value For DataView Variable?

Feb 1, 2012

I have the following code passing a dataView variable to a function and I am getting the following warning:"Variable 'cl' is passed by reference before it has been assigned a value. A null reference exception could result at runtime."

Function Editclass()
Dim cl As DataView
Bindclass (SqlConnection2, cl)

[code].....

View 1 Replies

Store Variable Data Into Another Variable?

Feb 4, 2010

How can I store the value of a variable into another variable that wont be changed unless it meets certain criteria

View 1 Replies

How To Assign A Different Reference To A Class Instance From Inside The Class Code

Jan 18, 2011

my proble is the following: I have a class MyClass and another class Modifier, which has a method ModifyMyClass(ByRef mc as MyClass) that receives a MyClass instance as ByRef parameter to modify it. A smell of the code is:

[Code]...

View 4 Replies

VS 2008 Reference Parent Class From Inside Child Class?

Apr 11, 2009

I have a 'property management class' that contains several functions and properties. I have several other classes that use the 'management class' as a property to derive the value of several of its other properties.Is there a way for me to reference the outer class from the 'management class' functions without having to pass it as a parameter? I ask because several different classes can have this 'management class' as a property and am having a hard time typing the parameter.

View 7 Replies

Forms :: Store The Reference Passed To A Sub?

Aug 6, 2010

I've searched a lot on both google and here but sorry, couldn't find.Maybe I'm just asking the wrong question, so I'll try to explain it here to see if someone can help me:

what I'm trying to do is what in C would be as simple as int varptr = &var I have a form that is just a communication watcher/logger. It's just a blank text box with a Pause/Play button and a copy to clipboard button and every new activity on my serial communication is logged. At the moment the form have a timer that once a second do textbox.text = serial1.log ...

but the problem is that I also have serial2; serial3; sql1 that I would like to keep an eye on them, and considering my work here I'm sure I would be re-using this form a lot if I could make it portable. Create one form for each is just stupid, as you'll all agree.

Then I would like to have an sub initialise(byref log as string) that would store this reference into an local variable within the form; so that every new instance of my form could be initialised with whatever log they'll be looking for and the timer just make textbox.text = LogPointer to the actual value of the log string.So, as I said I really wanted a int varptr = &var

View 4 Replies

Class With Class Properties: AObject Reference Not Set To An Instance?

Aug 19, 2009

I have a class in which some of the fields are also classes.I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"But the code compiles fine.

dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition
dados_Defenicao.arCode = "123"
dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error

How can i fix this ?

View 6 Replies

Class With Class Properties: Object Reference Not Set To An Instance

Aug 19, 2009

I have a class in which some of the fields are also classes.

I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"

But the code compiles fine.

dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition
dados_Defenicao.arCode = "123"
dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error

View 4 Replies

Get Base Class Object Reference Outside The Class's Definition?

Dec 10, 2010

If we are within the derived class then ofcource we can use MyBase keyword to access base class's object reference . That's fine , how can we take that base class's object reference outside that derived class's definition.My following code will explain what i want . Actually that is giving error right now, but it is explaining my requirement .

Public Class Base
Public x As String
End Class

[code]....

Actually there is error in ReadOnly Property BaseReference's Getter . Error is "Error 1 'MyBase' must be followed by '.' and an identifier. " how can i get base class object reference in Main method ?

View 1 Replies

Reference A Parent Class Object From A Child Class?

Jan 2, 2010

I have a Parent Class Called Fuselage that containsfour child classes called Forebody, CenterBody, AftBody, and CrossSection. CrossSection classcontains objects common to Forebody, CenterBody, and Aftbody (example: width). How do I access thewidth property in CrossSection from within the classForebody?

Public Class Fuselage
Dim Forebody As ClsSection
Dim Centerbody As ClsSection

[code].....

View 6 Replies

Get A Reference To The Class That Creates An Instance Of Another Class?

May 20, 2010

I need to create a new instance of a class that needs a member of the calling class. But i can't pass a reference to the calling class through the constructor.The solution i am looking for is something like this:

Public Class ChildClass
Public Sub New(args)
_MyMember = GetMemberFromCallingClass()

[code]....

I want this to work without having to manually pass any references or variables from the calling class to the new instance of ChildClass.

View 2 Replies

Store 23:23:30 In A Variable?

Apr 14, 2009

i have 23:23:30 in a texbox and i like to store this in a variable ,if i put a variable m1 as decimal, i have a message error,if i put string , i have 0 and not 23:23:30,why?

View 11 Replies

Store Value From One Variable To Another?

Mar 11, 2010

How can I store the value of a variable into another variable that wont be changed unless it meets certain criteria

View 2 Replies

Class Inheritance Object Variable Or With Block Variable Not Set?

Sep 26, 2011

i had a class called Tag with a structure like:

public class Tag
private _members
public properties
public shared database_methods
end class

this class was tailored for mysql database. i'm currently adding access 2007 support so i split tag into tag and tagdata with structures like:

[Code]...

View 2 Replies

Inside The Service Class, Declare A Class Variable Named Started?

May 8, 2012

Create a class named Service. Inside the Service class, declare a class variable named Started. The datatype of this variable is Boolean.Public Class Service Dim started as Boolean End Class Create a class named Server. Inside the Server class, declare a dynamic array that can contain elements of the type Service.(Note: For convenience, both the array and the variable Started can be accessible from a client program that creates an instance of Server and Service respectively)

Create a constructor for the Service class. When the constructor is executed, it will set the value of the class variable Started to True. Create two new classes: WebServer and DatabaseEngine. Both of these classes inherit from the class Service. Inside the Service class, declare a Sub procedure (method) named Terminate. This method should display the following text Service stopping in a message box when executed.This method can be overridden in classes that inherit from Service class.

Inside both the WebServer and DatabaseEngine class, override the method Terminate inherited from their base class Service. Both methods should first call the base class Terminate method. The messages Web server stopping and Database engine stopping should also be displayed in a message box when the Terminate method for the WebServer and DatabaseEngine are called respectively. These messages should only be displayed if the Started variable inherited from their base class is not equal to False.

Inside the Server class, declare a method named Shutdown. This method does not return any value. When executed, it will call the Terminate method for each of the Service instances (if any) in the arrServices
array. You should call the Terminate method within a For Each loop that loops through the elements of the arrServices array.

In the Sub Main method, create an instance of the class Server. Set the size of the arrServices array in
your Server instance to contain 2 elements. Create first a WebServer instance and then a DatabaseEngine
instance into this array. Call the Shutdown method from your Server instance.

View 7 Replies

Unable To Use An Instance Of The Nested Class Through A Public Variable Of The Parent Class?

Jun 7, 2012

I want to created a nested class that can only be visible to and instantiated from the parent class.But I also want to be able to use an instance of the nested class through a public variable of the parent class.I tried making the nested class private, or making the nested class' constructor private, but it won't compile.Is it possible to do this in .NET?

[Code]...

View 3 Replies

Min Date To Store In Variable In .net?

Jan 1, 2012

I got Minimum date from database using sql qry, And when i try to store that min.date in one variable, its getting error, PlZ help me. for below coding.

Dim qry as string
Dim Min_Date As Date
If SqlCon.State = ConnectionState.Closed Then
SqlCon.Open()

[code]....

View 2 Replies

Store / Appear In A Variable - A Textbox Value?

Feb 2, 2009

Can someone give me a simple example on how can I store/appear in a variable/or a textbox a value that i retrieved from a database. The sql query is something like "Select Comment from Params where id =1".

View 5 Replies

Store ByRef In A Variable?

Jun 4, 2009

Just wondering if it's possible to store a reference to an object in a variable.

I will elaborate:

[Code]...

View 5 Replies

Store Operators In A Variable And Then Use It?

Apr 22, 2010

Can I store the common operators such as '>', '<', '+' etc., in a variable and then use it when required.

[Code]....

so here instead of directly using > and +, Can I use the variables OP1 and OP2 somehow. May be I can put the entire string from "If..... NUM1" in another variable as text string and then execute that variable.

View 1 Replies

Store The Location As A Variable?

Nov 7, 2009

I have a program where I open files and I store the location as a variable so I can reopen them later on. It works much like MS Word does, where it shows the names on the side and when I click it and open, it will open the file. Mine is a little different because it will store large numbers of file names in a list box because people are usually going to open folders full of files. The initial way I did it had the path name stored in a list box and it would open the file using that path. I decided it was a bad idea and I tried to use just the name of the file. However, I ran into a problem with the code that I was using.

Code:
If its checked, it will open the selected item from the list box instead.
If CheckBox1.Checked = True Then
'for all the indexes of the saved location record of array, if the selected item is found, then open that file
For counter = 0 To SavedLocations.GetUpperBound(0)

[code].....

So as you can see, what I have is it decides whether you opened from the list box or not. If it is not from the list box, it opens it up fine. It adds the information to the list box and stores some information in an array so I can access it later on. If it does open from the list box, then it will search for the file name in the array. If it finds it in the array, it will proceed to open the file using the directory. There is no else clause because it should be finding it 100% of the time.

The error I get is that parameter cannot be null. Filename2 never seems to get assigned, which means it's not finding the value in the array. I've tested and the value is in the array and the values are the same values.

View 4 Replies

Store The Previous Value In Another Variable?

Feb 2, 2010

'ValueNow is updated by an external link eg ADO.NET
Dim PresentValue as Decimal
Dim PreviousValue as Decimal

[Code].....

View 6 Replies

[2008] Null Reference Error - Store Values In Arraylist Permanently

Jan 22, 2009

I have a module and form. Module has a structure.

[Code]...

Actually values are not stored in that array list permanently. its storing temporarily and then destroying. i want to store that values in that arraylist permanently.

View 28 Replies

Can't Set DataTable Class Level Variable = Class Table Property?

Sep 29, 2011

I have procedure (Import) that calls a for a new instance of frmImportData. I also have a class name clsBatch that has a data table property called prpParametersTable.For some reason, I get an error (indicated below with ERROR>>>) when trying to assign prpParameterTable to cv_dtImport2. The error states "Object reference not set to an instance of an object.". Why does this error not happen when I assign dtBP to cv_dtImport1? Both cv_dtImport1 and cv_dtImport2 are equal to Nothing and in my Import procedure dtBP = prpParametersTable.

Public Sub Import(ByVal clsB As clsBatch)
Try
Me.cv_clsB = clsB

[code]....

View 5 Replies

Class Property Usage - Unable To Retrieve A Variable From On Class

Nov 14, 2009

I have three class files, accounts.vb and transactions.vb in addition to my form.vb. I am unable to retrieve a member variable from on class from inside the other. When the combobox index changes, the program loads the correct account (checking or saving) from two different sequential files. I don't think I have the calcBalance procedure in the correct class file. And that is what I am having trouble with. Accessing it to display it. [Code]

View 1 Replies

.net - Store Data In One Variable Or Multiple?

Jan 30, 2010

I have a file which is opened and the bytes are loaded into a class.The file needs to be split into chunks, and there is a header which gives the locations and sizes of the chunks.Should I (upon opening the file) split the file into chunk sand store each chunk in an array of variables And then when I want to access the data in the chunks I just use the array.

or store all the chunks in one variable together and then when I need access to the chunks get the location and size of them and use that to find chunks each time I need to modify them.

View 1 Replies







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