Passing A Type As An Argument?

Aug 12, 2010

I'm using VB.NET 2003 with .NET Framework v1.1. I know it's getting a bit old now but I'm stuck with an existing program and don't have the time/knowhow to convert it to anything newer.

My question would probably be solved very easily with Generics in .NET 2.0 but as I can't use that right now, I'd like to know if the following is possible:

I have a load of manager classes which inherit from DictionaryBase and hold collections of my custom classes. For example, I have a Employee class, a Batch class, a Supplier class, etc... and each of these has a Manager classwhich holds a collection of them - eg: my PlantTrayMgr class holds collections of PlantTrays, etc..

I have one particular form where I have to populate loads of comboboxes with the contents of various Manager objects. What I currently do in my form load event to populate comboboxes is this:

Code:
Option Strict On
Option Explicit On
Private _plantTrayMgr As PlantTrayMgr

[Code].....

View 4 Replies


ADVERTISEMENT

Sql Server - Assign The Value I Queried To A String Which Is An Argument In A Procedure If The Argument's Data Type Is An Object?

Dec 5, 2011

I made this procedure re-use a select query:

[code..]

And I use it like this if I would want the selected value placed in a textbox and it works fine

[code...]

However if I want the value to be passed in a string like so:

[code...]

The string ends up having an empty string value. How do I assign the value I queried to that String?

View 2 Replies

Argument Passing In C# And .NET?

Jan 14, 2012

In VB.NET, can we pass an original object as an argument without instantiating it? For example, I have two forms in my project formA and formB. Now I have this code.

[Code]...

Apart from this, in VB.NET in any class like formA, if I type formA, I can see all the objects and controls present there but not in C#. Again, I have to make a new instance to see all the controls. This becomes a problem if I want to manipulate two running and working instances with each other. So what basic thing am I missing here?(I am an amateur programmer migrating from VB.NET to C#. Things are going nice and clean expect for the ones I've recently figured out.)

View 3 Replies

Passing Argument Into Dll Call?

Mar 7, 2010

In my vb.net code I want to call a dll file created by Qt4.

Now everything works fine untill and unless I pass some string argument to the function.

Here is the function in dll file:

const char* QtEngineDll::randInt(char url[])
{
QString result;
/*QTextCodec *codec = QTextCodec::codecForName("UTF-8");

[Code]....

When the function returns some constant value, say if i put result = "Abhijit" then it returns the value properly. But if I want result to return value url the it is returning some garbage values.

View 8 Replies

Passing Argument To Or From A FORTRAN DLL From .NET?

Feb 1, 2010

I have a DLL written in fortran that I know works because I am getting it from a working software package that we use daily. I am trying to call it from anything but am having problems i believe with passing the correctly formatted arguments in and out of it, so i decided to try and access it from a VB program. I chose VB because I have contacted the developer of the software package we are using and he gave me his DLL function call in VB6, even though he is not allowed to show me the FORTRAN source.

Problem is (perhaps, i think) that I am writing in VB.NET, which has different data types than VB6. Can anyone see why i am am having problems. The error i get upon running is: "AccessViolationException was unhandled: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

[Code]...

View 3 Replies

Passing Argument To Shell()?

Jan 5, 2009

I'm designing an interface using visual basic .NET with visual studio tool. In my program I have to call an extern .exe using the function shell() and pass a FileName to it. The problem is that what it passes to the executable is never the file path. My code is this one and I think it should work but I don't know why, it doesn't.

Public Class FormMain
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[code].....

View 15 Replies

Passing Array As Argument?

Feb 28, 2010

When I try to do the same in .net the "array argument" value of the second sub is either Nothing or I get an error saying "Value of type 'String' cannot be converted to'System.Array'."I've tried converting the array to a system.array but it will not hold all the Types of data it needs to hold. (I tried 3 days ago and don't remember what Types would cause an error. My 1st value is a string and the second is an integer and this caused some error.)

View 1 Replies

Passing Url Based Argument

Mar 27, 2011

I have written an application to register a url type extension at startup so in short if user inputs dld:// in any browser it loads my app now, what I want to do I want to somehow move a bit further like if user goes dld://about the application loads and shows the about page

View 5 Replies

Generics Compiler Error: Type Argument X Does Not Inherit From Or Implement The Constraint Type Y?

Mar 1, 2012

I've spent quite a bit of time reading up on generics, covariance, etc., and I am failing to understand why I get the aforementioned compiler error in this type of codeLet's say I have a base "Bill" class made up of a collection of Lines..

Public Class Bill(Of L As Line)
Private _lines As List(Of L)
Public Property Lines() As List(Of L)

[code].....

View 11 Replies

Change Variable Value When Passing As Argument

May 18, 2012

is there a way i can do like this in vb.net

[Code]...

what i want is that idx keeps incrementing after each line, without incrementing it on a seperate line.

View 1 Replies

Force Passing Argument Byval?

Sep 16, 2010

I have an old unmanaged dll function and I want to pass an array to it.The dll function expects the array to be passed by reference.Sometimes I can do that and sometimes I need to pass a pointer in a variable.Is it possible to override the declare for the function so that I could pass either the array by ref, or a pointer to it if I need to?

View 15 Replies

Passing Command Line Argument?

Dec 15, 2011

I am a beginner using Visual Studio Express 2010 to create a small console app to use as a utility accompanying another primary app that can pass a command line to the utility. I would like to set it up so that the utility will not run independently but only run and load its only form (Form1) if it is launched by the primary app using a "/run" command line parameter. (I can set up the primary app to launch and pass a command line parameter. I need help with the utility's code.)

The utility already has some VB code, so I need to figure out what code to add to receive and act on the " /run" command line and even more challenging for me, where to place this new code so it works.

pseudo-code:

initial event to read the command line, then if it is " /run" load Form1, else do not open and run utility app.

View 13 Replies

Error : Type Argument 'TChannel' Does Not Inherit From Or Implement The Constraint Type 'System.ServiceModel.Channels.IChannel'

Apr 8, 2010

I have the below lines of code :I am getting the error as mentioned in the Title above.This error has come after converting a C# Code to VB.NET Code which is mentioned below:

C#:
public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
{
if (context == null)

[code]....

View 1 Replies

BackGroundWorker Passing Argument In RunWorkerCompleted Event?

Jan 15, 2012

my current solution as you can see is by using shared variable within a class in order to pass a value.

on the form load of my application i called: workerSample.RunWorkerAsync

Dim finalList As List(Of String)
Private Sub workerSample_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles workerSample.DoWork

[Code].....

View 1 Replies

Passing A Array As A Argument To A Javascript Function?

Apr 20, 2011

Im trying to pass a array as a argument to a Javascript function from code behind(vb.net)
Code im trying

[code].....

View 2 Replies

Passing Structure As Argument Through Files / Functions

Jun 21, 2012

I can't get to pass structure as argument through subs/functions in different files of single vbnet project like I use to in earlier MS basic versions.[code]File "mysetup.dat" is reachable and data is saved correctly what I can see with HxD.But read part seem's to not work as expected. Please any help on reliable passing structure as argument without too much public elements based on upper example.

View 1 Replies

VS 2008 - Passing Class As Argument For Function

Mar 23, 2010

VB.NET is not letting me dance with both feet, or piss with both hands. I've got one foot and one arm tied behind my back at every turn. I want to use this statement in a function:
Return CType(Formatter.Deserialize(FS), DS)
Seems doable, right?

Function ReadFileStream(ByRef FS As FileStream, ByRef DS As Object)
Dim Formatter As New BinaryFormatter
FS.Position = 0
Return CType(Formatter.Deserialize(FS), DS)
End Function

Right? I mean, CType only accepts a class name as the second argument. I can't give it an instance of a class, or it croaks. Yet if I try to pass the class name as the argument to that function:
DataInfo = ReadFileStream(FileStream1, DataStruct)

VB.NET croaks on this, too, complaining that "'DataStruct' is a type and cannot be used as an expression.". It's used as an expression by CType just fine outside of the function. Does the VB.NET legislature provide a clause that allows for a 'Type' to be passed as an argument in a function? Writing all the supporting code ten million times to deserialize a file using CType ten million times in a large application will get very complicated and tricky very quickly. It should be handled by a routine so that any cases and adjustments that come up can be dealt with in one spot.

View 8 Replies

When Passing An Object As An Argument To A Method, String Properties Are Populated But Integers Are Null

Jan 27, 2011

I have a class and method exposed to a client asp.net app. The class looks like

<DataContract()> _
Public Class Class1
Private v_string As String
Private v_integer As Integer

[code]....

The method is declared as

<OperationContract()> _
Function GetStuff(ByVal bar As Class1) As String

In the client code I create an instance of Class1 and set the values for v_string and v_integer, but using Wireshark to look at the xml being sent to the server only a value for v_string is being sent as part of Class1. I'm guessing this is because it considers the value of v_integer to be null/not set. Here is an example of the client code.

Dim MyService as New Service1.ServiceClient
Dim test as New Service1.Class1
test.P_integer = 1

[code]....

how different types are passed/used since Integer is a intergral type and String is a class, but can't seem to work out what to do to fix the problem.

View 4 Replies

Entity Framework Error - "Type Argument 'Namespace...EntityName' Does Not Satisfy The 'Class' Constraint For The Type 'TEntity'"

Feb 28, 2011

I have the following two tables defined...

CREATE TABLE [LogLevel] (
[Id] int primary key
,[Name] nvarchar(50) not null

[code]....

After creating a fresh endity model, I add the two tables above. When I try to build I get the following errors...

Type argument 'Inxsol.CommandPlan.Data.Model.Log.LogLevel' does not satisfy the 'Class' constraint for type parameter 'TEntity'.
Value of type 'System.Data.Objects.DataClasses.EntityReference(Of Inxsol.CommandPlan.Data.Model.LogLevel)' cannot be converted to 'System.Data.Objects.DataClasses.EntityReference(Of Inxsol.CommandPlan.Data.Model.Log.LogLevel)'.

[code]....

View 1 Replies

Sql - Passing Parameters To A Stored Proc Accepting In Parameter Of Type XML Type?

Jun 7, 2011

I have a storedproc accepts parameters in XMLtype as

CREATE OR REPLACE PROCEDURE GetDetails(
p_para IN XMLTYPE,

[code].....

View 1 Replies

Possible To Have An Argument Of Any Type?

Sep 6, 2010

Is it possible to have an argument of any type? Here's what i mean:[code]

View 3 Replies

Argument 'Date1' Cannot Be Converted To Type 'Date'

Sep 30, 2011

Why when I press button without enter the data to one of the field I got:

Argument 'Date1' cannot be converted to type 'Date'.[code]...

View 7 Replies

Function Returning An Object With Type Specified In The Argument

Mar 22, 2011

How can I create a function that returns an object of a certain type, which the user of the function specify in the argument (using vb.net 2010) ?

[Code]...

The code above doesn't work, but maybe it can explain what I want to achieve. Using this feature, I want to hydrate my data transfer objects from datatable. Client will just call this function, specifying which DTO the client wants, and this function will just create that DTO and populating the properties with reflection GetType.GetProperties().

View 2 Replies

Deployment :: File Type Associations And Command Line Argument

Feb 21, 2009

How would that work? I can't find any documentation in the MSDN.you know how when you open a txt file it opens up notepad and loads the file? how does the whole 'loading the file' thing work in VB?

View 1 Replies

Is A Delegate Type And Requires A Single 'addressof' Expression As The Only Argument To The Constructor

May 10, 2010

I got 2 classes in a form, and I would like to pass a value from a textbox to the other class, so I decided to use Deligate.

Below is the code.

Public Delegate Sub delPassSize(ByVal text As TextBox)
'To get size from Class Calculate(Class 2)
Public Sub GetSize(ByVal txtForm1 As TextBox)

[code]....

and the error message is 'cls.Getsize is a delegate type and requires a single 'addressof' expression as the only argument to the constructor.'

View 2 Replies

.net - FileInfo Passing FileInfo Argument To Method?

Oct 12, 2011

I have the following VB function which takes a FileInfo object as a parameter:

Public Shared Shadows Sub Start(ByVal filePath As FieldInfo)
XmlConfigurator.ConfigureAndWatch(New System.IO.FileInfo(filePath.ToString()))
End Sub

In another class I have the following code calling that 'Start' method. But VisStudio indicates there is a problem with the 'FilePath' argument that I'm passing.

[Code]...

View 1 Replies

Passing Base Object Type When Using Inherited One?

Oct 8, 2010

I have a project that has mainly two objects, both inheriting from a base. Like this:

Public Class Vehicle
Property Model As String
Property Make As String[code].....

The above function doesn't work because myVehicle is a Vehicle, not a Truck.Is there a way I can pass around a Vehicle type and have the IDE know which type to use? Or am I completely missing a better way to do this?

View 5 Replies

Passing Parameter (Value Or Referenced Type) Into Method?

Nov 11, 2009

What happened when parameter passing. Here is a test project I write.
Public Class Form1
'1.test string
Private Sub btnString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnString.Click
Dim str1 As String = "x"
[Code] .....

From the project you can see, when pass integer type parameter (value type) into a method , if use ByVal keyword, the value won't change. If use ByRef keyword, the value will change (I can understand it, to my understanding, when using ByVal, It pass the value of the argument to the method; when using BvRef, it pass the address of the argument to the method, so the value can be rewrite)

Well, for the following two scenarios , I can't understand why.
String type is reference type, but it acts like integer type.
Val type is also reference type, but no matter what you use(ByVal or ByRef), the result will be the same.
So my question is what actually passed into method? What's the underlying mechanism about pass parameter? What's the effect of ByRef and ByVal to value type and reference type?

View 1 Replies

Passing Winapi 'HANDLE' Type Between VB & C Code

Feb 23, 2011

I have written some C/C++ code that uses the winapi functions CreateFile WriteFile SetFilePointer etc. to read & write some large (>4 GB) binary files. Some colleagues who are more familier with Visual basic than C, want to modify some of their existing code to call my C code functions.

I have turned my code into DLLs that I have successfully called from other C programs. I have also created a small C DLL that doesn't use the winapi functions & called it from a small VB program.

What I haven't so far been unable to do is pass the HANDLE type variable between a C function that uses the winapi functions & the VB program that call it so the VB can call another of my functions & pass the HANDLE.

In my attempt to do this, the declarations in the header file for two of the functions in the C DLL are:

[Code]...

When I step through the VB code in debug mode there is no problem with calling OpenSegyRW, but at WriteToSegy I get the error message:System.Runtime.InteropServices.MarshalDirectiveException was unhandled

Message=PInvoke restriction: cannot return variants.So what am I doing wrong & is there any way to pass the winapi HANDLE type between VB & C code? BTW indents etc. get lost when I paste my message into the forum. I hope this is decipherable.

View 3 Replies

Reflection - Passing Values To Constructor Of Type T?

Jun 18, 2012

I have this code to get the default constructor:

Public Function f(ByVal t As System.Type) As Object
Return t.GetConstructor(New System.Type() {}).Invoke(New Object() {})
End Function

I need to pass values to the Constructor as

Public Function f(ByVal t As System.Type) As Object
Return t.GetConstructor(New System.Type() {someInteger,someString,etc.etc}).Invoke(New Object() {})
End Function

Also I have 3 classes of Type T, with all having different parametric constructor. It's important for me to have it generic as the Classes of type T might increase in future with less or more parameters.

View 1 Replies







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