Optional Structures As Arguments?

Mar 16, 2011

It says that I can't have structures as optional arguments.That's really annoying for my program. Isn't there any way to circumvent this?

Sub fa(Optional ByVal colz As System.Drawing.Color = Color.AliceBlue)
End Sub

This example cannot compile

View 14 Replies


ADVERTISEMENT

.net - Call Method From C# With Optional Arguments?

Mar 3, 2010

I have a method written in VB.NET. It looks like this:

Shared Sub SomeMethod(ByVal Id As Guid,
Optional ByVal str1 As String = "foo",
Optional ByVal str2 As String = "")

I want to call this method from C# 3.0 and I want it to use its default arguments. I tried passing System.Reflection.Missing.Value, but I cannot cast it as String. Is there any way to do that?

View 3 Replies

Create Sub Signature With Multiple Optional Arguments?

Oct 8, 2010

Is it possible to create a sub signature with multiple optional arguments.Private Sub TestProcs(ByVal sentotal As Integer, Optional ByVal stext1 As String = "",Optional ByVal stext2 As String = "",...,Optional ByVal stextn As String = "")

View 1 Replies

Passing Structures As Arguments For A Fortran DLL?

Sep 11, 2010

I could pass a User Defined Type data structure to a Fortran DLL, that contained Short Integers, Singles (real variables) and a series of Fixed Arrays, both short integers and real variables.I am upgrading my VB6 app to Visual Studio 2008 - VB, and I want to keep the same data structures as they are used in about 300,000 lines of code.I modified the Data Structure as follows below, making sure it is of Explicit Layout, since I want the position of all variables to be the same both in VS 2008 and Fortran.Two problems arise:

1) if the LayoutKind is Explicit, such as in the example below (only part of the data structue is shown, where "..." indicate part of omitted data structure members), whenever I try to run my app, I get the following exception message, which indicates that the VBFixedArray declared at Offset 154 is in conflict with some other object, unnamed by the exception handler.

Message="Could not load type 'MyApp.SomeStruct' from assembly 'MyApp, Version=1.32.3906.33480, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 154 that is incorrectly aligned or overlapped by a non-object field."

Source="MyApp"
TypeName="MyApp.SomeStruct"
StackTrace:[code]....

2) if the LayoutKind is Sequential, the app will start, all the data preceding the VBFixedArrays is passed to the Fortran Dll without problem; everything that follows the VBFixedArray is garbled and unusable. To check this, I have made a Fortran subroutine in the Dll to which I pass both the Data Structure and a vector; in the Fortran subroutine, all the elements of the data structure are equivalenced to individual positions in the vector; upon return from the Fortran subroutine, I compare the elements of the data structure and those of the vector.

The problem here is that the Data Structure contains some 1300 names, and is used extensively in the application, as it is the way to pass elegantly a lot of data pertaining to a mathematical model with only one adress when accessing the Fortran Dll, in which the computing engine lies.

<StructLayout
<StructLayout(LayoutKind.Explicit, Size := 9226, CharSet := CharSet.Ansi)>
Public Structure SomeStruct[code]......

View 5 Replies

(2005) Arrays Of Structures Within Structures?

Jan 20, 2009

I have a structure called 'Scheme' and in my program I want (ideally) an ArrayList of 'Schemes' (so i can add, remove schemes etc.). However, within the 'Scheme' structure, I want to have an ArrayList of 'Item''Item' is another structure. Are there any solutions out there for iterating through these arrays quite easily?

How can I easily add multiple Items to a Scheme and mutliple Schemes to my Scheme array. Code is below. When I try to add Items to a Scheme, I get the 'Object not set to a reference of an object, try the 'New' keyword', but you cannot declare 'New' keywork within a structure.

[Code]...

View 4 Replies

Optional Date Value In One Of My Sub - Handle The Default Value For An Optional Date?

Mar 6, 2010

I am trying to have an optional Date value in one of my sub but since you cant set Date to nothing, this doesn't work. And i cant set it to the Date.minvalue inline.

