Reading a book, the following examples are given regarding value and reference types. This example is noted as a value example. ptY display {x = 10, y = 20}
Dim ptX As New System.Drawing.Point(10, 20)
Dim ptY As New System.Drawing.Point
ptY = ptX
ptX.X = 200
Console.WriteLine(ptY.ToString())
This example is noted as a reference example. objY displays "Hello Test".
Dim objX As New System.Text.StringBuilder("Hello World")
Dim objY As System.Text.StringBuilder
objY = objX
objX.Replace("World", "Test")
Console.WriteLine(objY.ToString())
The idea is simple enough, but I just can not tell the difference between the two. Could someone explain how the heap, the stack and the New keyword play a role in accessing directly and indirectly objects and variables?
I have a class with a Property called 'Value' which is of type Object.Value can be of any type, a structure, a class, an array, IList etc.My problem is with the setter and determining whether the value has changed or not.This is simple enough for value types, but reference types and lists present a problem.For a class, would you assume that the Equals method has been implemented correctly, or just assume that the value has changed every time the setter is called?If I did assume it's changed, then perhaps I should assume it for value types as well, so that the behaviour is consistent.
The difference between reference types and value types is often confusing for beginners due to not understanding what a variable of value type actually holds. We know that:Value types store the actual valueReference types only store the reference to the object
I understand that an array variable contains a reference to an array object - it is a reference type. A string variable is also a reference type.So, if I make a copy of either one, a change to the copy should also change the result I get when I look at the original because both refer to the same object.
I understand that an array variable contains a reference to an array object - it is a reference type. string variable is also a reference type. So, if I make a copy of either one, a change to the copy should also change the result I get when I look at the original because both refer to the same object. In the following code, I expected to see "Whoooy" as the result for original and copy for both the array and the string. It works with the array but not the string.
I'm still working on the code in this thread [URL] and as I mentioned in that thread, I thought that passing objects around between methods would probably be bad for performance (perhaps not really noticeably at first but maybe if I did it enough then it could have an impact).
1. When you pass a reference type to a method using ByVal then what is actually 'copied' ? I understand that ByVal copies the object into the local method that you are calling where as ByRef passes a reference to the actual object so you can work with the original object. So when you have a Reference type and you pass this ByVal then does copy the entire object or does it just copy a 'reference' to the object?
2. When working with an object that relates to a 'physical' item, such as a file on disk or a network stream between two connected machines, then what happens when you pass it around between methods (this might be irrelevant depending on the answer to the first question) ? I mean if I have a NetworkStream object that represents the data stream coming from a remote computer, if I then pass that ByVal into another method then does that mean I am still working with the same data stream or a copy of it or what?
I'm integrating one of our apps with a third-party provider's web service. I've added the service reference, but when I go to dimension a var as one of their types, the types aren't showing up for me in Intellisense. I'm using VB.NET/VS 2008 on Windows 7 and a 2.0 Framework web site running on local IIS. I have imported System.Web and System.Web.Service in my codebehind. I also made sure to check the "Always generate message contracts" checkbox.Types not showing up for service reference
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.
Is it okay for a structure variable to hold a small number of reference types? I thinks it's fine because the pointers themselves are not that big, regardless of what they're pointing to. But I never did fully figure out the whole heap/stack thing, so I'd like to make sure.
First post here so Im sorry if im posting in the wrong place. Im trying to build a simple poker game which requires the program to recognise hands of each players. Luckily there are 3rd party solutions such as pokereval. However my problem comes when i try to convert a C# ported version of pokereval by Keith Rule, into vb.net. The following error shows up referring to the line with the *.
Im having trouble writing different values types to memory, for a particular exe Using the code below will allow me to write a value of 4 Bytes correctly but I also need to write a Float value.[code]Is there any way I can have both of these, to allow me to write 4 byte integers as well as Float Values?
Supposing the referenced List below contains 2 elements: Dim Countries = From c In List _ Select New With { .Country = c.Country, .CountryID = c.CountryID }
I'm trying to do something similar to what's described here, but with nullable types.
[URL]
int availableUnits = unitsInStock ?? 0;
In VB, it would be this:
Dim availableUnits As Int32 = If(unitsInStock, 0)
However I'm working with db columns, which could be DbNull, and nullable types, which can be Nothing (which is different to DbNull). If a column is DbNull, I want to return Nothing, otherwise return the value. For eg:
Dim availableUnits As Int32? = If(myDataReader("UnitsInStock").Value, Nothing)
The error I'm getting is "Specified cast is not valid" but I'm not sure why. I've tried this as well:
Dim availableUnits As Int32? = If(isDbNull(myDataReader("UnitsInStock").Value), myDataReader("UnitsInStock").Value, Nothing)
Which is messy and just results in the same error. The only thing that works is this:
Dim availableUnits As Int32? If isDbNull(myDataReader("UnitsInStock").Value) Then availableUnits = myDataReader("UnitsInStock").Value Else availableUnits = Nothing End If
Which is just silly. Is there a better way of getting nullable db values into nullable variables that I'm not aware of?
I'm trying to create a web site that users can log into and self serve their user information ie name, address etc. I've set up a SQL server DB with a couple of table holding the data and accessing those using Linq. I'm selecting specific data from my datacontext then trying to assign it to a label, ideally I want to assign the value to a class attribute so I can use the users details on multiple pages.
I've simplified the code (removing WHERE statement etc for the purposes of this question):
Using CurrentUserDataContext As New UserDataDataContext()
I am working on a project where my class has to execute VB code provided by the user, to make it simple I am trying to recreate my own eval function, I am using the following code I found on the web to do this task.
The problem with code is that it can't access any variables or there values, so I have decided to get the variable names, there values types and there types dynamically and recreate them in the class that is being created dynamically. Any way to get the variable names there types and values in the current class or method, so that I can recreate them, and execute the user passed code, the user knows what variables are in the current class or method and there datatypes but he don't know there values as they may have changed, so he can't initialize them. Is there a way to do this, this code will be called in an asp.net page on page_load event, the code passed by the user is stored in the variable vbCode that is passed as a parameter.
I get this error:Reference to a non-shared member requires an object reference.When i compile on the following code section:
Private Sub statusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) ToolStripMenuItem.Checked = Not ToolStripMenuItem.Checked statusStrip1.Visible = ToolStripMenuItem.Checked
I have a large form that reuses several elements, so I decided to create a usercontrol with some common fields. The problem is when the form is filled out by a user and submitted, how do I reference those values so I can input them to my database???
Example:
Using Conn As New SqlConnection(connect) Using Cmd As New SqlCommand(SQL, Conn) Cmd.Parameters.AddWithValue("@Acct_Company", txtPartner.Text) Cmd.Parameters.AddWithValue("@Acct_AccountNum", txtPartnerAccount.Text)
So, above two Cmd lines are for normally inserted textboxes in my form, but what would the line look like to reference any usercontrol form fields?
I'm creating a VB.Net Windows Form Application. Apologies if this is not clear as I'm still new to .Net. This consists of a text box and a gridview.The user is able to write SQL code in the textbox, click run and see the results in the gridview.It uses a SQL DataAdapter and the fill method to a datatable to populate the gridview.My problem is that I need to know the SQL datatypes for each column in the data table (NOT the .net ones). I.E SQL Server 2008 data type 'Date' is stored as System.Datetime in the datatable. I need to know if the SQL Server datatype is 'Date' or 'Datetime'.
When adding a column to a datatable. I can specify a type as one of my overloads such as
dt.Columns.Add(New DataColumn("UID", Type.GetType("System.Int32")))Why can't I use
dt.Columns.Add("etwe", TypeOf(Integer)) when I thought integer is a type. Instead its telling me that integer is a type and can't be used as an expression.
How Should I Use Diffrent Types Mouse Pointers in .Net for Each Form? How Should I Play a mp3 sound File From "D:My Locationsound.mp3"? How Should I Create an Set up File in VB.Net 2008? How Should I Make a Form Shaped Round? How Should I Use The Mouse as Mouse Touch Event?
I wrote the following function to randomize a dictionary object:
Friend Function RandomizeDictionary(Of T)(ByVal oCollection As Dictionary(Of String, T)) As Dictionary(Of String, T) Try Dim oResult As Dictionary(Of String, T) = Nothing
[code]....
This code works fine on simple dictionary objects, but when I use it with complex types I get a type cast exception. For example, I have an object X that Inherits Dictionary (Of String, Class Y). If I call the randomize function on object X, I get the type cast exception. I don't really understand why it cares what the type of the dictionary value is, I thought that was the point of using generics.
In summary the following all work:
Dim x as New Dictionary (Of String, String) Dim x as New Dictionary (Of String, Boolean) Dim x as New Dictionary (Of String, Integer)
This does not:
Dim x as New Class X Class X Inherits Dictionary (Of String, Class Y)
I'm using my data objects in a crystal report. The thing is, when I select my object, it gets added to the field explorer table. My properties are listed except for the Nullable Type properties. Why would this happen. I've had quite a few issues yesterday as this is my first attempt at a crystal report in .Net. I thought I worked around them but now I've hit this snag.
Am New To This Fourm So Forgive Me If I Have Put This In The Worng Place I HAve Been Programming For 3 Years And Need A Project I Am Doing.I Am Using Visual Basic 2008 Express EditionOutlineI Want To Be Able To Add A Dword Value To A Exsisting Location and add a value to that Dword Value
Example: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList and then Add a new Dword Value that is not there such as Administrator
I have imported a number of web elements that are called "reference values" from a website. These are added to the end of a website to navigate to a corresponding page. I am going to go to said website individually for each "reference value" and scrape code for use in a scheduling programming. How should i navigate to each of these websites when the url cannot be edited. The "reference values" are currently stored in an array but this does not seem like the correct method.
I am currently working on a VB.NET project and the hardest thing that I am having trouble with is that everything is black and blue. Having worked a lot with C#, I really like the way that types are colored differently.
I have tried going in and having a look at the "Tools > Options > Fonts and Colors" and the various "User Types" under "Display Items" is set to a different colour but its not reflecting that colour in the text editor.