Results 1 to 12 of 12

Thread: [RESOLVED] [2005] Null In array

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Resolved [RESOLVED] [2005] Null In array

    Hi all
    How to check Null value in the array
    See this

    VB Code:
    1. Dim FileName() As String = Nothing
    2.             If Not IsDBNull(DataTable.Rows(0).Item("Document")) Then FileName = Split(DataTable.Rows(0).Item("Document"), ",")
    3.             For Index As Integer = 0 To UBound(FileName)
    4.                 Me.lstFiles.Items.Add(Application.StartupPath & "\ShaktiProjectAttachDocument\" & FileName(Index))
    5.             Next

    if this is IsDBNull(DataTable.Rows(0).Item("Document")) Nothing then then there is Null in the array and the error will occuring here.For Index As Integer = 0 To UBound(FileName)
    so How to avoid this error.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: [2005] Null In array

    change your NULL to nothing.

  3. #3
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Null In array

    Couldn't you just replace any element that is NULL with an empty string?
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Null In array

    How about you put the For loop inside the If block too? Also, you don't need that array variable at all:
    VB Code:
    1. If Not DataTable.Rows(0).IsNull("Document") Then
    2.     Dim path As String = IO.Path.Combine(Application.StartupPath, "ShaktiProjectAttachDocument")
    3.  
    4.     Me.lstFiles.BeginUpdate()
    5.  
    6.     For Each fileName As String In CStr(DataTable.Rows(0)("Document")).Split(","c)
    7.         Me.lstFiles.Items.Add(IO.Path.Combine(path, fileName)
    8.     Next fileName
    9.  
    10.     Me.lstFiles.EndUpdate()
    11. End If
    Now, I'm afraid I can't help but say this. I'm a big fan of consistency in code and I'm also not a big fan of Hungarian notation. You've got a variable named "lstFiles", so you're using Hungarian notation. I'd suggest not doing that, but if you're going to then may I suggest that you at least be consistent? You've also got a variables named "FileName", "DataTable" and "Index". If you're not going to use Hungarian everywhere then what's the point of using it at all?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Null In array

    Quote Originally Posted by jmcilhinney
    :[End If[/Highlight]Now, I'm afraid I can't help but say this. I'm a big fan of consistency in code and I'm also not a big fan of Hungarian notation. You've got a variable named "lstFiles", so you're using Hungarian notation. I'd suggest not doing that, but if you're going to then may I suggest that you at least be consistent? You've also got a variables named "FileName", "DataTable" and "Index". If you're not going to use Hungarian everywhere then what's the point of using it at all?
    That's nice sir but can you please tell me what is mistake and how to correct it??
    I can not understand above line.
    thanks

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Null In array

    In short, use Hungarian notation all the time or not at all. If you aren't going to use prefixes to identify the type of every variable then don't use them on any variable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Null In array

    Please provide some example of the Hungarian notation
    Thanks

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Null In array

    What about this one
    VB Code:
    1. If FileName.Length() > 0 Then
    2.             For Index As Integer = 0 To UBound(FileName)
    3.                 If FileName(Index).ToString().Length > 0 Then
    4.                     Me.lstFiles.Items.Add(Application.StartupPath & "\ShaktiProjectAttachDocument\" & FileName(Index))
    5.                 End If
    6.             Next
    7.         End If
    Last edited by danasegarane; Feb 15th, 2007 at 12:54 AM.
    Please mark you thread resolved using the Thread Tools as shown

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Null In array

    Quote Originally Posted by shakti
    Please provide some example of the Hungarian notation
    I already did.
    Quote Originally Posted by jmcilhinney
    You've got a variable named "lstFiles", so you're using Hungarian notation.
    Quote Originally Posted by jmcilhinney
    If you aren't going to use prefixes to identify the type of every variable then don't use them on any variable.
    I do feel like I'm speaking Swahili some times. The fact that you don't know what it is is a prime indication that you're one of the many people who use it because they've seen it somewhere without any thought for its purpose. The fact that you don't use it consistently is a prime indication that you don't feel that its intended purpose is worth fulfilling. If that's the case, don't use it at all.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Null In array


    Thanks sir for reply
    then what i use at the place of the lstFiles",

    lstFiles", is the listbox

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Null In array

    If it's a list of files then "fileList" would be a logical choice don't you think?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Null In array

    Quote Originally Posted by jmcilhinney
    If it's a list of files then "fileList" would be a logical choice don't you think?
    Thanks JMC for guidance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width