Private Sub abc (ByVal A As String, Optional ByVal B As Date = Nothing)
End Sub

So, i went and set it to some date in the past.

Private Sub abc (ByVal A As String, Optional ByVal B As Date = #1/1/2001#)
End Sub

what would be the proper way to handle the default value for an optional Date?

View 3 Replies

Structures And Arrays Of Structures?

Jun 2, 2010

I read in the Book "Mastering Microsoft Visual Basic 2008" about "User-Defined data types".The example given is creating a Structure as follows.I wanted to check that so I wrote all the code given; I used a TextBox and a Button for this.(I didn't include the "CheckDate" here; that is in the book)

Structure CheckRecord
Dim CheckNumber As Integer

[code]....

The problem is this does work.What I get is "00000". and I found out that the "Checks(4)" Array does hold any value ie: on keeping the cursor over that, it shows "CheckAmount 0.0, CheckNumber 0 , CheckPaidTo Nothing ".

View 1 Replies

Create A List Of Structures Within A List Of Structures?

Jul 20, 2009

I'm attempting to create a list of structures that contains a list of structures. I can't seem to figure out how to properly allocate the object for the inner list of structures. I expect the outer list of structures to have a couple thousand entries and the inner list of structures to be fairly small at 2 to 10. Both lists will grow over time but the number of elements within the inner list will be constant for an instance of the outer list. Meaning, if an instance of the outer list has 2000 entries each of those will have the same number of elements on the inner list, say 4 entries.

Here is a simplified code fragment. This fragment makes no attempt to create the instance of the inner list "StructBlist" since I can't figure out where to put it. Tried "New List(Of StructB)" in the declaration as well as "Alist(0).StructBlist = New List(Of StructB)" but neither works.

Public Class Form1
Structure StructA
Dim FieldA1 As Integer

[Code]....

View 5 Replies

Convert Optional Into C#?

Jun 26, 2012

I'm trying to convert come vb.net code into C# from another programmers old work but came across optional in one of the functions.[code]...

It seems like instead of using overloading, VB.Net has an option to create it into one method/function. Does C# have a similar equilvalent or do I have to create a method for each possbility?

View 3 Replies

Using Optional Third Party DLL?

Dec 21, 2009

I have a third party dll that contain a class, SampleClass1

Public Class SampleClass1
Public SomeValue As Double
Public Function Test() As Double

[code]....

My intention is if the dll is found, use it. Else ignore it. However, if the dll is not found, the program throw an Invalid OperationException.

View 7 Replies

.net - Optional Where Clause In Query?

Jan 27, 2010

I have an application that does a search of our database (exposed via EF) for records meeting certain conditions. We have two main tables (Jobs and Recipients). Recipients are linked to the Jobs table by a Job ID.The job record has various fields (Process Date, NameJobType). The recipient has a lot of Name and ID fields (e.g. Account Number, Surname, etc)

View 1 Replies

Adding New Optional Node On XML?

Oct 15, 2009

I currently have this XML schema :

<PSC5>
<POI_ORI>
<CIT>LIM</CIT>
</POI_ORI>
</PSC5>

if user want to add a new option, the final schema will be :

[Code]...

View 3 Replies

Isnothing(foo) And Optional Args?

Mar 30, 2012

I'm looking at an old module to add some new features. I noticed this in a subroutine declaration:sub foo(...,optional fum as integer = 0)the later if not isnothing(fum) then <do something>I'm wondering, will <do something> ever be executed? I'm guessing not, since fum has a default value, but I want to be sure I'm getting this correctly.

View 12 Replies

Optional Where Clause In Query

Apr 25, 2012

I have an application that does a search of our database (exposed via EF) for records meeting certain conditions. We have two main tables (Jobs and Recipients). Recipients are linked to the Jobs table by a Job ID.The job record has various fields (Process Date, Name, JobType). The recipient has a lot of Name and ID fields (e.g. Account Number, Surname, etc)I want to present a search screen where they see a list of fields to search on. The ASP.net code then sees which textboxes the user typed in (or selected), and builds a query based on that. [code] Where I'm stuck is figuring out how to add in additional where clauses. Should I just use Entity SQL?Can this return strongly typed EF objects as well? And is it possible to return both the Jobs and Recipients objects?

View 1 Replies

.net - Utilize Optional Parameters In Delegates?

Aug 6, 2010

However, I am wondering if there are any workarounds or plans for incorporating this feature into VB.NET in the future?What I'd like to do:

Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, optional ByRef BufferPosition As Integer = 0) As T
'Implementation of a func that matches the delegate'
Class A
Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
....

In the absence of specifying "optional" inside the actual delegate itself, it'd at least be nice to be able to do it in the function implementation only:

Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, ByRef BufferPosition As Integer) As T
'Implementation of a func that matches the delegate'
Class A
Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
....

