Chain A Null Coalesce Operator?
Oct 25, 2011
I have a class Customer which contains the property Extensions which in turn contains the property Any. I tried to do: Dim room = If(customer.Extensions.Any.ElementAt(0).InnerText, Nothing) but it threw an error when it did not find an Extension element in the incoming xml. I thought it would return nothing once it saw that the first expression was Nothing. Do I have to do a multiple if statement in this case?
View 1 Replies
ADVERTISEMENT
Jan 4, 2011
i'm afraid that this is a stupid question, but i must assume that i have programmed VB.Net too long and now can't figure out how to convert this C# null coalescing operator into VB.Net:
if( Convert.ToBoolean(ViewState[tp.UniqueID + "_Display"] ?? true) == false ){}
I know the IIF-Function but i'm not sure how to use it here and if it gives the correct result(in IIF both expressions are being evaluated). Please help to shed light on the dark.EDIT: if you want to see the source of this: forums.asp.net There you can see a solution that generates a Option Strict On disallows implicit conversions from 'Object' to 'Boolean' compiler exception.
View 7 Replies
Mar 10, 2009
Possible Duplicate: Is there a conditional ternary operator in VB.NET?
Can we use Coalesce operator(??) and conditional ternary operator(:) in VB.NET as in C#?
View 5 Replies
Sep 17, 2010
I am using vb.net sqlite.net and dblinq0.20.1 to search a sqlite table on a primary key field.My code looks like this
Dim blb = (From d In db.Data Where d.UID = myuid Select d).Single
This returns the error "Coalesce used with type that cannot be null" .If I search on a nullable field it works fine.
View 1 Replies
Jul 22, 2011
Possible Duplicates: Coalesce operator and Conditional operator in VB.NET Is there a VB.NET equivalent for C#'s ?? operator? Is there a built-in VB.NET equivalent to the C# null coalescing operator?
View 4 Replies
Apr 19, 2012
If you assign a value to a nullable integer via a ternary operator, it can't become null..While this question may seem like a duplicate of many, it is actually being asked for a specific reason.Take this code, for example: Dim n As Integer? = If(True, Nothing, 1) In that code, the ternary expression should be returning Nothing, but it's setting n to 0. If this were C#, I could say default(int?) and it would work perfectly. Now it looks like I am going to have to ditch the ternary and use a regular If block, but I really want to use the ternary. If Nothing were truly VB.NET's equivalent to C#'s default, how can you explain this behavior?
View 1 Replies
Sep 14, 2011
I'm experiencing unpredicted effects with nullables in VB.net. The object in question has a property defined: Public Property Value As Int32?
When I try to coalesce the value using IIf, I get a null exception
cmd.Parameters.AddWithValue("@HOValue", IIf(headOffice.Value.HasValue, headOffice.Value .Value, DBNull.Value))
In C#, I know there's no implicit conversion for nullables, hence you can't use ??, but why is the first part of the IIf being evaluated in VB.NET?
View 3 Replies
Mar 1, 2012
I would like to break a "SELECT" SQL statement into its logical components. i.e. I would like to create an object like "SelectSqlStatement" which has a property called "Table", "Where", "OrderBy", etc. The reason I want to do it is that I don't want to manipulate a string but rather manipulate an object and serialize it back to a string. Before I write one for .NET, I was wondering if there was one available. I did a search but didn't see anything.
View 4 Replies
Dec 8, 2011
I'm trying to do something similar to what's described here, but with nullable types.
[URL]
int availableUnits = unitsInStock ?? 0;
In VB, it would be this:
Dim availableUnits As Int32 = If(unitsInStock, 0)
However I'm working with db columns, which could be DbNull, and nullable types, which can be Nothing (which is different to DbNull). If a column is DbNull, I want to return Nothing, otherwise return the value. For eg:
Dim availableUnits As Int32? = If(myDataReader("UnitsInStock").Value, Nothing)
The error I'm getting is "Specified cast is not valid" but I'm not sure why. I've tried this as well:
Dim availableUnits As Int32? = If(isDbNull(myDataReader("UnitsInStock").Value), myDataReader("UnitsInStock").Value, Nothing)
Which is messy and just results in the same error. The only thing that works is this:
Dim availableUnits As Int32?
If isDbNull(myDataReader("UnitsInStock").Value) Then
availableUnits = myDataReader("UnitsInStock").Value
Else
availableUnits = Nothing
End If
Which is just silly. Is there a better way of getting nullable db values into nullable variables that I'm not aware of?
View 3 Replies
May 30, 2009
Usually, if I make a class that has an implementation and also inherits a class with same method signatures, then I do not need to manually add implementation code. For example, if I create a class that inherits List(of Double) and Implements IList(of Double), then I do not need to add any code to make this compile, since the program realizes that the inheritance covers all the methods of the implementation. (Even though VB will auto-generate methods you can remove them no problem).
Now I'm trying do to something more complicated, using an implementation on top of IList, with a class that has a chain of inheritances, and the program won't accept it. See this example:
Interface ICustomList
Inherits IList(Of Double)
Sub TestSub()
End Interface
Class BaseList
[Code] .....
The final item, CustomList, is not compiling. The program says 'TestSub' must be implemented, but by inheriting BaseList, the class has a TestSub (and it is recognized by intellisense)! All the subs exist, they are functional, so why is the implementation not valid? (I know I can get rid of this error by manually creating an (overloading) TestSub in CustomList and specifying that it is an implementation. However, this should not be necessary since it already exists, and if I am going to be building a chain of classes inheriting each other, this could potentially become time-consuming and annoying.)
View 1 Replies
Apr 20, 2010
Not sure if I am using the correct term, but it's not child/parent since they aren't nested objects. In my application I've got a User, UserUserGroup, and UserGroup objects which are pretty standard, UserUserGroup is a linking object with corresponding IDs. I am using Linq-to-SQL so unforunately it doesn't used nested objects, but it still knows the relation.
[Code]...
View 1 Replies
Feb 25, 2011
I have a query that I cannot seem to replicate in expression method chain syntax. I have two tables "User" and "UserPayment". User and UserPayment have a one to many relation i.e. One User can have many UserPayments.
View 1 Replies
Mar 15, 2012
I'm making this POS software for a restaurant and I was wondering what the best way to create the button interface for the items since it's going to use a touch screen monitor.
I was thinking of adding the buttons at runtime to solve the excess space problem, and also add the code at runtime, but that seems like too much work, so I thought I should ask if there are any other ways to approach the problem?
[Code]...
View 1 Replies
Feb 22, 2009
I am having an issue with Visual Studio 2008 SP1. Basically, I have a .NET 3.5 solution with a client, shared and server component. While coding, all components run on the same box, but in production the server component is a standalone (remoting) service running on a separate server.
I would expect that a change to the client component would require only a rebuild of that component as there is no client/server dependency. This is in fact how it works on my work PC. However, on my personal PC and another co-worker's PC, any modification - even a simple label change on the client, requires the server component service to be stopped so that the solution can be rebuilt in its entirety. Does anyone know if there is a particular setting that controls this??
View 2 Replies
May 9, 2012
I'm trying to work out whether every Class in an Inheritance chain needs an explicit Dispose(disposing As Boolean) method or, if a given Class has neither managed nor unmanaged resources to dispose of, it can be skipped for that Class - even if a latterClass does require a Dispose method to dispose of mananaged or unmnaged resources?
Here's two examples:
Public Class BaseClass
Inherits Component 'Component has already implemented IDisposable
[code]....
View 15 Replies
Jan 27, 2010
I am tightening up my coding with the Option Strict set to ON. It has now produced alot of errors. An example of this is:
If AllocatedDGV.Rows(i).Cells("RoomNumber").Value = RoomsAvailableDGV.Rows(j).Cells("RoomName").Value Then
It gives me the following error: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.
View 6 Replies
Apr 6, 2012
I need to write an interface to get data to/from our data files.
We have a low level class that holds field values for each record read from the files.
This just holds two values, the value read from the file (DBValue) and the updated value that may need to be written back to the file (CurrentValue).
These values may be any of the standard value types (integer, date etc) or a string.
Either value (DBValue or CurrentValue) may be null if not defined.
I have written the class to manage this data which works fine while option strict is NOT on.
But we have an office policy of having option strict on all the time.
When I put option strict on, my object value comparisons fail with the error: "Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity."
Question, how should I change the following code to handle option strict on ...
This is all running on Visual Studio 2010
[Code]...
View 1 Replies
Jun 9, 2011
I want to write a program to do Markov chain, but my states are quite large. First of all I calculate all the transition probabilities and revenues for all states(1381860 total states), and store in a multidimensional array. Public RevArr(0 To 9, 0 To 750, 0 To 282) As Long
After that the iteration of markov chain should use these as inputs to calculate the steady-state probabilities. But when I try to run the main code I got this error.Exception of type 'System.OutOfMemoryException' was thrown.
The following is the declaration of second array I add just another dimension for storing all the iterations, but I get this error. Dim stateprob(IT + 1, 0 To 9, 0 To 750, 0 To 282) As single
View 1 Replies
Nov 11, 2009
I want to perform equality comparison in VB.NET and cannot get it to work. Error: value of type Boolean can not be converted to System.Drawing.PointF
[code]...
View 4 Replies
Dec 15, 2011
I have a fairly simple piece of code:
Private _PurchaseDelivery as PurchaseDelivery
Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As PurchaseDeliveryItem)
[Code]....
Which is inside a class which overrides a custom list base. The code is occassionaly throwing an unhandled exception, System.NullReferenceException, on this line when used in production:
If _PurchaseDelivery IsNot Nothing AndAlso _PurchaseDelivery.DefaultSKUBinID.HasValue Then
DeafultSKUBinID is declared as an Integer? (Nullable Int) in the PurchaseDelivery class. I cannot see what might be causing this error, why would this be returning an error?
View 3 Replies
Jul 15, 2011
How to check whether a column is null i use the following code but I got this error "Input string was not in a correct format."
[Code]....
View 2 Replies
Aug 12, 2009
When I put a break point to the last if clause in the sub ("If (backOrder < 0) Then", see below) it runs until the break point, if I put the break point further below, I get the following error:
Cannot insert the value NULL into column 'OrderID', table 'WHM.dbo.OrderDetails'; column does not allow nulls. INSERT fails. The statement has been terminated.
I've discovered first hand that it only happens when prodqty is bigger then qtyOnStock, thus executing the if clause.
The code:
Private Sub NCOSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NCOSubmit.Click
Dim sqlText As String = ""
[Code]....
View 4 Replies
Oct 20, 2011
I am trying to create a treeview in VB.net, the data has to be loaded from MSAccess 2010 database. When I try to run this program I get error : Argument Null Exception was unhandled, 'column' argument cannot be null and the program crashes. I have pasted the code as under:
Imports System.Data.OleDb
Public Class frmRating
Private Sub frmRating_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
[code].....
View 1 Replies
Jun 24, 2010
I have some code which gets child items for a menu via the GetChildren function which takes a list of menuData: Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu
If menuData.Children IsNot Nothing Then
menuData.Children.AddRange(GetChildren(menuData))
End If
Next
If I check if menudata.children isnot nothing, it always is nothing because the GetChildren function is yet to run (providing the child items, which do exist). If I remove this check and just have this code:
Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu
menuData.Children.AddRange(GetChildren(menuData))
Next
Then I am presented with a Object reference not set to an instance of an object error on menuData.Children.AddRange(GetChildren(menuData))
View 1 Replies
Aug 5, 2009
What does the ! mean in the following code snippet?Availability is a table in an access database Family and Model are column headers in the table cmbFamily and cmbModel are combo boxes.
If Availability!family = cmbFamily.Text Then
cmbModel.Items.Add(Availability!model)
End If
add the models of as aircraft family to a combobox(cmbModel) using a selection from another combobox(cmbFamily).
View 10 Replies
Oct 13, 2009
whats do Or operator in Vb do when it is applied as follows eg
Dim returnValue As UInt32
Public Const RMA_VC_RET_NULL_PTR_PARAMETER = 1
returnValue = returnValue Or RMA_VC_RET_NULL_PTR_PARAMETER
what does the 3rd statement do?
View 1 Replies
Mar 28, 2012
Dim bteJustTheAddress As Byte bteJustTheAddress = RawData(2) And &H7F
RawData is a Byte Array and I know &H7F is the Hex 7F
View 3 Replies
Jun 14, 2011
came across this issue while converting a for loop in C# to VB.net I realized that the increment operators are not available in vb.net (++ and --)whereas i was able it do something like cnt +=1 .In VB, a STATEMENT cannot be just an EXPRESSION. why this doesn't work in the same way as it does in C#.
View 4 Replies
May 16, 2011
I want to know what is purpose of '' in vb ? I have this statement: frontDigitsToKeep 2 and I want to convert it to C#.
View 2 Replies
Sep 9, 2009
What scenarios would you consider operator overloading in .net?
View 5 Replies