Create A Method With Unknown Number Of Parameters?
Jun 5, 2012
Is there a way to create a method with unknown number of parameters? And if it this the case: How is it possible to get access to them within this method? Do they have to be from the same type?
Using Access 2003 and VB code, I have created a form with a number of labels. The labels will display an employee's names. I have named the labels name1, name2, name3...etc. Using an ADO data set and DCount I have determined the number of names in an Access table (the number of names can vary). What I want to do is for each record in succession to pick the first name and surname from the data set , combine them into a full name (this part has been successful), and then set the full name into the label caption in succession. Example: full name 1 into name1, full name 2 into name2, full name 3 into name3... until all names appear as labels on the form.
I created a counter to and a variable to increment the label number but when I address the caption property of the variable containing the new label (e.g. name1, name2..etc.) it throws an errer at runtime. Here is the code:
I've been creating short test apps repeatedly to try to understand some of the concepts in VB.NET.For the most part it has been illuminating.I read Bucky's .NET knowlegebase tutorial on passing objects as parameters to newly created forms. He shows how to create a new class that inherits from the base form class and define a New() method with parameters Extending the concept I thought about doing the same thing with a form that was created at design-time (In this case Form2).
I built a simple vb.net winforms project that pings IP addresses and logs the results. It works fine on most machines I've tried it on. I log the status result of the ping System.Net.NetworkInformation.IPStatus) by using the IPStatus.tostring method.
Normally this returns a text result such as "Success" or "TimedOut"Yesterday, on one machine it returned "65" ...which is not one of the enum values. I have a feeling it might be a combination of values. I ran some test code:
Dim status As System.Net.NetworkInformation.IPStatus status = Net.NetworkInformation.IPStatus.Success MsgBox(status.ToString) Which returns "Success"And this: status = Net.NetworkInformation.IPStatus.BadDestination Or Net.NetworkInformation.IPStatus.BadHeader MsgBox(status.ToString)
Which returns "11050" I suspect the "65" I saw was the result of some combination of enum values. Is there any way I can change the code in my second example to show the text names of both values? That is... any way I can see ALL values in this variable?
I'm saving path's to text files in a text file so the user himself would be able to add new data. My problem is that I need to make a loop that reads from these different text files and stores the data (but I don't know how many there might be.) This was my try to it:[code]
I have a dynamic query which returns a DataTable. This DataTable will contain a varying number of columns depending on the selection used in the query. I want an efficient way of filtering the records in the DataTable.
For Example The DataTable contains columns : A, B, C and D
I need to query this data at serveral points in my program. At some point I may need records where A=10 and C>40. At another point I may need records where A<10 and D=90 etc.etc. The selects are dymanmic, I do not now what Columns or values are needed until the code is executing.
I could simply use a DataTable Filter and build the selection string dynamically. I have no problem with this. However I was wondering if using LINQ would be more applicable. I am completely new to LINQ and would like to use it but don't know its capabilities.
(At present I am using a DataTable but in future this may change to a collection of Objects)
I'm gonna add x number of items to a listbox in form #2 form form #1. When I click the button it opens Form #2 and then I tried this code (which makes the form freeze): Dim qwe As Integer = 1 Do Until qwe = regKey.GetValue("Count") + 1 PrMaker.ListView1.Items.Add(regKey.GetValue(qwe)) qwe = qwe + 1 Loop The regKey.GetValue("Count") is a registry key which contains a integer (unknown). What is wrong, or is there another, better way, of doing this?
I am trying to print (to a text file) the fragmentation information give by Win32_Volume class using the DefragAnalysis method and have come up with the following VB.NET code:
Dim objReader As StreamWriter objReader = New StreamWriter(FolderBrowserDialog.SelectedPath + "FragInfo" + "_" + CreationDate + ".txt") Dim colItemsFragInfo As New ManagementObjectSearcher("rootCIMV2", "Select * from Win32_Volume where DriveType = 3")
[code]....
You do not need to defragment this volume.However executing this in Visual Studio returns the below:
Volume size: MB Cluster size: MB
You do not need to defragment this volume.The point here is though it does NOT work under Windows Server 2008 R2, but does work under Windows Server 2003 (when executed in Visual Studio), WMI Code will work regardless of platform.
NB: i have played with the "Console.WriteLine" and changed it to "Debug.WriteLine" to output value to immediate window.
I am trying to call a method which has two parameters using thread. How can I do this? If I pass parameter to my thread.start() method, it is giving error.
I am writing a alternative to GDI, and rigth now i am working at a logging function. The idea is that while you use the class to draw, it will write a logg of what you have done, which can be used to draw it back later. In that way i would be able to store a drawing with weary little disk usage.
How would I go about passing parameters to a method? I would want to do the following: Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ReceivingUdpClient = New System.Net.Sockets.UdpClient(6767) Dim receiveBytes As [Byte]() = ReceivingUdpClient.Receive(RemoteIpEndPoint) Dim ThreadReceive As New System.Threading.Thread(AddressOf receiveMessages(receiveBytes)) ThreadReceive.Start() End Sub Private Sub receiveMessages(ByVal receiveBytes As Byte()) 'INSERT CODE <br/> End Sub
I have a code below to make collection that bind to a gridview able to sort by clicking on the column header. The problem here is "IPerson" is unknown at compile time. I want the delegate type able to decide by getting from gridview datasource.[code]....
I have an inline lambda expression that I would like to use throughout my application. I just can't seem to find a reference on how to do this with more parameters than the element being tested. Here is a quick example of what I currently have.
Private Sub Test() Dim List As New List(Of String) From {"Joe", "Ken", "Bob", "John"} Dim Search As String = "*Jo*"
I have the following test method (VB.NET) <RowTest()> _ <Row(1, 2, 3)> _ Public Sub AddMultipleNumbers(ByVal number1 As Integer, ByVal number2 As Integer, ByVal result As Integer) Dim dvbc As VbClass = New VbClass() Dim actual As Integer = dvbc.Add(number1, number2) Assert.That(actual, [Is].SameAs(result)) End Sub My problem is that when the test runs, using TestDriven.Net, the three method parameters are 0 and not the values I am expecting. I have referenced the NUnit.Framework (v.2.5.3.9345) anf the NUnitExtension.RowTest (v.1.2.3.0).
I was familiar with the optional parameters in vb 6 and it made sense given the capabilities of the language but why the heck does VB.Net support optional parameters when there is method overloading? Which one should I use and is there a difference? If there is a difference when should I use each one?
A friend in work suggested the use on classe to store the parameters BEFORE call a method. He's said this is called "Abstract Class". My "know how" of VB.NET is small... so, I want to know of you what mode is the best way: Call a function/sub like that:
I have a large problem with inheritance in vb.net. The problem is the following:
I have 2 forms => frmBase and frmChild
In frmBase i want to create a method Called StartWorking() and i want frmChild to inherit this method.
But here is the tricky thing: when frmChild.StartWorking is called i would like the following => without calling MyBase.StartWorking()
I want frmBase.StartWorking() to be executed first and after a test in frmBase.StartWorking if blnValue is true then frmChild.StartWorking has to be activated. if blnValue is false that frmChild.StartWorking cannot be activated.
I have a COM component that I want to call using late-binding from VB.NET (using Primary Interop Assembly - PIA method). My IDL signature for the COM method looks like: HRESULT Send([in]BSTR bstrRequestData, [out]VARIANT *pvbstrResponseData, [out]VARIANT *pvnExtCompCode, [out,retval]int *pnCompletionCode);
So 2 'ByRef' parameters in VB.NET lingo, and a return value. I attempt to invoke this method like so: Dim parameters(2) As Object parameters(0) = "data" parameters(1) = New Object() parameters(2) = New Object() Dim p As New ParameterModifier(3) [Code] ..... This fails spectactularly with an exception: {"Invalid callee. (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))"}
I assume this means I'm doing something wrong in my parameterMods array. Because if I comment out setting any value of the ParameterMods array to 'True' - it works. It of course doesnt update the parameters that are [out] parameters and so it's not working as intended. Is there something else to consider since the method also has a return value? The MSDN example pretty much does exactly what I am doing, with the exception that example did not have a return value.
For example, assume that in my assembly, in Namespace A, Class B, there is an instance method with the following signature: void Test(string someString, int someOtherParm, string someOtherString ); This method is called multiple times, from multiple places in the assembly. I would like to be able build a list of all invocations of this method and the value of the someString/someOtherString (assuming they are hardcoded). In other words, I like to extract a list of calls like the example one below, if they happen in the assembly somewhere: Test("some text", 8, "some other text");
I am trying to design a Function/Sub that will need to accept a variable number of parameters. Catch is that the parameters being passed are arrays themselves. As i understand it when you pass a variable number of arguments to a method, you pass them via an array. What im looking for is to make a method that would accept this form:
Is it possible to have a class, sub or function declared with an arbitrary number of parameters? And those parameters be a type, like generics? For example
vb.net Public Class Test (Of T1, (Of T2))'The (Of T2) means that after the first parameter can be an arbitrary number of parameters
I have a dataset connection to an MS Access database. I want to use IN operator in WHERE clause like: WHERE DepartmentID IN (1,2,3)This means that all record with an ID of 1, 2 and 3 will be filtered. But the problem is I cannot create a parameter like: