3.5 Assignment Operator Assigning Pointer Instead Of Copying?

Dec 16, 2010

My program has decided to assign pointers instead of make copies of an object, and I'm not sure why. I have something like this:

Public Class Foo
Private myFooData As New List(Of FooData)
Public Sub New(ByVal newFooData As List(Of FooData))

[Code]....

Very simplified, but basically what I'm doing. So for some reason today when I change item in newFoo.FooValues, originalFoo.FooValues also changes, and mainFoo does not. I've tried assigning the entire objects as well and I get the same results.

View 2 Replies


ADVERTISEMENT

Overloading Assignment Operator?

Jan 9, 2010

i would like to hijack the assignment operator and do some customization before an instance of my class is assigned.

example:
Dim A as New MyClass
Dim B as MyClass = A

i want custom the behavior of = is that possible?

View 9 Replies

VS 2008 Assigning Form Pointer To Variable?

Aug 31, 2010

What I want to do is either trivial, or likely impossible in the .NET framework.

I have a number of forms, with various pictureboxes, labels, etc. in each. Same names for the same items on each form. Only one form is visible at a time. What I need is some way to assign to a variable in the code which form is currently in use, such that I can reference the control on that form in a single statement.

That is, I have set up (already) references to the individual forms (call them frmForm1, frmForm2, etc.). So I can write to a textbox as:

frmForm1.textbox1.text="Hi there."
frmForm2.textbox1.text="Hello world."

What I need to be able to do is something like:

currentform = frmForm2
currentform.textbox1.text="Display on visible box"

Is such a thing even possible? Obviously, the way .Net normally wants to work is to verify everything at compile, and there is (of course) no way for it to know if whatever "currentform" points to even has a "textbox1" control.

save me a LOT of long-winded IF-THEN-ELSE to see which form is currently displayed for each and every time I want to display something. [FWIW, I *could* right everything out to every form, but I feel that would waste to much CPU time.]

View 6 Replies

Define An Assignment Operator In Structure?

Jul 9, 2010

I am having a structure that is actually a simple byte with more functionality.[code]...

If there would be a way to inherit from Structure I would simply inherit from Byte adding my functionality, basically I just need a byte Structure with custom functionality.

My question is also valid when you want to define your new singleton member value-types (like, you want to define a nibble-type for instance etc.) and you want to be able to set it with an assignment to number or other language typed representation.

View 1 Replies

Lamdba Expression, Use Assignment Operator Instead Of Equality?

Oct 27, 2010

I have a method that takes an System.Action, this is what I'm trying to feed it:Function() Me._existingImports = Me.GetImportedAds()

The thing is that it complains about the = sign since it thinks I'm trying to do a comparison, which I'm not. I want to assign the Me._existingImports the value of Me.GetImportedAds(), but VB.NET complains about DataTable not having a = operator.

How can I force it to use the assignment operator instead of the equality operator?

In C# this works perfectly fine: () => this.existingImports = this.GetImportedAds()

For now the solution will be to use a standalone method, but that's way more code than needed.

View 1 Replies

How To Distinguish Between Copying Class Data And Pointer

Oct 2, 2009

How do I distinguish copying data and a pointer when using a class?E.g.
public class myparams var1 as integervar2 as intergerv3 as stringend classmyvar as new myparamsmyvar.var1=1myvar.var2=2myvar.v3 ="hh"othervar as new myparams

I want to copy all of myvar data into othervar in one go.. without doing
othervar.var1=myvar.var1 etcusing othervar=myvar"
Looks like its just copying the pointer of myvar into othervar? Can I copy all the class data in one go? VB2008 user

View 1 Replies

Assigning Result Of If Operator To System.Nullable Type

Aug 30, 2011

When using the If operator [URL] to assign a value to a System.Nullable object, if the result is Nothing (null), then 0 is assigned to the object. Example: 'Expected value is null (Nothing). Actual value assigned is 0. Dim x As System.Nullable(Of Integer) = If(1 = 0, 1, Nothing) If x is a nullable type, why is it being assigned the default integer type of 0. Shouldn't it receive a value of null?

View 2 Replies

Does The Assignment Operator In 1.1 Do A Member-by-member Copy Of The ObjOriginal To ObjClone

Nov 18, 2009

I'm "cloning" objects in my code. For instance: objClone = objOriginal My question is: Does the assignment operator in VB.NET 1.1 do a member-by-member copy of the objOriginal to objClone or does objClone simply point as a reference to memory referenced by objOriginal?

View 3 Replies

VS 2008 Pointer - Error32'System.Reflection.Pointer' Has No Type Parameters And So Cannot Have Type Arguments

Jul 15, 2010

I have an open source project I converted to vb.net. I solved all the errors, except for one. This is the C# line

[Code]....

View 4 Replies

C++ - Declare Pointer To Pointer In COM/ATL?

Dec 29, 2010

How can I declare pointer to pointer in ATL. Actually I have a handle which I want to pass by address to function. As shown below

STDMETHODIMP Function(HANDLE* hHC) //HANDLE declared as void * so actual type is void **

