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
ADVERTISEMENT
Apr 12, 2012
I have a query like so:
Dim clcexists = (From p In dbContext.Signatures _
Where p.StudentID = people_id _
And p.ContractType = "clc" _
Order By p.ID Descending _
Select p)
Later I check whether any rows exist in clcexists using IsNothing like so:
If IsNothing(clcexists) Then ' If no CLC is on file.
clcfirst = Date.Now.Subtract(year)
clcdate = clcfirst
[Code]....
But IsNothing() is not functioning like I expect. There is no row in the results table, but it is still acting as if there is and going to the Else clause.
View 3 Replies
Oct 8, 2011
When debugging my app it works fine i.e. It gets the two commandline args, through a loop, and execute as expected. However, once I publish it, the app only picks up the first argument, which is the .exe file string. Code below:
Public Sub Main()
Dim args() As String = Environment.GetCommandLineArgs()
Dim n As integer = args.Length
[Code]....
View 7 Replies
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
Jan 8, 2009
Let's say I have a console application that performs some actions on text files. I'd like a way to, in Windows Explorer, select multiple files, then hit a function key (or something like that) which launches my application using the selected file names as it's input parameters.
View 1 Replies
Aug 9, 2011
I'm creating an inherited class like this:
Public Class MyClass1
Public Sub New()
MsgBox("No Args")
[Code].....
Why does the MyClass1 new() method (no args) get executed when I am instantiating the zzz class and passing in a string ?
View 3 Replies
Nov 16, 2009
What I am wanting to do is pass some information from my app to a new DLL project I have created. In the DLL I have 2 test forms (frm123, frm456). What I need to do is send 2 parameters over to the DLL, when the DLL recieves the info it would then determine which form to open. In the DLL I have in the Main Module ' I will use arg(0) later
[Code]....
View 18 Replies
Oct 28, 2009
Perhaps surprisingly I haven't added an event handler programatically before and I'm having trouble getting my head around AddHandler.I am creating a series of DataGridView controls in a loop and want to subscribe to the CellFormatting event on each of them.The event handler signature is as follows;Private Sub ConfigureRows(ByVal sender As System.Object, yVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs)This works fine when I enter it in the visual editor properties box but I can't figure out how to give it the correct arguments using AddHandler.
View 2 Replies
Apr 6, 2011
I'm trying to convert the C# code from this webpage to VB.Everything seems to have converted pretty much fine using an online converter tool, but then I reach the following line:
fadeOutAnimation.Completed += (sender, args) => OnFadeOutAnimationCompleted(d, hostGrid, grid);
The fadeOutAnimation.Completed event produces an event with the signature (sender, args), and d, hostGrid and grid are variables local to the function containing this mysterious event handler assignment.
I think I can see that the instruction on this C# line is telling the code to execute the OnFadeOutAnimationCompleted function, using d, hostgrid and grid as parameters, when fadeoutAnimation.Completed occurs, but I have no idea what to even search for in order to replicate this behaviour in VB.net.
View 5 Replies
Sep 16, 2010
This illustrationshows 4lines of arguments usedforprojectis run in Debug mode.
View 3 Replies
Sep 24, 2009
I Ported this code from a code project article in c# called Nscript
heres the code
Base App
Imports System
Imports System.IO
Imports System.Resources
[code]....
Okay Now I only get two errors (I dont know how to solve them)
Error3Class 'BaseApp' must implement 'Sub OnCompilerError(errors() As CompilerError)' for interface 'IScriptManagerCallback'.
And
Error4Class 'ScriptManager' must implement 'Sub CompileAndExecuteFile(file As String, args() As String, callback As IScriptManagerCallback)' for interface 'IScriptManager'.
But What I would also Like to know (as well as how to fix the errors), is would the code work?
View 1 Replies
Aug 2, 2010
I was playing a game recently and saw that they could use args in the shortcut, and I decided to try to impliment this into my application...so far, I got: (runs this sub on load)
Sub startup_args()
If Environment.GetCommandLineArgs.Contains("+game") Then
Dim path As Array = Environment.GetCommandLineArgs
[code]....
just to see what it returns, but the application crashes. I also tried path.tostring(), but that didn't work. When I did:
If Evnironment.GetCommandLineArgs.Contains("+game") Then
Dim path as string = Environment.GetCommandLineArgs.tostring
MsgBox(path)
[code]....
but that returned the value "SString.Array[]"...
View 7 Replies
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Jan 12, 2010
I would just like to know why. optional parameters cannot have structure types?
View 4 Replies
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