Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

An array question....

zax_14zax_14 Member Posts: 4
ok...here's the deal...I've written a piece of code that would essentially take the files from a folder and put them in a temporary array, and then sort out the ones that are JPEG or PNG format...but everytime I run it with some files actually in the folder i get an error message...

Here's the code:
[code]
Dim i As Integer
Hrvtemp = IO.Directory.GetFiles(Application.StartupPath().ToString + "data1Croatian")

If Hrvtemp.GetLength(0) >= 2 Then
For i = 1 To Hrvtemp.GetLength(0)
Dim j As Integer = 1
If VB.Right(Hrvtemp(i), 4) = ".jpg" Or VB.Right(Hrvtemp(i), 4) = ".png" Then
Hrv.SetValue(Hrvtemp(i), j)
j += 1
End If
Next
End If[/code]

i get the error at "Hrv.SetValue(Hrvtemp(i), j)"..."Object reference not set to an instance of an object."...but i dont get it cuz both of the arrays are defined as String...and it should work and worked many times before...but this time it just wont for some reason...

help....please...

PS: i imported VB as Microsoft.VisualBasic...

Comments

  • seancampbellseancampbell Pennsylvania, USAMember Posts: 684 ✭✭✭
    You haven't included all of your code here, so I cannot tell you exactly why it's happenned, but your HVR object has not been initialized.

    Null Reference Error, in this case, means that HVR was not initialized before you tried to use it.
    [code]
    Dim i As Integer
    Hrvtemp = IO.Directory.GetFiles(Application.StartupPath().ToString + "data1Croatian")

    If Hrvtemp.GetLength(0) >= 2 Then
    For i = 1 To Hrvtemp.GetLength(0)
    Dim j As Integer = 1
    If VB.Right(Hrvtemp(i), 4) = ".jpg" Or VB.Right(Hrvtemp(i), 4) = ".png" Then
    If (isNothing(Hvr) Then
    MsgBox("Hvr is Null")
    Else
    Hrv.SetValue(Hrvtemp(i), j)
    End If
    j += 1
    End If
    Next
    End If
    [/code]
Sign In or Register to comment.