Passing Objects To Methods?
Jun 26, 2010
I always thought I understood how this works...but lately I have started really using interfaces and now things arent doing what I am expecting.
using entity framework, I have a service for each object that is responsible for interacting with the database and such....on my one service I am passing the collection of objects to my service as an icollection(of contactinfo) before I pass the object, the changetraker has the right states. however in my method, this is not the case and all states are set to unmodified.
Private Sub SaveExecute(ByVal param As Object)
Dim srv As Services.ContactInfoService = GetService(Of Services.IContactInfoService)()
[Code]....
As I said above the Me.contacInfoCollection has the right changetracking states. But Once its passed to the srv.savechanges it reverts to unmodified. I am sure its something silly I am missing...the whole EF thing can be confusing to me...
View 2 Replies
ADVERTISEMENT
Apr 19, 2009
I've been wasting so much time on this. Basically I want to have a list of objects and I want to call some specific methods of some specific bjects..g.MsgBox(Instances(0).Position(0).ToString)It should alert a number that presents the X position, but it is not working... the box does not even appear and no errors.
View 8 Replies
Apr 7, 2009
In C# I'm calling a function on an interop class (Connection, written in VB6), which itself returns a plain object (System). Then there's a function on that object (InitialiseData) that I also call (even though the compiler isn't aware of it). var isInitialised = Connection.System.InitialiseData(path); The problem is, because that System object is returning a mere Object, I get the compile error "cannot resolve symbol". I can see why, but the same thing works fine in VB.NET:
[Code]...
View 1 Replies
Aug 11, 2009
Is it really impossible to create an extension method in C# where the instance is passed as a reference?
Heres a sample VB.NET console app:
Imports System.Runtime.CompilerServices
Module Module1
[code].....
View 3 Replies
Oct 21, 2009
I have a List(Of AddlInfo) with AddlInfo being an object. I'm trying to pass addlInfoList by reference into a function of another class:
[Code]...
This works if I'm not passing the reference into another class, but when I try to do this, I get the following error: Overload resolution failed because no accessible 'Sort' can be called with these arguments:
[Code]...
View 1 Replies
Jul 9, 2009
I seem to find more and more that I declare a lot of objects or methods as Shared now but it feels like I am not doing things properly.I try to avoid doing this but then I just end up with situations where I have to create an instance of a class just to call one method that would act no differently if it was just a shared method.Basically I'm just wanting to know if there is any good reason to avoid using Shared objects/methods. Obviously I dont declare EVERYTHING as shared, but it just seems to make things a lot simpler most of the time.For example in my current project (a chat application using WCF) I have a class just called Core which houses a lot of the main functions of the client program, so it has methods such as: SignUserIn, SignUserOut, SendMessage, MessageReceived etc and it also holds properties such as a list that contains all of the currently online users. These things are all declared Shared in my program because as far as I can see there is no reason for having to do this:[code]
View 15 Replies
Dec 26, 2010
If I create new textboxes, or any objects, based on user input, how can I create methods that use those new textboxes (objects). For instance,
[Code]...
View 2 Replies
Aug 11, 2010
I'm translating a document management application from vb6. I want to program with good habits and technique, so I'm asking for your opinion really rather than just a solution.I have a decent understanding of OOP, but I'm not very experienced in VB at all. What I'm doing now is trying to figure out the best way to pass objects between forms.For example, in my initialization form, I have an object that stores a group of database connections. I need to pass this object around because reconnecting takes a significant amount of time. There are other objects such as user info and permissions.
Public Class Form 1
Dim DB = New DBobject
Public Sub Form1_Load
[code]......
View 5 Replies
May 20, 2011
I have an ASP application, which calls an HTTP WCF service, which calls a TCP WCF service (all on different servers). I'm ultimately trying to pass one class object between the three.I've discovered that I can't do this directly in the HTTP WCF, even though my class object is defined identically in BOTH WCFs. Like this:
Public Function CallOtherFunction(ByVal ThisClass as MyClass)
Dim RetVal as Boolean
RetVal = CallMyOtherWCFFunction(ThisClass)
End Function
Instead I have to:
Public Function CallOtherFunction(ByVal ThisClass as MyClass)
Dim RetVal as Boolean
Dim MyOutgoingClass as MyOtherWCF.MyClass
[code]....
My objects are rather large, to say they have a lot of properties. Any way to not have to declare a new variable in my calling function?
View 1 Replies
Jun 26, 2010
I want to know what are classes , objects , a namespace , subroutines,functions,methods,properties and differemce betweem byval and byref in your words.
View 18 Replies
Jun 12, 2011
I have the following problem. This is a simple example of some classes I have (each have dependencies on other classes).
public Class1()
{
public Class1(Class2 class2)[code].....
The problem I have is that the assert is always null, even though class1 has been initalized. One condition I do have is that I only want there to be one instance of each class created.
View 3 Replies
Aug 19, 2011
I have the following code in Class B
FolderList.add(FolderCategory)
when i do a count it display a list of 25 items in the folderlist.Now i have a main class when i tried to use the following method
Dim MainClass as New ClassB
Console.writeline(MainClass.FolderList.count()) the value reflects as 0 items meaning is empty.i need to retrieve the arraylist from Class B using the MainClass to retrieve those items inside the arraylist.
View 7 Replies
Jul 16, 2009
I have no idea where to begin. I've looked online but haven't been able to find anything.
View 1 Replies
Aug 21, 2011
I was wondering if someone could tell me if this is "bad practice" or is a perfectly acceptable way to pass an object to another form.I've cut out a lot of the code to summarise what im asking.
[Code]...
Dim myRetrievedObject as myObject = Module1.returnSavedObject()Is this a acceptable way of passing an object between forms or is it a completely bad idea?Ideally i would like to be able to "add" further objects to the initially created object in Form1 but then on reloading of Form1 , retrieve the new version of myObject with the newly added objects within the myObject class.My initial thinking is this creates an almost session like state for the initial object. So you can use the same object over all 3 forms or more and just simply add to it like a shopping cart type of functionality.
View 10 Replies
Jan 31, 2012
I have adopted a technique where I pass existing objects to forms so that they can display the object's content and allow the user to alter it if necessary. The form is not bound to the object, so when it comes time to act, the form sweeps up the content of its controls and puts them into the object. The object is then validated and any issues reported to the user. If the object is valid, it may be handed back to the caller so the caller can refresh a view/list/etc.
So far, so good. However, if the form's content, or lack of, creates an invalid object and the user does not correct it, maybe cancelling the form, there's a chance the form will hand an invalid object back to the caller. This is not good.
Essentially I'm looking for an elegant and efficient way of either leaving the object as it was or rolling back if the user cancels the form/action.
I have considered a range of techniques, each with many pros and cons. I'm keen to consider some other views.
View 3 Replies
Dec 28, 2009
Passing data between forms without any public methods or properties on the forms. everything but the "Controller" class, which I would like you furnish. I just changed the title from "Intermediate" to "Beginner" This solution is an example of the Observer Pattern. The "Controller" class is the "observed" class, which in this case means it publishes events.
' File Definitions.vb
Public Delegate Sub MessageDelegate(ByVal sender As Object, ByVal e As MessageEventArgs)
Public Class MessageEventArgs : Inherits EventArgs
Public Message As String
[CODE]...
The program should initially display Form1, and Form2. Clicking of the button on either form will modify the Title Text of both forms. I think that you will find the final end result to be pretty neat, as it works with any number of open forms not just two. I think asking for the Controller class is easier than asking for the code in the forms. My solution for Controller class has 7 lines of content, 9 lines if you include Class, EndClass. A minimal solution could achieved with only 4 lines of content, but it would a textbook example of bad programming.
View 12 Replies
Nov 23, 2010
Have a windows application that "got complex" and new products could use many portions of the existing application.Decided to break app into multiple projects to facilitate sharing the appropriate pieces with new products.One object in app provides a library of text phrases used in the production of output docs.Wondering if such an object should be a set of shared methods instead of instantiating it in every object that consumes these text phrases.
View 5 Replies
Aug 13, 2010
In VB.Net I am attempting to use Office Automation starting in Access; then to Excel.I am having difficulty finding the References in VB.Net which will permit me to upgrade my VBA code to VB.Net.For example in VBA the code line: Application.SysCmd(acSysCmdSetStatus, Space(75))
In VB.Net, I cannot find "acSysCmdSetStatus." Error message = Name "acSysCmdSetStatus" is not declared
Following are my Imports:
Imports System.Data.OleDb
[code]....
View 2 Replies
Apr 22, 2012
Base class has one field to hold numeric balance value. With 2 methods that accept arguments for adding and subtracting the new input calculating new balance. Sub class has four fields dates, transaction, memo and amount.I have a deposit form, and withdraw form. Each time one transaction is entered it creates an object with sub class fields, then adds to the account collection. My problem is not understanding how to call the deposit/withdraw method and pass the current transaction amount back to the base class to alculate the new balance. Does anyone have any links to information/tutorials on how to perform something like this? As you can see with my code I have tried various different approaches without any success.
[Code]...
View 5 Replies
Aug 29, 2011
This is the original code in c#
public class CategoryRepository: RepositoryBase<Category>, ICategoryRepository
{
public CategoryRepository(IDatabaseFactory databaseFactory)
: base(databaseFactory)
[Code]...
Does anyone has an idea what i should change to let it work and let my UserRepository use the methods in RepositoryBase while implementing the IUserRepository?
View 1 Replies
Jun 24, 2011
I am working with a vb program, but there is something strange on one of my .vb code pagewhen i put the "dot" afther the object name its dont show the methods availables for this objectbut on other vb code pages i can see it. but in this one no.for exmaplethis is a piece of code: Dim sb As New StringBuilder()
View 3 Replies
Mar 29, 2010
I am not sure how clear my question is by the title, but I am trying to make Class methods instead of Instance methods in Visual Basic that way I don't have to waste memory and code creating temporary objects to execute methods that don't need instance variables.
I am not sure if you can do that in VB but I know you can in Objective-C by using either a "+" or "-" sign in front of the method declaration. And in C++ (at least I think, I can't remember) you put the static keyword or const keyword in front of the function.How would I do this in VB if it is possible? Or should I just make a separate set of functions that are not members of a class?
View 2 Replies
Aug 26, 2010
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim someproc As Process
[Code]...
View 3 Replies
Dec 5, 2011
make objects from the ToolBox using code instead of changing existing objects invisible then visible later?
View 7 Replies
Jun 23, 2012
I am getting this error, Not sure why it is happening "Error The SqlParameterCollection only accepts non-null SqlParameter type objects, not Int32 objects."I have tried with all sorts of possibilties, now try to enter default data as dummy data,
Using connection As New SqlConnection
connection.ConnectionString = ConfigurationManager.ConnectionStrings("DentalDeviceConnectionString").ConnectionString
connection.Open()[code].....
View 1 Replies
Jan 29, 2011
I have a program like this.
Module Module1
Public Class Mstr
Public Property Prop1 As String
Public Property Prop2 As String[code]....
But it is not working as I expect it to. You can see it from.The DtlsB properties of all three DtlsA objects are having values from last iteration.
View 1 Replies
Jan 6, 2011
I want to let the user input objects to a richtextbox 1 object on each line, and somehow use Random.Next to select pseudorandomly a few objects, the number 'few' inputted in a textbox.
View 9 Replies
Jan 18, 2012
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using conn As New SqlConnection("Database=Clinic_Management_System;Data Source=.SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|Clinic Management System.mdf")
Dim cmdRecord As SqlCommand
[code]....
View 2 Replies
Feb 7, 2010
I have a user control that inherits the FW ListView and I need to dispose of two objects when the form's disposing of it's objects. Here's what I've concluded already, am I on the right track?
[Code]...
View 3 Replies
May 1, 2009
long story short, I have created a ListView type control, using UserControls for the parent control and the ListViewItems. Most the of the control is written and works fine, right up to the point where I tried to replicate the 'Control.SelectedItems(0).Index' property and the 'SelectedIndexChanged' event.
Each child object knows its index value, and could pass this value via the SelectedIndexChanged event (assuming this is how it works in a normal ListView control -- user clicks on an item, and that item fires an event updating the selected index value in the parent object).
How does the child object raise an event in the parent object? I have a feeling this could be done with Delegates, but I'm still learning about their usage.
View 1 Replies