At least this second way, the functions for the delegate will always have a value mapped to each parameter, although some may come from the function side and not the calling side.

View 2 Replies

Add A Optional Parameter In Visual C# Function?

Mar 14, 2012

How can i create a optional parameter in C# as we create in VB.Net

Public Sub Demo(ByVal a As Integer,Optional ByVal b as integer=3)
End Sub
I want to declare this in C#

[code].....

View 2 Replies

Asp.net - Get By Reflection The Value Of A Property Whose Getter Has An Optional Value

Feb 23, 2012

I am retrieving several properties of a control. Here is how I used to retrieve properties (with pinfo of type PropertyInfo):

value = pinfo.GetValue(obj, nothing)

That worked well, but now I am facing a property that has a optional value, and I get an error message telling me that the number of parameters is incorrect. So I changed my code by this one:

Dim index As Object() = {Nothing}
value = pinfo.GetValue(obj, index)

At this point, I didn't get any error message, but this code doesn't retrieve the good value. It only works if I replace Nothing by the default value provided by the property accessor...

But I don't know in advance what this default value is! And this code is within a function that retrieves properties that doesn't have optional values, so I cannot change the code especially for one case or another..

I am working on .NET 2.0

EDIT: More precisions about the case leading to the problem

Here is an example of property leading to the problem:

ReadOnly Property Foo(Optional ByVal Number As Integer = -1) As String
Get
If Number = -1 Then

[Code]....

With this kind of property, none of the codes above retrieve the good string.

My best guess would be to try the first code for general purposes, catch the appropriate exception, and then dynamically retrieve the default value of the parameter (Number in that case) and its type, so that I can call getValue with this default value.

So, How can I retrieve the default value of the optional parameter?

View 2 Replies

Asp.net 1.1 - Assign Null Value To Optional Parameters In .NET 1.1?

Dec 21, 2010

I tried DbNull.Value but no luck. How do I assign a default value as null to a string parameter that is null in VB.NET? Its litte strange to see that VB does not have anything like plain null as most of the other languages do. Also what is the difference between null and DbNull and Nothing.

View 3 Replies

C# - Handling Optional .NET DataSource Parameters?

Aug 9, 2011

What is the standard way to implement optional query parameters in a .NET WinForms application?In other words, only query on a field if the value of a corresponding control is not null.

EDIT: I use a FillBy method which calls a query in my Access database. In the TableAdapter query editor, I just used WHERE (field1 = ?) AND (field2 = ?) ... I just can't find the "hook" to bind form controls to the table adapter query parameters and so that if a form uses the default value to not query on it.

View 2 Replies

Error : Optional Parameters Must Specify A Default Value

Jan 21, 2011

Public Function Foo(ByRef a As AClass, _
Optional ByRef b As BClass = Nothing, _
Optional ByRef c As CClass = Nothing) As XClass

Error : Optional parameters must specify a default value.

View 2 Replies

Have An Optional Parameter Of The Type List?

Sep 25, 2009

Is it possible to have an optional parameter of the type list?Ex.

Private Function TestFunction(Optional ByRef MyList As List(Of Double))

