Pass A "type" As An Argument?

Jul 2, 2009

I want to do something like the following in VB.NET, is it possible?

Function task(value as Object, toType as Type)
Return DirectCast(value, toType)
End Function

View 3 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

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

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

How To Pass Array As Argument

Mar 6, 2010

Does the following work in VB 2008 for passing an array to a function:
Public Function functionname(ByVal array1() As Short, ByVal array2() as Short) As Short
Also, can ByRef be used in place of ByVal?

View 2 Replies

Pass An Address Of A Sub As An Argument?

Feb 12, 2011

Private Sub SpecialMenu( ByVal ddItems As ToolStripItemCollection, method as ??)
...
AddHandler ddItems(item).Click, AddressOf method
...

How can I pass a sub address into a subroutine.

I understand delagates but not enough to figure this out.

I have a sub that creates and adds menu items to a menu and I need to use it in more than one project so I want to put it into a library.

But I don't know how pass it the address of the subs to attach to the new menu items.

View 3 Replies

Pass Argument To Sub Then Add To ListView

Mar 5, 2009

I am trying to pass an argument to a sub then have it add to my listview, my code is:

Module modFunctionsSubs
'Function and sub routines
'This sub logs an even in the listview
Public Sub logEvent(ByVal statusText As String)
listViewMainLog.Items.Add(statusText)
End Sub
End Module

My argument is getting through ok, statusText but I get an error:
'Name listViewMainLog is not declared'

View 3 Replies

Pass More Than 2 Argument To Events

Nov 10, 2009

Can we pass more than 2 argument to our events, tell me in brief about Events

View 1 Replies

Forms :: Pass UserControl As An Argument?

Sep 8, 2010

I've got several user controls and every time I add them, I post this

Dim uc As New ucTemplates ' 'ucTemplates' is the name of the actual user contrll
gbControls.Controls.Clear()
gbControls.Controls.Add(uc)

So, I'd like to create a sub that does the same thing, passing the usercontrol as an argument

Private Sub AddUC(myControl as UserControl)
gbControls.Controls.Clear()
gbControls.Controls.Add(myControl)
End Sub

But - when I try:
addUC(ucTemplates)

I get an error that ucTemplates is a type and cannot be used as an expression
I can get it working if I add the Dim uc As New before the addUC - but I'd rather have it so I only repeat one line, not 2

View 1 Replies

How To Pass A Command Line Argument

Feb 16, 2012

I know how to pass arguments between two dotnet applications! However I have hard time with this: I want to pass a command line argument. for example; test.exe is a console application (none dotnet) self terminating app. From cmd.exe if I type "test.exe -v" the cmd output text will display the test.exe version info. If I place the test.exe in the same path as my VB.net app.What I want to do is:

[Code]....

View 7 Replies

Pass Any Command Line Argument?

Jan 4, 2006

How, can i pass any command line arguments (Through Run Command)pass when my VB application execute and that's valuesare receive when form activate.

View 12 Replies

Pass Argument When Form Is Loaded?

Mar 28, 2011

I have created my app to load with a argument

now, what I want to know if it's possible to pass the load argument even if app is loaded

like

app.exe -a = loads a special form on app.exe at load time

and if app.exe is already loaded to load same form if user requests it again from a shortcut or so

View 12 Replies

Pass Listbox Control As Argument?

Feb 16, 2012

<p>I'm trying to use a function that takes a variable referring to various listboxes.</p><p>Something along the lines of:</p><p>Calling code:</p><p>...</p><p> Dim lstBox
as ListBox</p><p> if a=1 then lstBox = Me.ListBox1 else lstBox = Me.ListBox2</p><p> MyFunction(lstBox)</p><p>...</p><p></p><p>Called function:</p><p>
public sub MyFunction(lstCtrl as ListBox)</p><p></p><p>lstCtrl.Add()....</p><p></p>

View 8 Replies

Unable To Pass String Argument?

Mar 7, 2010

