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


ADVERTISEMENT

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

Pass A Type To A Constructor For Instantiation?

Mar 7, 2011

What I want to do is pass a Type to another object's constructor, where the other object creates a new instance of Type. I can create a constructor with a parameter declared as System.Type without problem, but when I try to instantiate it tells me there is no such type.

Public Sub New(targettype As System.Type)
Dim Test As System.Windows.Forms.Form = New targettype
End Sub

View 3 Replies

Pass An Object Type To A Class?

Jun 18, 2009

I create a object type entity in the main function and would like to pass it to a separate class, do some calculation, and then pass the result back to the main function. But I keep getting errors, can someone point me where I did wrong? It's in windows application[code]...

View 2 Replies

Pass Type To A Function In Program?

Jul 29, 2009

I get a compile error Type "ctltype" is not defined with this code.

This is .NET 1.1 legacy code so not good I know.[code]...

View 1 Replies

C# - Pass An Anonymous Type As A Parameter To A Function?

Aug 1, 2011

After reading this post i realized that i cannot pass an anonymous type as a parameter to a function. So what other options do i have?

Perhaps, passing a Query.ToList as parameter would help, or am i re-inventing the wheel?

Update: I have the following query, which i would like to pass to a function:

Sub Test
Dim Query = (From c In DB Select New With { .ElementName = c.Name })
DoSomething(Query)

[Code].....

View 3 Replies

Pass A Generic Type Not Having A Interface To A Of T Function?

Jun 8, 2009

I have a following code which works fine

MsgBox(AddSomething(Of String)("Hello", "World"))
Public Function AddSomething(Of T)(ByVal FirstValue As T, ByVal SecondValue As T) As String
Return FirstValue.ToString + SecondValue.ToString

[code].....

View 3 Replies

Pass Different Font Type Strings Into RichTextBox?

Feb 25, 2010

I have situation where I have to retrieve different fields from Access Database and put into one RichTextBox but they have to be displayed as DIFFERENT font types/colors.

I am able to get the database field data into RichTextBox but not able to set font styles or font colors. They are displayed in default font style. Please help me with sample code by giving example, i.e., taking two to three different string types and sending them to RichTextBox with different font color and styles.

View 2 Replies

Pass Particular WebControl Type As A Parameter In Program?

Apr 23, 2009

I'm trying to create a function that searches up a WebControl's parent-child relationship (basically the opposite of WebControl.FindControl(id as String), but looking for a specific WebControl type).

Example

I have a user control in an ItemTemplate for a GridViewRow. I'm trying to reference the GridViewRow from the user control. The user control may or may not be inside a div or other types of controls, so I don't know exactly how many parent's up to look (i.e. I can't just use userControl.Parent.Parent). I need a function that will find the first GridViewRow that it finds on the way up the parent-child hierarchy.

View 1 Replies

Pass The Type(t) When Call ToGenericType Method

May 27, 2010

I have the following generic method : Namespace Helpers

[Code]...

I would like to use type interference so that when i call ToGenericType method, I would not need to pass the type(t) This is how i call ToGenericType now.......

[Code]...

View 2 Replies

VS 2008 Pass The Type Of Export As EventArgs?

Jan 26, 2011

I'm creating buttons programatically. I want to create an ExportToExcel and ExportToWord button.

I created this class to pass the type of export as EventArgs:

The exportType is an Enum

Public Enum ExportType
nsExcel
nsWord

[Code]....

View 12 Replies

Pass Generic Type Definition To Asmx Webservice?

Feb 8, 2012

I use jQuery ajax calls to ASP.Net web services (ASMX files) to update the web page data.

I have the database storing code seperate from the domain object class code (in the example code below, there is an Animal class and an AnimalRepository class). I'm implememting a convention that all similar domain object repository classes will have a Store method .

I would like to create a web service that can cater for calling the Store method for any one of these repository classes. To get this to work, in the below code sample, the List(Of Animal) parameter would need to be a generic type.[code]...

View 2 Replies

.net - Pass An Expression To Act On A Single Field In An Anonymous Type In LINQ?

Mar 27, 2012

I have the following Data Transfer Objects defined:

Public Class MemberWithAddressesDTO
Public Property Member_PK As Integer
Public Property Firstname As String
Public Property DefaultAddress As AddressDTO
Public Property Addresses As IQueryable(Of AddressDTO)
End Class

[Code]...

View 1 Replies

Pass Values In Array List To Caluclute Sum Of Each Sport Type

Oct 26, 2009

i have a for loop retrive me sum of colums but i need to pass these values in array list to caluclute sum of each sport type

[Code]...

View 2 Replies

Forms :: Pass An Integer Into A Label - Error "A First Chance Exception Of Type 'System.InvalidCastException'

Nov 22, 2011

I have this issue with casting....is there anyway i could pass an integer into a label...this is what i have done so far but i am getting this error "A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll"

Dim firstNumber As Integer
Dim secondNumber As Integer

Dim solution As Integer

[CODE].........................

View 1 Replies

.net - ByRef Underlined With "Expression Expected" Error When Trying To Pass In A Object Of Type List(Of ClsFooDetail)?

Mar 3, 2010

I work with C# 99% of the time. However, I'm having to update some legacy VB.Net code and encountering an issue with VB.Net code syntax. The error that I get is "ByRef" is underlined and "Expected Expression" tag shows up when you hover over "ByRef". The "FooDetail.Load" function is written in C# and expects a List object passed as reference. Don't have any trouble using the same function in other C# classes. Can someone indicate what is wrong with below VB.Net code.

Dim FooDetail As New clsFooDetail()
FooDetail.FooID = FooID
Dim lstFooDetail As New List(Of clsFooDetail)
FooDetail.Load(ConnectionString, "Stored Procedure", ByRef lstFooDetail as System.Collection.List(Of(clsFooDetail))

View 1 Replies

Pass An Optional Parameter To A Function Of Type System.Drawing.Color - Error "Constant Expression Is Required"

Mar 22, 2012

I want to pass an optional parameter to a function of type System.Drawing.Color. The problem I am having is that when I declare the function it says "Constant expression is required" but I have tried variations of the following, including integers, full qualified indentifiers, even old vbWhite constants to no avail.

[Code]...

View 14 Replies

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

VS 2005 Update Table - If All Results Is PASS Then The Table2 Should Be Updated As Pass

Jun 8, 2012

I have two tables:

table1

case_no flow result
tc_1 001 pass
tc_1 002 pass
tc_1 003 pass
tc_2 001 pass
tc_2 002 fail
tc_2 003 pass


table2"

case_no result
tc_1 pass
tc_2 fail

Table2 should be updates from table based on the results... If all results is PASS then the table2 should be updated as pass... if any result is FAIL then the entire case_no should be updates a s fail..

View 7 Replies

Sockets - VB9 .Net 3.5 (2008) Code Works On The First Pass.Then Second Pass It Just Hangs On

Jun 19, 2009

This code was working consistently, but now...This code works on the first pass.Then second pass it just hangs on Code:Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient() for about 2 minutesThen the code will fork for another pass, then fail.....

Code:Imports SystemImports System.TextImports System.Collections.GenericImports System.XmlImports System.Xml.LinqImports System.Net.Sockets

[CODE]....

View 2 Replies

Pass Data To Dialog - Manipulate And Pass Back?

Jan 15, 2010

Just started VB programming this week and have found a wealth of information about what I'm trying to do. Problem is, some of it is more complete than others.Here's what I'm trying to do:In Form1 (my main form), I want to instantiate a class that contains a couple of properties (speed setpoint and position setpoint). When I click a button, I want to pass this data to Form2 and populate two textboxes on Form2 with the properties of this object. I want to manipulate the property values on Form2 and click an OK button which closes the dialog and returns the manipulated data, updating the property values of the object. Here's the algorithm I'm following:1) On Form1, instantiate the class2) On Form1's "Pass Data" button click event handler, instantiate a Form2 object and invoke the ShowDialog method, passing the object as a parameter.

3) On Form2, overload the ShowDialog method to accept the object as a parameter and modify the method so that it returns the manipulated class data.4) On Form2, in the ShowDialog method, populate the textboxes with the class data that was passed in.Here's where I get stuck. If I press the OK button on Form2 (DialogResult.OK), it returns me to Form1, but what hook do I have in Form1 to receive the manipulated class data that the ShowDialog method is returning?Here's an example of what I'm thinking about:

Code:
Public Class Form1
Dim clsController1 As New MotionController

[code].....

I'm sure it's probably a very elementary question, but every explanation I've found seems to be incomplete.

View 2 Replies

VS 2005 To Pass Or Not To Pass?

Apr 16, 2009

I am looking for some input. I am helping with a web application that is fairly large. We have some logic factored out into classes, not a true business logic layer (yet ). The classes are setup to pull values directly from the QueryString or Session variables and I'm not sure that that mehtod is proper or even a

The reason I would like some input is, there may be a chance to rewrite or at least refactor the code.

[Code]...

View 2 Replies

Determining If A Type Is A Reference Type Or Value Type

Oct 13, 2010

I've come from a Assembler and C/C++ background, so I understand the concept behind reference types versus value types in vb.net. Also, I've read Jon Skeet's article regarding references and value types and I understand all of that. My question is: How can you tell if a given type is a reference type or a value type? Is it simply that all integral types (ints, floats, etc.) are value types and all classes are reference types? (If so, where do strings fall?)

[Code]...

View 1 Replies

Asp.net - Unable To Cast Object Of Type 'ASP.webform1_aspx' To Type 'System.Web.UI.WebControls.Button'

Jan 28, 2012

when view in browser, i got this error: Unable to cast object of type 'ASP.webform1_aspx' to type 'System.Web.UI.WebControls.Button'.

how should i solve this problem?

Line 7: If Not Page.IsPostBack Then
Line 8: Dim rowIndex As Integer = 0
<b>Line 9: Dim btn As Button = DirectCast(sender, Button)</b>

[Code].....

View 2 Replies

DB/Reporting :: Conversion From Type DBnull To Type String Is Not Valid When Inserting A Record

Mar 22, 2010

I'm trying to add a new record to my database but i keep getting the message - "conversion from type DBnull to type string is not valid". I think its something to do with the Employee ID when VB attempts to save it to the database my code is below

Imports System.Data.OleDb
Public Class Add
Private Sub DisplayRow()

[Code]....

View 5 Replies

Error: Microsoft.VisualBasic: Conversion From Type 'DataRowView' To Type 'String' Is Not Valid

May 25, 2011

I now have SQL Parameters set up and I'm using them to save/delete/add my data. This all works well, except when it's trying to save a combobox to the datatable it appears with the error above.Majority of my comboboxes have datasources, and the valuemembers of these are the actual list items, not the ID's of the list items.I'm not sure why this error could be happening, I'm fairly sure I've connected everything to the binding source correctly; I've checked it a few times.Does anybody know what the cause of this could be? I've looked around a bit and I haven't found much

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

Statically Type Local Variable To Be Static Type Of Expression On Right Had Side Of Assignment?

Dec 22, 2009

E.g. how do I get VB.Net to statically type a local variable to be the static type of the expression on the right had side of the assignment?

View 1 Replies

Unable To Cast Object Of Type 'ADODB.InternalField' To Type 'System.String

Apr 19, 2010

I had write code (just for learning), the codes :

dim Temp as string
Temp = Recordset("
Table_Field")

but, when I start Debugging the error messages "Unable to cast object of type 'ADODB.InternalField' to type 'System.String"

View 2 Replies

Unable To Cast Object Of Type 'IMAPI2FS.FsiStreamClass' To Type 'IMAPI2.IStream'

Apr 13, 2011

I am implementing IMAPI2 into my vb.net project but ran into a wall. I am getting the message Unable to cast object of type 'IMAPI2FS.FsiStreamClass' to type 'IMAPI2.IStream' when trying to start the burn. I googled around and found this is something that microsoft hasn't fixed.. which basically renders IMAPI2 useless in vb.net.

I found a post on codeproject.com by eric hadden who combined the IMAPI2.dll and IMAPI2fs.dll into an c# interop file. I also see the IBURN interop in microsoft SDK samples. I'd like to use either, but it's in c# and I'm using vb express. Does anyone know a way to get the interop into visual basic or a way around "Unable to cast object of type 'IMAPI2FS.FsiStreamClass' to type 'IMAPI2.IStream'"?

View 1 Replies







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