|
-
Feb 12th, 2007, 05:47 AM
#1
Thread Starter
Just Married
[RESOLVED] [2005] Null In array
Hi all
How to check Null value in the array
See this
VB Code:
Dim FileName() As String = Nothing
If Not IsDBNull(DataTable.Rows(0).Item("Document")) Then FileName = Split(DataTable.Rows(0).Item("Document"), ",")
For Index As Integer = 0 To UBound(FileName)
Me.lstFiles.Items.Add(Application.StartupPath & "\ShaktiProjectAttachDocument\" & FileName(Index))
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.
-
Feb 12th, 2007, 08:06 AM
#2
Hyperactive Member
Re: [2005] Null In array
change your NULL to nothing.
-
Feb 12th, 2007, 08:17 AM
#3
Fanatic Member
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 
-
Feb 12th, 2007, 06:29 PM
#4
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:
If Not DataTable.Rows(0).IsNull("Document") Then
Dim path As String = IO.Path.Combine(Application.StartupPath, "ShaktiProjectAttachDocument")
Me.lstFiles.BeginUpdate()
For Each fileName As String In CStr(DataTable.Rows(0)("Document")).Split(","c)
Me.lstFiles.Items.Add(IO.Path.Combine(path, fileName)
Next fileName
Me.lstFiles.EndUpdate()
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?
-
Feb 15th, 2007, 12:34 AM
#5
Thread Starter
Just Married
Re: [2005] Null In array
 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
-
Feb 15th, 2007, 12:39 AM
#6
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.
-
Feb 15th, 2007, 12:42 AM
#7
Thread Starter
Just Married
Re: [2005] Null In array
Please provide some example of the Hungarian notation
Thanks
-
Feb 15th, 2007, 12:43 AM
#8
Re: [2005] Null In array
What about this one
VB Code:
If FileName.Length() > 0 Then
For Index As Integer = 0 To UBound(FileName)
If FileName(Index).ToString().Length > 0 Then
Me.lstFiles.Items.Add(Application.StartupPath & "\ShaktiProjectAttachDocument\" & FileName(Index))
End If
Next
End If
Last edited by danasegarane; Feb 15th, 2007 at 12:54 AM.
Please mark you thread resolved using the Thread Tools as shown
-
Feb 15th, 2007, 12:59 AM
#9
Re: [2005] Null In array
 Originally Posted by shakti
Please provide some example of the Hungarian notation
I already did.
 Originally Posted by jmcilhinney
You've got a variable named "lstFiles", so you're using Hungarian notation.
 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.
-
Feb 15th, 2007, 01:07 AM
#10
Thread Starter
Just Married
Re: [2005] Null In array
Thanks sir for reply
then what i use at the place of the lstFiles",
lstFiles", is the listbox
-
Feb 15th, 2007, 01:22 AM
#11
Re: [2005] Null In array
If it's a list of files then "fileList" would be a logical choice don't you think?
-
Feb 15th, 2007, 01:32 AM
#12
Thread Starter
Just Married
Re: [2005] Null In array
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|