Re: IIF Function

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I've been doing this since the days of VB6 and ADO, no problems yet.
Thanks for the comments though.

"Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ecsfaT6sFHA.3528@xxxxxxxxxxxxxxxxxxxxxxx
>> Dim intADCN As Integer = "0" &
>> ds1.Tables("DataTable").Rows(0)("RevNumber")
>
> Turning Option Strict Off is extremely bad practice, and the above code is
> a horrible example of why. You're treating BOTH a string and possibly
> Nothing as an Integer. You're also occasionally concatenating Nothing to a
> String. This sort of coding can lead to all kinds of debugging headaches,
> as well as not throwing exceptions that should be thrown, thus enabling
> your app to pass the smell test in testing, and fail behind your back in
> production.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Neither a follower nor a lender be.
>
> "Chris Botha" <chris_s_botha@xxxxxxxxxxxxx> wrote in message
> news:eHnlOPzsFHA.2076@xxxxxxxxxxxxxxxxxxxxxxx
>> Taken from your example, this will return 0 if the value is Null, else
>> the value:
>> Dim intADCN As Integer = "0" &
>> ds1.Tables("DataTable").Rows(0)("RevNumber")
>>
>>
>> "Sparky Arbuckle" <twa@xxxxxxxxxxxxxx> wrote in message
>> news:1126044243.445419.130500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>>I am using the IIF function in my application to create an instance and
>>> value of a field if it doesn't exist in the query. I am using a
>>> datagrid to display 4-5 items at a time and if one of the items doesn't
>>> have a revision listed in tblRevisions then the whole page errors out.
>>> I am using the following to try and fix the problem:
>>>
>>> Dim intADCN As Integer =
>>> IIf(ds1.Tables("DataTable").Rows(0)("RevNumber") Is Nothing, 0,
>>> ds.Tables("DataTable").Rows(0)("RevNumber"))
>>>
>>> I am getting an error: Cast from type 'DBNull' to type 'Integer' is not
>>> valid. It seems as though instead of creating the instance and value of
>>> 0, it is simply creating the instance of there being an a row there and
>>> the value is null.
>>>
>>> Am I missing something or does anyone have any suggestions?
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: Compact SQL Database and ADO
    ... I've since made this change to the code for 'N' in front of the string. ... What happens when you change the working SQL statements to the ones I ... I haven't used SQL CE with ADO myself, I do still write a lot of VB6 apps ...
    (microsoft.public.data.ado)
  • RE: Converting VB6 Fileopen/input/close to vb.net
    ... swallow and spit it out as a single string. ... stand alone components set for those VB6 file methods(such as FileOpen, ... Dim file_num As Integer = FreeFile ... For standard binary file read/write, in .NET, you can use BinaryReader ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Use of Mid Statement in VB.Net
    ... Dim buffer as New String(" "c, ... If you use VB6, then stick to your own group. ... Microsoft for the change in the language paradigm that VB.Net introduced. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Converting Quick Basic to Visual Basic
    ... "Bill McCarthy" wrote in message ... VB3 or earlier applications cannot be opened directly by VB6 IDE, and also require replacement of control libraries etc, etc. ... You still declare a String the same way and you assign and use strings the same way. ... could you imagine if every object had to have an ansi string property and a unicode string property for each property. ...
    (microsoft.public.vb.general.discussion)
  • Re: Using a dll vs. ocx
    ... The wrapper for VB6 appears to be a class. ... dll command in VFP. ... DECLARE integer AUDIOAnalyzeFile IN "AudioGenie2.dll" string ...
    (microsoft.public.fox.programmer.exchange)