Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

vb run-time error 5 Invalid Index run time runtime

I get an error on the red line when I execute this code.  Can someone please help.
 
CWIMAQViewer1.Attach CWIMAQ1.Images(ImageIndex)
CWIMAQ1.LoadInterfaceDefaults
CWIMAQ1.AcquisitionType = cwimaqAcquisitionContinuous
CWIMAQ1.Start
CWIMAQ1.Stop
 
Dim Image As New CWIMAQImage
Dim ImageType As CWIMAQImageTypes
Dim HistogramReport As New CWIMAQHistogramReport
Dim Value As Double
ImageType = cwimaqImageTypeU8
CWIMAQVision1.Cast Image, Image, cwimaqImageTypeSGL
CWIMAQVision1.Histogram2 Image, HistogramReport 
CWIMAQVision1.Subtract Image, HistogramReport.Item(0).PixelRange.Min, Image 
0 Kudos
Message 1 of 6
(9,808 Views)

Hi tres0422,

You are indexing an object that has not been initialized with the line HistogramReport.Item(0).  This results in your Invalid Index runtime error.  When you call Dim HistogramReport As New CWIMAQHistogramReport the resulting object has zero items.  You will need to add an object using HistogramReport.Add before you try to reference it in memory.

Regards,

Ryan F.
 

0 Kudos
Message 2 of 6
(9,791 Views)

Ryan I totally appreciate your help.  Thank you.  I tried the histogramreport.add, but it didn't work.  I changed the ".item(0)" to an ".item(1).  Now I am getting another error.  "Run-Time Error 31006.  The Image is not large enough for the operation."  My concern is that I have not attached an image to the variable named image or that .item(1) is empty.  Can't tell which, any ideas?

Thanks,  Thomas

0 Kudos
Message 3 of 6
(9,784 Views)
Ok all is fixed now.  There is no histogramreport.item(0).  I could never get it to work.  Change the 0 to a 1 and it works.  I was making a mistake in the other part when assigning a value to Image.  I should have used a "Set".   Now all is good.  thanks Ryan for all of the help.
0 Kudos
Message 4 of 6
(9,773 Views)

Ryan,

    Here is the code.

Thomas


Private Sub Convert_click()
    Dim imGrab As New CWIMAQImage
    Dim ImageType As CWIMAQImageTypes
    Dim HistogramReport As New CWIMAQHistogramReport
    Dim Value As Double
 
    ImageType = cwimaqImageTypeU8
   

'*****intSnapIndex is a public variable that is equal to the index number of the last valid Image Acquisition

    Set imGrab = CWIMAQ1.Images(intSnapIndex)
   

'*****  Start of code created by builder file from Vision Assistant
    CWIMAQVision1.Cast imGrab, imGrab, cwimaqImageTypeSGL
    CWIMAQVision1.Histogram2 imGrab, HistogramReport

    CWIMAQVision1.Subtract imGrab, HistogramReport.Item(1).PixelRange.Min, imGrab

    Value = IIf(ImageType = cwimaqImageTypeI16, 32677, 255) _
    / (HistogramReport.Item(1).PixelRange.Max - _
    HistogramReport.Item(1).PixelRange.Min)

    CWIMAQVision1.Multiply imGrab, Value, imGrab

    CWIMAQVision1.Cast imGrab, imGrab, ImageType
   
    CWIMAQViewer1.Palette.Type = cwimaqPaletteGrayScale

'***** End of code created by builder filer from Vision Assistant
    strfileext = "JPEG"
    Call Save_Click
     
End Sub

Message Edited by tres0422 on 02-02-2006 01:37 PM

0 Kudos
Message 5 of 6
(9,766 Views)

Thanks a lot Thomas.  Good luck in your application,

Ryan F.

0 Kudos
Message 6 of 6
(9,759 Views)