OR

STDMETHODIMP Function(LONG **hHC)

And want to access this function from the VB client.

View 1 Replies

VS 2005 - Copying The Internet Cache Folder But Getting Copying Error?

Apr 22, 2009

I have a copying error with my program. I am trying to copy the internet cache folder, and the error states that some files cannont be copied (read only maybe?) How can i make it copy, or just skip the uncopyable files?

My.Computer.FileSystem.CopyDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Internet Cache), "d:My Documents")

View 12 Replies

Error: Option Strict On Disallows Operands Of Type Object For Operator '='. Use The 'Is' Operator To Test For Object Identity

Jan 27, 2010

I am tightening up my coding with the Option Strict set to ON. It has now produced alot of errors. An example of this is:

If AllocatedDGV.Rows(i).Cells("RoomNumber").Value = RoomsAvailableDGV.Rows(j).Cells("RoomName").Value Then

It gives me the following error: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.

View 6 Replies

Option Strict On Disallows Operands Of Type Object For Operator Use The 'Is' Operator To Test For Object Identity

Apr 6, 2012

I need to write an interface to get data to/from our data files.

We have a low level class that holds field values for each record read from the files.

This just holds two values, the value read from the file (DBValue) and the updated value that may need to be written back to the file (CurrentValue).

These values may be any of the standard value types (integer, date etc) or a string.

Either value (DBValue or CurrentValue) may be null if not defined.

I have written the class to manage this data which works fine while option strict is NOT on.

But we have an office policy of having option strict on all the time.

When I put option strict on, my object value comparisons fail with the error: "Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity."

Question, how should I change the following code to handle option strict on ...

This is all running on Visual Studio 2010

[Code]...

View 1 Replies

Coalesce Operator And Conditional Operator In .NET?

Mar 10, 2009

Possible Duplicate: Is there a conditional ternary operator in VB.NET?

Can we use Coalesce operator(??) and conditional ternary operator(:) in VB.NET as in C#?

View 5 Replies

How To Use Operator As A Comparison Operator

Nov 11, 2009

I want to perform equality comparison in VB.NET and cannot get it to work. Error: value of type Boolean can not be converted to System.Drawing.PointF

[code]...

View 4 Replies

VB 2010 With The Assignment?

Sep 24, 2011

I have a school assignment and I just started to learn VB. Until now I/ve done pretty good however I encountered a problem which I can't solve in this assignment. So, I would ask if someone could tell me what I'm doing wrong?

This is the assignment:The application calculates the new hourly pay for each of three job codes, given the current hourly pay for each job code and the raise percentage (entered as a decimal number).

a.) before the form appears, use the InputBox function to prompt the personnel clerk to enter the raise percentage. You will use the raise percentage to calculate the new hourly pay for each job code.

[Code]...

View 4 Replies

Why Does The Assignment Fail

Jun 5, 2012

Concerning this code... Dim i1 As Integer = Nothing

[Code]...

View 12 Replies

.net - Perform An Assignment In An IF Conditional In .NET?

Mar 19, 2012

Is there a way to set a variable in VB.NET in an IF statement. I would like to do the following:

[Code]...

Is there some way I can get the last "ElseIf" to work? I know I can re-write it to get it to work but is there some syntax that will make it work the way it is?

View 3 Replies

ASP.Net String Assignment Failure

Aug 16, 2010

I'm having an odd problem with an ASP.Net page.I'm getting an object not set error message when assigning a string literal to a variable. [code] And here is the code that the error is pointing to. The last line in this fragment is the line 10 the error is complaining about [code] It seems it fails on accessing any reference type, even if it is declared locally in the load function. I originally found the problem when Request. IsSecureConnection was nulling out on me. I eventually discovered I could replace it with the above code and fail in the same way. The problem does not always happen. It seems to be triggered by publishing an update from Visual Studio, or when I head home for the day and the server sits idle all night. One or two app pool recycles seems to clear it up, and the page functions correctly. I've been doing desktop development for a few years, but I'm fairly new to web development.So maybe this is something obvious I've got configured wrong. I'm currently using .Net 4 on IIS 6. That code is in a foreach over an IEnumerable(of XElement). The stack trace still points to the string assignment, but all other stack traces are spot on, so I don't think it's a bad pdb.Also, when the error occurred this time, no amount of recycling the app pool or stopping and starting it would fix the error. I finally got it working again by switching the application to a different app pool.

View 2 Replies

Assignment Operators Overloadable In .NET?

Apr 23, 2012

Why aren't the assignment operators (+=, -=, *=, /=) overloadable in VB.NET?

View 1 Replies

Combobox Assignment Of Variable?

Apr 4, 2011

If I put:

variableName = namecombobox.selectedItem

or

Dim variablename as type = namecombobox.SelectedIndex

Visual studio gives me the error: "Option Strict disallows conversions from object to string.

I can fix this by putting:

variableName = convert.ToString(namecombobox.SelectedItem)

