kelshall
05-09-2003, 10:26 AM
i am writing an auto-correlation program for short dicrete signals.
i am having a problem where i am getting an error saying the subscript is out of range. my code is below with the problem line starting:
sngAns(intLoop) = sngAns(intLoop) + sngAlldata(intCount) * sngAlldata(intCount - intLoop). I think that is caused by sngAns(intLoop)
Private sngAlldata(1 To 100) As Single, intSamples As Integer
Private Sub butload_Click()
'declare some varibales
Dim sngdata As Single, strtest As String
Dim intFree As Integer
'set some variables
intFree = FreeFile
'set a dialog box allowing the user to search for his/her data
CommonDialog1.ShowOpen
strtest = CommonDialog1.FileName
'read in a file of data
Open strtest For Input As #intFree
intSamples = 1
'print some headings
' set up a loop that runs till the end of file
Do While Not EOF(intFree)
Input #intFree, sngdata
sngAlldata(intSamples) = sngdata
Text1.SelText = Str(sngdata) & vbCrLf
intSamples = intSamples + 1
Loop
intSamples = intSamples - 1
Text1.SelText = "no of samples = " & Str(intSamples) & vbCrLf
End Sub
Private Sub butproautocor_click()
Dim intCount As Integer, intLoop As Integer, sngAns(1 To 199) As Single, intCount1 As Integer, intN As Integer, intM As Integer
For intCount1 = 1 To 199
sngAns(intCount1) = 0
Next intCount1
intN = intSamples
intM = intSamples
'no samples of a and b is n and m respectively
'set loopcounter for tau values to increment difference between them
For intLoop = -(intM - 1) To intN - 1
'to increment staring values to multiply
For intCount = 1 To intN
'to multiply then add them up
sngAns(intLoop) = sngAns(intLoop) + sngAlldata(intCount) * sngAlldata(intCount - intLoop)
Next intCount
Text1.SelText = Str(sngAns(intLoop)) & vbTab & Str(intLoop) & vbCrLf
Next intLoop
End Sub
any help or suggestion will be greatly appreciated
thanks
i am having a problem where i am getting an error saying the subscript is out of range. my code is below with the problem line starting:
sngAns(intLoop) = sngAns(intLoop) + sngAlldata(intCount) * sngAlldata(intCount - intLoop). I think that is caused by sngAns(intLoop)
Private sngAlldata(1 To 100) As Single, intSamples As Integer
Private Sub butload_Click()
'declare some varibales
Dim sngdata As Single, strtest As String
Dim intFree As Integer
'set some variables
intFree = FreeFile
'set a dialog box allowing the user to search for his/her data
CommonDialog1.ShowOpen
strtest = CommonDialog1.FileName
'read in a file of data
Open strtest For Input As #intFree
intSamples = 1
'print some headings
' set up a loop that runs till the end of file
Do While Not EOF(intFree)
Input #intFree, sngdata
sngAlldata(intSamples) = sngdata
Text1.SelText = Str(sngdata) & vbCrLf
intSamples = intSamples + 1
Loop
intSamples = intSamples - 1
Text1.SelText = "no of samples = " & Str(intSamples) & vbCrLf
End Sub
Private Sub butproautocor_click()
Dim intCount As Integer, intLoop As Integer, sngAns(1 To 199) As Single, intCount1 As Integer, intN As Integer, intM As Integer
For intCount1 = 1 To 199
sngAns(intCount1) = 0
Next intCount1
intN = intSamples
intM = intSamples
'no samples of a and b is n and m respectively
'set loopcounter for tau values to increment difference between them
For intLoop = -(intM - 1) To intN - 1
'to increment staring values to multiply
For intCount = 1 To intN
'to multiply then add them up
sngAns(intLoop) = sngAns(intLoop) + sngAlldata(intCount) * sngAlldata(intCount - intLoop)
Next intCount
Text1.SelText = Str(sngAns(intLoop)) & vbTab & Str(intLoop) & vbCrLf
Next intLoop
End Sub
any help or suggestion will be greatly appreciated
thanks