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


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

.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

Declaring Each And Every Variable

Apr 26, 2011

Trying to declare some arrays. I haven't worked with them that I remember. I always took the long road, of declaring each and every variable, but would like to learn this method. The problem is I'm having trouble with the methods I'm finding on the net..[code]for some reason there is a squiggly under each MonsterName except in the declaration that says "declaration expected"

View 16 Replies

.net - Declaring A Byte Variable?

May 30, 2012

We can declare a byte variable like this, for hex '88'

Dim bytes = New Byte() { &H88 } My case, 88 is assigned to a variable, hexvalue

How to declare the byte with the variable hex value?

Dim bytes = New Byte() { &H & hexvalue }the above throws syntax error.

View 2 Replies

.net - Declaring A Variable As Byte

Feb 19, 2011

I'm trying out a program which I found on the net. Why is it necessary to put to curly braces at the end of the statement? It gives an error: "Byte has no constructors". Dim data As Byte() = New Byte(1023) {} I can't put the code like this either, it produces the error "byte cannot be a 1-dimensional array".

[Code]...

View 2 Replies

Declaring A String Variable?

Mar 29, 2012

if this silly but I am trying to declare a string variable by the following line

[Code]...

View 2 Replies

Declaring A Variable For Form And Using It?

Feb 8, 2010

I have declared this variable in a module : Public GenericForm As System.Windows.Forms.Form

and then through code I can asign to that variable a specific form .For example GenericForm = Form1. Then I can use that variable to handle that specific form , for example :

GenericForm.Show

My problem begins when I want to handle a control on that form , for example :

GenericForm.TextBox1.Text = "aaa"

This code creates an error reading :TextBox1 is not a member of System.Windows.Forms.Form.I have been using code like this in VB6 and was quite useful ,but now in VB .NET I cannot .You see I have many forms on which there are some text boxes with the same name,so I declare a generic variable as Form and accordingly insert the code the desired text box conform the form I wish each time . Can I do this in VB .NET too ?

View 23 Replies

Declaring Variable Dynamically In .net?

Dec 21, 2011

I have started using the builder class to create my connection strings for the sole purpose of making more generic connectivity code. However, I am stumped on this issue. The MS eConnect product apparently expects to receive integrated security=SSPI in its connection string if you want to use integrated security, (vs Integrated Secturity=True). I thought I would just pass "Trusted_Connection"="SSPI" to the builder class.

as it turns out, the item for Integrated Security is boolean and despite what the documentation says, will not give me SSPI in my connection string. Has anybody else found this issue and is there a simple fix for it? as for now, I'll simply strip out the item and replace it in my string.

View 3 Replies

Declaring A Variable And Setting It Correctly?

Nov 4, 2010

I'm having a problem declaring a variable and setting it correctly.

BEGIN WORKING CODE:

private sub doSomething
Dim tokenHandle As New IntPtr(0)
Dim dupeTokenHandle As New IntPtr(0)

[Code].....

View 1 Replies

Declaring A Variable Length Array?

Apr 26, 2010

I am new to VB.NET but used to write a lot of code in VB 6.

How do i declare a variable length array in VB.NET?

In VB6, i would just put:

Dim sArrayList() As String

But when I do that in VB.NET, it highlights my array name and says "unused local variable". What do I need to do to get it to work without an error?

View 2 Replies

Declaring A Variable TableAdapter On A Form

Aug 15, 2011

I am building a generic search form in my application. This will allow the user to search for various records throughout the application. The one thing I cannot seem to figure out is how to allow the declaration of the TableAdapter to change at run-time. Each part of the app will be passing a variable to the search form to specify which table should be loaded. In the form class I have the following:

FRIEND WITHEVENTS tbaSearchData AS database.databaseTableAdapters.TableOneTableAdapter This is great for TableOne. But, I have about a hundred tables that could be searched through. To load the data I'm using a DataGridView and populating it via a private method.

View 2 Replies

VS 2008 - XML Xdocument - Declaring The Variable

Apr 18, 2010

I've got

Option strict ON
Option explicit ON

How should I declare the variable:-

Dim bounds as? = (From item In xml...<bounds>

[Code]

View 7 Replies

Declaring A New Class Within A Sub?

Feb 22, 2011

Ok, basically i have 3 different classes: one is a NormalUser, one is a SuperUser, and one is an Administrator. I have on one of my form loads an if statement like this:

If frmLogin.lstCurrentUserData(frmLogin.lstCurrentUserData.Count - 1).Contains("Normal") Then
Dim player As New NormalUser

[Code]....

So based on an item in a list, i want to create a new instance of that class to be my player. now i know that code doesn't work, because the variable is only present within the if statement. my question is, how can i declare "player" as a new instance of the correct type, and still be able to access it in other subs?

View 10 Replies

.net - Getting An Advantage To USING Versus Declaring A Context Variable?

Nov 5, 2009

These two snippets do the same thing - is there one that's better than the other, or is it just a matter of preference?

Using context As MyDatabaseDataContext = New MyDatabaseDataContext()
Dim test = context.Employees.Count
End Using

vs.

Dim context As MyDatabaseDataContext = New MyDatabaseDataContext()
Dim test = context.Employees.Count

View 6 Replies

Asp.net - Declaring A Global Request.ServerVariable Variable

Jul 7, 2011

After many many years of using Classic ASP, I am attempting to delve into the world of ASP.Net using VB. I have gotten way to use to being able to declare variables on a page, inlclude that file and use it everywhere. I am struggling to declare a global variable. I just need

[Code]...

View 2 Replies

Declaring A Variable Of Type Interface And Object

Oct 19, 2010

what is the difference between declaring a variable in this way

ByVal
List As IEnumerable as
a parametre in a function
Dim

[Code]....

View 1 Replies

Declaring Private Variable - Automate Properties?

Sep 28, 2009

I come from C# (use VS 2005, .NET 2) and I know that when I declare a private variable I can "extract" from it the corresponding "property". In VB.NET I've declared a lot of properties (in the diagram class designer). Now am I forced manually adding the corresponding private fields?

View 4 Replies

Declaring Fixed Length Variable Arrays In Structure?

May 25, 2012

How do I declare a fixed length variable arra

Structure MyInformation
<VBFixedString(4),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=4)> Public ReturnStatus As String

[code]....

View 2 Replies

Declaring Object Variable - Inactive During Initialization Of Module?

Feb 16, 2012

Got a question regarding declaring a variable. Basically I have a module that writes to a text file using textwriter which is declared for the whole module to use at the top of the code. But what I want to do is clear the contents of the text file when the program is executed (using file.writealltext). The problem I have is that the file is obviously already in use as a result of the textwriter and the file cannot be modified because of this.

My question is: is there any way of declaring the textWriter object later on (not during the initial initialization of the module) without passing the object between functions? Setting the variable as inactive or something along those lines during initialization would be ideal.

View 1 Replies

Declaring New String At Top Of Class?

Nov 23, 2009

I had a problem with CLR profiler. But it worked eventually and the results were outstanding. My app took 47 milliseconds to run before and after some adjustments CLR profiler runs in 6 miliseconds! This had to do with String values in a resource file which apparently takes a lot of time. So this got me thinking, isn't it more effective if you would declare 1 String at the top of your class and constantly change it throughout your code? Instead of creating a new String in a method when you need it.

Instead of using:
Dim text = "blalblalba"
You would do this everytime you needed a string:
text = "blalbla"

My question is... What exactly happens when you say text = ""? Does .net create a new String? It looks like you replace the text but what happens in the background? Would it be faster then declaring a new string?

View 3 Replies

Declaring Variables In A Class?

Mar 5, 2010

What's the proper way to declare variables in a class? I've been doing something like:

'in a class
public shared teststring As String = "first"
'on a code behind

[Code]....

with shared variables loading a second window or reloading the page (without clicking the button) renders the hello world string. so how do I declare variables in a class but make it per instance?

View 5 Replies

How To Use A Class Without Declaring Object

Mar 30, 2011

I'm trying to develop a class in VB .NET in order to manage a language globalization stored in a database and editable by the user.What I need is to know what kind of class I need to declare in order to use it without declaring a new object. For example, the way My.Settings is used.

One of the goals is that in some project the developer imports the reference and after that access directly to a property. For example: My.CustomLanguage.GetWord("Hello") without declaring objects.

Is this possible? And if it's what is the best way to aproach it?

View 3 Replies

Gained By Using The Function Itself To Hold The Return Value Instead Of Declaring A Local Variable?

Oct 28, 2010

What's best practice (in VB.Net):

Function GetSomething() as String
GetSomething = "Here's your string"
End Function
or
Function GetSomething() as String
Dim returnString as String = "Here's your string"
Return returnString
End Function

Obviously, neither of these implementations make any sense, but they're just meant to illustrate my point. Is there anything to be gained by using GetSomething itself to store the return value instead of declaring returnString locally and then returning that (does it avoid having an extra string allocated/instantiated - and if so, are there any performance/memory benefits)?

View 6 Replies

Repor Declaring Class Instances?

Oct 20, 2008

I've decided to forget the d@mned custom code because everything I do with comes up with errors I don't know how to fix and it seems no one else does either. Or they do and they're keeping to themselves.