Are all values contained in a combobox automatically treated as a non-string even when they are string values (in this case "Male" & "Female") and what is the correct way of assigning the value selected in a combobox to a variable?

View 1 Replies

Constant Cannot Be Target Of An Assignment

Jun 12, 2011

i am making a program on visual basic 2010 and part of my objective is to calculate the tax, i am trying to calculate the TAX so this is part of my code and this is the only part which gives me errors:[code]

1. Constant cannot be target of an assignment

2. value of type 'string' cannot be converted to 'System.windows.forms.Lebel'.

View 2 Replies

Create A Code For This Particular Assignment?

Jun 21, 2010

I have an assign ment that says: create an application to let the user enter his or her name (first and last name), then displays the Initial in Upper Case. FOr example: you enter "John Wow", then the Label will display "JW". I know that I'm supposed to use the Substring method. But to use the Substring, I have to have the exact location of the Leter that is going to be displayed in the Label.The problem is: the name that the user enters always vary. So in strnewstring.Substring(... , ...) ---> the number in the parenthesis would vary, too. Thus, I cannot put a number in there.So how can i create a code for this particular assignment.

View 4 Replies

Design A Sudoku( 4*4 ) For VB Assignment?

Sep 26, 2011

i need to design a sudoku( 4*4 ) for my VB assignment..and i am having problem with generating random numbers for the four text boxes i have used..

View 4 Replies

Difference Between Return And Assignment?

Sep 28, 2011

What is the difference between this two ways of returning value in a function in VB.NET?

Using Return Statement:

Public Function Foo() As String
Return "Hello World"
End Function

Using Assignment:

Public Function Foo() As String
Foo = "Hello World"
End Function

I'm using the first one then I saw someone using the second. I wonder if there's a benefit I could get using the second.

View 4 Replies

Object References And Re-assignment In .net

Nov 17, 2010

Maybe this is a n00bish question, but I'm used to c++'s pointers and references and this is confusing me a bit. Let's say I have the following scenario in a VB.net application:

[Code]...

The situation is this: I have a collection of objects, and during execution of the program, any of them can be fetched from the collection to be used/edited by another part of the program. Now obviously if I edit the data inside the object it is allright, but what if I want to replace the object, as I did above at line 5? I would change only the local reference (y) but not the object inside the collection!

Is there a way around this? How can I take with me a "reference to the object's reference", instead of just a reference, so if I reassign it it will also reassign the one in the collection? I hope I'm making myself clear, unfortunately english is not my native language, to be clear: in c++ this would be easy using a pointer to a pointer, or passing a pointer to the object always by reference, so calling new or reassignment on it would change the original pointer itself)

View 4 Replies

Post Several Parts Of Assignment?

Jan 4, 2009

I have post several parts of my assignment. Can someone advise me on how to do a log on screen. I have a splash which is on a timer, which is supposed to go to a logon screen. I have created the database project in visual studio 2008. Database was created in ms access 2007.

View 2 Replies

Variables Are Stuck At An Assignment Of Zero?

Feb 27, 2012

I've got one for you. I am working on a program that calculates the cost of a trip given a specific price of a Workshop say "Handling Stress for $595" the length of the workshop say "3 Days" and the city the workshop is in say "Austin for $95/day" now the issue i am having is that for example my NumDays variable (the variable for the number of days of the workshop) is not taking the value. Ive ran a Watch on the variable and it stays at 0. It also displays zero. i have assigned it an integer so it should be working if I assume correctly.

[Code]...

View 4 Replies

Varriable Assignment Of PictureBox?

Sep 29, 2009

I am fairly new to Visual Basic, but have had extensive experience with TI Basic and am 1 month into a class at my high school in Visual Basic.I recently began a blackjack application that will play as if you had actual randomized cards. I currently have 2 variables per card, one for the value (random integer 2-14), and one for the suit (random integer 1-4). I have pictures of all 52 cards with this numbering system (21.png, 22.png, etc. The compiler understands picturebox statements as

PictureBox1.Image = My.Resources._21 It seems like there would be some way to have a variable assignment, but

PictureBox1.Image = "My.Resources._" & You1Card & You1Suit isn't recognized as it is a string. Is there some way to either randomize the pictures to generate a random picture in My.Resources as opposed to integer representations of cards? Or is there some way to have the PictureBox assignment accept a variable string?

View 8 Replies

VS 2005 What Can Use Instead Of A Pointer

May 1, 2010

I understand there are no pointers in VB.Net. I need to use something similar.The issue is that I have a structure that represent a deck of cards, with elements showing how many of each type of card there is. So I have my_deck.ace, my_deck.two, and so on.What I want to do is set a pointer called current_element that refers to any element in the structure. It may one time point to my_deck.three, and another time to my_deck.nine, and so on. It could point to any element.What I want to do is, for instance to set current_element to point to my_deck.ace, then decrementing current_element would reduce the count of aces by one.[code]that would work, but it's inelegant, I have about 30 different operations to perform, some of them using several lines of code. I'd like to avoid this if at all possible. I could tolerate doing it 2 or 3 times, but not 30.

View 8 Replies







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