I have an interface ITest with a method GetResult(). I have a class Test which implements ITest and thereby defines private method GetResult().
Next I create an instance of Test in a different class. The code is as below:
Module NewClass Public Sub New() Dim i As ITest = New Test()
[Code]....
I am migrating existing code from VB 6 to VB.NET and hence I'm not supposed to change the access modifier of GetResult. Leaving it Private will throw InvalidCastException Unable to cast object of type 'System.Object' to type 'ITest'
Object type variable o is used in many places and hence I don't want to change that. And yes, Test implements ITest.GetMember with a different name.
I'm not entirely sure what to call what C# does, so I haven't had any luck searching for the VB.Net equivalent syntax (if it exists, which I suspect it probably doesn't).
In c#, you can do this: public void DoSomething() { new MyHelper().DoIt(); // works just fine }
But as far as I can tell, in VB.Net, you must assign the helper object to a local variable or you just get a syntax error:
Public Sub DoSomething() New MyHelper().DoIt() ' won't compile End Sub
Just one of those curiosity things I run into from day to day working on mixed language projects - often there is a VB.Net equivalent which uses less than obvious syntax. Anyone?
Use the "new" keyword to create an object instance & Check to determine if the object is null before calling the method. I'm reading text from a text file using the following [Code]
Writing an asp.net mvc app and i have something like this...
Public Class AA '... has some variables... End Class Public Class BB
[code]....
So, now in my program, i just want to copy object of type AA to an empty variable of type BB?it makes sense to do this, as i expect all the fields in AA type object to be copied to the newly created BB type object, and the ExtraVariable in the BB type object i would (will) just assign a value to it later (after the copy) on my own time!!I know copying BB type to AA type would not be appropriate as there would be lost data!But im trying to copy AA to BB, I've used both DirectCast and CType to do this, and i keep getting "unable to cast" error!
Note: I'm using vb.net (but can read c#, no problems)
Okay, I am TOTALLY confused here. I have a class... say MyClass. It has several properties of another class of my type, say MyHelperClass (along with other properties).
I am doing the following: Dim inst As MyClass = New MyClass() With { .p1 = sv1,
When I am loading an Assembly dynamically, then calling a method from it, I appear to be getting the method from Assembly executing before the code in the method that is calling it.It does not appear to be executing in a Serial manner as I would expect. Can anyone shine some light on why this might be happening. Below is some code to illustrate what I am seeing, the code from the some.dll assembly calls a method named PerformLookup. For testing I put a similar MessageBox type output with "PerformLookup Time: " as the text. What I end up seeing is:
First: "PerformLookup Time: 40:842" Second: "initIndex Time: 45:873" Imports System
Let's say I have a page Test.aspx along with test.aspx.vb.Test.aspx.vb contains a class name "TestClass". In that class I have method1(), method2() and method3()I need to be able to call one of those methods, but I can't hard code it, the method to be executed comes from a string.
I can't do Select Case StringContainingTheNameOfTheDesiredMethod Case "Method1"
I have nine pictures that I need to animate -I need to use the ToString method and a counter to concatenate a file name into a string variable from the Image.FromFile method. Once the counter reaches its maximum value, and the last picture is displayed, the counter should be reset to zero or one depending on how the first image file has been name. Also a static counter variable should be incremented in the time routine. what I have so far -- I know what I have to do; however, I just do not know how to code this properly.. Right now I have this going thru a button procedure but it needs to go through a timer.
I hope the question makes sense, anyways. I'm looking to know if in VB.NET, when we call an object's constructor, is there some kind of a reference that points back to the caller? I'm interested because of a corner case where I want the object being created to first be able to validate the existence of some data in the caller before it allows itself to be created. If this validation fails, I plan on throwing an exception. This corner case will never happen at runtime unless the object being created is used improperly by a programmer. The object being created is not inheriting the object I want it to validate, so I can't do anything with the MyBase qualifier.
It's bit of a "future-proofing" issue that I have a (bad) habit of doing. Not critical -- I can always leave stern comments behind as a last resort. Wanted to know if this was possible.
I'm aware that questions like this have been asked before and I doubt it's possible, but I just wanted to make 100% sure that it isn't.In VB.net or C# (either language, it doesn't matter), I want to cast a variable to a type represented by another Type variable. Here's an example of the kind of code that would be needed in C#:
Object castMe = new Foo(); Type castTo = typeof(Foo); Foo beenCast = (castTo.GetRepresentedType())castMe;
Unable to cast object of type 'DynamicTreeNode' to type 'DynamicTreeNode'.
I have an inherited TreeView with an inherited class called DynamicTreeNode inside it. I am trying to loop through the DynamicTreeNodes in the TreeView.Nodes property which is causing this error.
I call the function GetDataTable and when it gets to the return line, I get the error message: Object reference not set to an instance of an object.
Dim DB As New DBConn Dim gd As New DataAccess.GetData Dim DT As New DataTable
[Code].....
Updated. I'll see if I can update with the DataAccess.GetData code. I didn't originally put it in there because our shop use it all the time and have no issues with it.
Basically i've got a web service that i'm trying to put some kind of usage logging in. To do this i've created a class with a logging method. I instatiate the class on the service and then call the logging method in each of the web methods.
Public Class CalculationParameter{ public Long TariffId{get;set;} }
In a workflow activity, I've an Assign like this:
(From tariffDetail In db.Context.TariffDetails Where tariffDetial.TariffId = calculationParameter.TariffId).FirstOrDefault()
Dto is passed to Activity as an Input Argument.It raise following error and I'm wondering how to assign Id.LINQ to Entities does not recognize the method 'Int64
GetValue[Int64](System.Activities.LocationReference)' method, and this method cannot be translated into a store expression.
How can I assign the calculationParameter.TariffId to tariffDetial.TariffId?!
UPDATE:Screen shot attached shows that how I'm trying to assign calculationParameter.TariffId to tariffDetail.TariffId (car.Id = Dto.Id) and the query result should assign to CurrentTrafficDetail object.
I have a .dll file (Interop.ACTMULTILib.dll) that I use to connect to a PLC. This .dll contains a sub called ReadDeviceBlock2(byval devicename as string, byval size as integer, byref data as short).My console application startup thingy is a module. When I call this method in my main it works fine, if I call it from another method that was called by main it works as well.However, it doesn't work when I call it from my Timer_Elapsed sub? I guess this has to do something with threads but I can't figure it out.
Module Main Private Timer As New System.Timers.Timer Private PLC As New ACTMULTILib.ActEasyIF Private DataSet As new DataSet
I have a project that has some VB code in it that I'm not allowed to convert to C#. I work in C# and not very good at VB, but I am needing to modify that VB code to use some C# methods I created.
For example:
C#: Code: using MGCIS2.Reporting; using CrystalDecisions.Shared;
[code]....
At this line in the VB code (Dim crv As New Tax.Reports.CrystalReportViewer(_rdbc)) it is giving me an error:Too many arguments to 'Public Sub New()'
I am having some problems calling the First() method of the System.Collections.ObjectModel.Collection(Of T) class. My front-end web application is VB.Net 3.5, and the data access layer is C# 3.5. Here is pretty much the sample code I have:
I have a form call form1 which is a mdi tab. Within form1 there is a datagridview and a button. When the button is clicked it will fire a method within form1 to update and repopulate the dgv.
Now my problem now is that I have another form call form2 which I load using .showdialog. Whenever I update the data within form2, it will fire method from form1 and update the dgv in form1. However the dgv doesn't seem to repopulate the updated data.