The real problem is giving the list a default value. When dimming a new list, you can use the code below to give it a starting value:

Dim MyList As New List(Of Double)(New Double() {1, 2, 3, 4, 5})

But even after trying many variations of the above code, I cannot get it to work as an optional parameter.

View 16 Replies

Insert Data To Optional Fields?

Feb 27, 2012

I have some fix fields in my database but user can add some another fields to my database if s/he needs. How can I insert data to this kind of fields if there are? For fixed fields I have used the follow cods

Dim rs
As New OleDb.OleDbCommand(
"INSERT INTO Wind_Parameters (ID, Name, CrX, CrY) VALUES ('" &
ID &

[Code]....

But I can't add optional fields to this code. I think I should use UPDATE syntax for fill optional fields after running this cod but I couldn't find correct syntax for it in visual basic 2010

View 8 Replies

Optional Fields In InfoPath; Getting The XML Node With VB

Apr 12, 2010

I use VB to get data through my form. I have some optional fields in my form and I have a problem with the following code:

MsgBox(myXPathNavigator.SelectSingleNode( _
"/my:Status/my:Questions/my:Questions1", Me.NamespaceManager _
).IsNode.ToString)

When the optional field 'Questions1' is inserted into the form I get the value 'true' by the IsNode() function.

If the field it is not inserted I have an exception stating that the reference is not correct (and it is indeed true). Is there a way to verify about a node, whether it is present or not in my form?

View 1 Replies

Optional Parameters Cannot Have Structure Types?

Jan 12, 2010

I would just like to know why. optional parameters cannot have structure types?

View 4 Replies

Optional Readonly Property In Interface

Aug 25, 2009

I am trying to develop a simple interface for allowing quick lists to be generated from classes. Basically, the interface needs to return an ID and a Name. However, some classes have a calculated name property which is read only, others just use a read/write name property. Basically, all I care is that it has a getter, it does not matter if the property has a setter. How can I write this interface to handle either or without throwing compile errors?

View 1 Replies

Passing An Optional Parameter To A Webservice

Nov 1, 2010

Is there a way to pass an optional parameter to a webservice, instead of having to overload the method?If the webservice user is accessing the webservice directly, I want to do ActionA, if the user is accessing the webservice through my web interface, I want to do ActionA + ActionB.

View 1 Replies

Possible To Make A Node Optional In XML Literals?

Nov 22, 2011

Dim task As XElement = <task>
<body>body</body>
<optional><%= myVar %></optional>

[code].....

View 1 Replies

Run-time Error '449': Argument Not Optional

Jun 30, 2009

I am getting this error when debugging a VB application. The method that is being called when I get this does not have any arguments. Definitions in code are as follows with names changed to protect the guilty

[Code]...

The question is, if the method is not defined to accept argments, then why am I having a debug assertion while debugging that says that the arguments are not optional?

View 15 Replies

RunTim Error '449': Argument Not Optional

Oct 12, 2010

I have an Image.OCX which is build on 2008. This is used by VB Application.Many OCX methods are not used in Application. I want to delete unused method from OCX.Step for method deletion.

Delete exists Method from .ODL File i.e //[id(181), helpcontext(11)] long CreateImage(ID id);.
Delete
CreateImage same function . Delete //DISP_FUNCTION(CImageCtrl, "CreateImage", CreateImage, VT_I4) from Ctrl.cpp.
Delete interface ID from AFX_DISP_ID.

[code]....

Following Error Message display "Run Tim error '449':Argument not optional."

let me know is that possible to delete exist method from OCX and How?

View 3 Replies

Set An Optional Byte Array In Function

May 2, 2011

I can't figure out the syntax for having an optional byte array in a .net sub Public SubMy Function(ByValFilename as String,OptionalFileData as Byte())The optional keyword requires me to set a default value - which is understandable, but I cannot figure out the syntax to do that here. Public Sub MyFunction(ByValFilenameasString,Optional FileData as Byte(){0})

View 1 Replies







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