I put the functions that I needed to use in a class called MsgBoxOperations. The file name is MsgBoxOperations.vb In the report, up on the standard bar where file, edit, view, and all the other stuff is, is one that says report. You click that and go to report properties and it brings up where you can name the report and put in custom code...(hate custom code right now...) and where you can put references and class instances. Clicking on the Reference tab brings up wher you put in your references and classes.

In the classes area it asks for the Class Name, which I put in MsgBoxOperations, and the instance name of that class, this case mbo. I get that far and put in those two things and save it. Then I go to the textboxes where the values need to be. I put in the text box: =Code.mbo.GetStartDate

I've already tried taking the Code. part out and it screams that mbo isn't declared. So it does have to be there. I go to run the code and comes up with this error: QuoteError in class instance declaration for class MsgBoxOperations: [BC30002] Type 'MsgBoxOperations' is not defined.

I've posted before and still have received no help or someone tried to help but then stopped when their suggestion failed and then no one else wanted to help. I've googled this problem to the point where every link that it comes up with I have already clicked and found their information useless. I've got a freaking migraine because of this issue and have been in tears over it more than once.

View 14 Replies

Use A Class Without First Declaring An Instance Of It With The New Keyword?

Jun 28, 2009

how do i use a class without first declaring an instance of it with the new keyword?i have a class items that has a function toArray.how can i call it this way:

View 1 Replies

Late Binding - Declaring A String Variable And Assigning The Item Property?

Nov 27, 2011

I have a problem involving late binding, and I absolutely cannot for the life of me figure out how to fix it. I have spent hours researching the problem to no avail, so I am turning to stackoverflow as a last resort.The problem is pretty much this: I am creating a grocery list application. I have a class named Item which stores the name, price, quantity, and description of an item on the grocery list. I have a module named ListCollection which defines a Collection of Item objects. I have created an Edit form which will automatically display the currently selected ListCollection item properties, but whenever I attempt to fill the text boxes, it tells me that Option Strict disallows late binding. I COULD take the easy route and disable Option Strict, but I'd prefer to figure out what the problem is so I know for future reference.I shall paste pertinent code here. (Late binding error is in EditItem.vb)

[code]...

I have tried declaring a String variable and assigning the Item property to that, and I have also tried grabbing the value directly from the List item (not using the Get function), and neither of these made a difference.

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

.net - Declaring A Function Inside A Base Class Non-overridable?

Aug 5, 2010

I have a base class foo that will be used in multiple child classes of similar but slightly different function:

Public MustInherit Class foo
Public Function bar1() as Something
''// Perfectly OK to change what this method does

[code]....

How do I get the compiler to generate an error when bar2() is overridden by a child class?

View 2 Replies

Any Way For A Class To Prevent Outside Code From Declaring Variables Of Its Type?

Jan 6, 2011

Is it possible for a class of exposing a type for function returns, without allowing users of that class to create variables of that type? A couple usage scenarios:A Fluent interface on a large class; a statement like "foo=bar.WithX(5).WithY(9).WithZ(19);" would be inefficient if it had to create three new instances of the class, but could be much more efficient if the WithX could create one instance, and the other statements could simply use it.A class may wish to support a statement like "foo[19].x = 9;" even when foo itself isn't an array, and does not hold the data in class instances that can be exposed to the public; one way to do that is to have foo[19] return a struct which holds a reference to 'foo' and the value '19', and has a member property 'x' which could call "foo.SetXValue(19, 9);" Such a struct could have a conversion operator to convert itself to the "apparent" type of foo[19].In both of these scenarios, storing the value returned by a method or property into a variable and then using it more than once would cause strange behavior. It would be desirable if the designer of the class exposing such methods or properties could ensure that callers wouldn't be able to use them more than once. Is there any practical way to accomplish that?In formulating a question, it's difficult sometimes to draw the line between complicated usage cases, and simpler usage cases which aren't quite so important. Here's another usage case, and one closer to the one I'd be most interested in (though I'm also interested in Fluent chaining; being able to have something behave like a C++ reference to a value type would be nice, but probably too much work to bother with).I have a type which is somewhat like the Windows registry, in that it is a hierarchical collection of items, each of which may have a string value, an integer value, and/or a nested collection of items. I wish to be able to support the following types of usage:[code]As for the Fluent interface, my thought would be to have the WithXXX properties return a new instance of a derived class which shadows (not overrides!) the WithXXX properties with versions that simply modify the current instance. The return object from WithXXX would be known to be of the derived class, and would thus use the shadowed WithXXX methods, but once it was assigned to a variable, it would be regarded as an instance of the base class, so the next WithXXX would create a new instance.

C++ a stronger concept of value types than C# or vb.net, including the very useful concept of references to value types; it ensures that references to value types cannot be persisted outside the scope of the type in question. Unsafe code in C# can use pointers to value types, but they don't have the protections offered by C++ references.

View 3 Replies







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