Re: IIF Function

Tech-Archive recommends: Fix windows errors by optimizing your registry



> 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: To David Raleigh Arnold-Slurs etc
    ... Other than the "shift" practice? ... of the repertoire could be played on one string, ... "Dynamic Guitar Technique": http://www.openguitar.com/instruction.html ... the scale of a chosen key would have on that open string). ...
    (rec.music.classical.guitar)
  • Re: Avoiding string noise when lifting left hand fingers
    ... I tend to sound the open bass string when lifting a left hand finger, ... practice after a forced haitus, and I'm now hyper aware of this noise; ... I find it exceedingly difficult to avoid making these noises. ...
    (rec.music.classical.guitar)
  • Re: To David Raleigh Arnold-Slurs etc
    ... one string scales? ... Other than the "shift" practice? ... fingering pattern is not so important here, ... string in a scale, or part of a scale, rather than some of the ways. ...
    (rec.music.classical.guitar)
  • Re: Sequential fingering
    ... Then work on accurately placing whole chords. ... and any other in which no finger is retained on the same string. ... fingers 4-3-2-1 in ascending order on the first four frets). ... completion with the practicalities of time, other practice prioriities ...
    (rec.music.classical.guitar)
  • Re: To David Raleigh Arnold-Slurs etc
    ... Other than the "shift" practice? ... of the repertoire could be played on one string, ... the scale of a chosen key would have on that open string). ... David, shifting with a fix, definite, fingering pattern becomes the ...
    (rec.music.classical.guitar)