The problem that I am facing is that I want to call a shared DLL created by qt4. Now reading the result from the DLL file is working well and good. But the problem arised while passing arguments required by the function in the dll file.The argument (both string or int) is not passed properly. Suppose I pass an integer argument 8, but 1 is passed. Whatever is my input only 1 is passed.

View 2 Replies

Pass An Argument To Dispatcher Object In Program?

Aug 22, 2010

In a threaded app in VB 2010, I can do this[code]...

View 6 Replies

Pass An Array Of Arrays As A Function Argument?

Nov 11, 2010

I have several parameters consisting of separate System.Byte() arrays. What I need is the syntax for a function declaration where the parameter is an array of arrays - I do not want to delve into System.Collections, and it's my preference not to CType each array into an Object and then back into a Byte().

Problem I'm having here is that:

Public Function MyFunc(arrayparam() As System.Byte) As System.Byte()

accepts a single-dimensional Array of individual Bytes.

Then Public Function MyFunc(arrayparam() As System.Byte()) As System.Byte()

View 12 Replies

Pass Clicked Button As An Argument In A Function?

Apr 26, 2011

How can i pass the button click as an argument in a function.

View 6 Replies

Use Form Handle In Class Without Pass It As Argument?

May 3, 2012

I'm writting a class that needs the form handle but there is a way to use it without send it as argument in the class constructor or in a property?I know that the handler is not set until the form is completely loaded so that is another problem too.The basic idea is catch the form handle without pass it as argument and handle the wm messages.

View 2 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

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

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

Convert String Value To Type And Pass As Type Parameter.

Nov 19, 2010

i am getting all filenames from a directory.parsing out the directory names & the .vb extension then converting those filesnames to classes.Every file in the LPCriteria direcotry is its own class with a "Evaluate" function.[code]

View 1 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

Pass A Value From A Sub Procedure To A Function Procedure .... Pass The Whole Subprocedure To The Function Procedure Argument?

Mar 30, 2012

Im a student doing an assignment, how do i pass the value from a sub procedure to a function procedure....i want to pass the value from decSubtotal to a function procedure named CalculateDiscount; check out my code--

[Code]...

View 1 Replies

Pass A Type To A Sub?

Dec 19, 2011

I have the following sub which works for the type "Button". I would like to make it general by having a parameter that is assigned a type rather than "Button" being hard wired. Can this be done? How do you pass a type? I tried the parameter "ByVal t as Type" but the compiler complained when I used t as a type and I also tried inserting (Of T)but the compiler complained about CType(control,T).

how add type as an input to this sub?

Public Shared Sub Example(ctrl As Control, items As ToolStripItemCollection)
For Each control As Control In ctrl.Controls
If TypeOf control Is Button Then
Dim butt As Button = CType(control, Button)

determine which component had been clicked?

View 13 Replies

Generic Mustinherit Class - Receive: "Type Argument BaseObject Is Declared 'MustInherit' ?

Aug 23, 2011

i have 2 mustinherit classes where one is a generic one:

'Visual Basic 2008 - .net 3.5 - Any CPU
Public MustInherit Class BaseObject

End Class

Public MustInherit Class BaseObjectList(Of T As {New, BaseObject})
Inherits List(Of T)
End Class[code]...........

i receive: "Type argument BaseObject is declared 'MustInherit' and does not satisfy the 'New' constraint for the type parameter"users would never enter data in the wrong form,files they choose to open would always exist and code would never have bugs.

View 1 Replies

Event Argument For The Form Click Event Has The Type "TimedEventArgument"?

Dec 23, 2009

As you noticed, in the code bellow, the event argument for the form click event has the type "TimedEventArgument".When the event is raised, e.Time holds the time where the form was clicked.Add the missing code in the class Form1 to make this work.You will not change anything to the methods "Form1_Click" or "Form1.Load".You will not use Option Strict On. HOWEVER, you will not do any narrowing or late binding that wouldn't have been allowed if Option Strict was on.You cannot create any new Class, Structure or Module.You cannot cast the EventArgs to TimedEventArg in any way

[code]...

View 10 Replies







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