|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help...Subscript out of range
Code:
Case 88
Get #1, lPtr + 2, source5
With source5
If Len(.Time.year) > 0 Then
FormatedYear = Right(.Time.year, 2)
End If
n = 1
nob = CLng(.n)
ReDim source5.Beams(1 To nob)
Get #1, lPtr + 2, source5
ReDim dathdrOld.data(1 To (24 + (nob * 28)))
lblUNBTime.Caption = "Date: " & Format(.Time.day, dd) & "-" & Format(.Time.month, mm) & "-" & FormatedYear & ""
Label1.Caption = "Time: " & Format(.Time.hour, "00") & ":" & Format(.Time.min, "00") & ":" & Format(.Time.sec, "00") & "." & Format(.Time.sec100, "00") & "." & Format(.Time.sec10000, "00") & ""
Label4.Caption = "Counter= " & .Counter
Label5.Caption = "SV= " & (.SV * 0.1) & " m/s"
Label3.Caption = "Gyro= " & (.Gyro * 0.01)
Label6.Caption = "Pulse= " & (.Pulse * 0.01) & " m/s"
Label8.Caption = "Mode= " & .Mode & " (0=omni, 1=RDT)"
Label9.Caption = "Source Power= " & .Power & " (0=low, 1=high)"
Label10.Caption = "GainStbd= " & .GainStbd
Label11.Caption = "GainPort= " & .GainPort
Label12.Caption = "Reserved= " & .Reserved
Label13.Caption = "Number of Beam= " & .n
Do While n <= nob
Label15.Caption = "Depth= " & .Beams(n).Depth & "cm"
Label16.Caption = "Across= " & .Beams(n).Across & "cm"
Label17.Caption = "Along= " & .Beams(n).Along & "cm"
Label18.Caption = "TravelTime= " & (.Beams(n).TravelTime * 0.05) & "ms"
Label20.Caption = "Amplitude= " & .Beams(n).Amplitude
Label19.Caption = "Quality= " & .Beams(n).Quality
Label21.Caption = "TimeOffset= " & (.Beams(n).TimeOffset * 0.5) & "ms"
Label22.Caption = "Heave= " & .Beams(n).Heave & "mm"
Label23.Caption = "Roll= " & (.Beams(n).Roll * 0.005)
Label24.Caption = "Pitch= " & (.Beams(n).Pitch * 0.005)
Label25.Caption = "Angle= " & (.Beams(n).Angle * 0.005)
End With
If n < nob Then
n = n + 1
End If
res = MsgBox("Continue Getting Bathymetry Beam " & crt & "?", vbYesNo + vbDefaultButton1)
If res = vbNo Then
Exit Do
Else
crt = crt + 1
End If
Loop
MsgBox ("Count: " & crt)
lPtr = lPtr + 2 + (24 + (nob * 28)) + 1 + checksum
Error occurs on Label15.Caption = "Depth= " & .Beams(n).Depth & "cm"... How can i solve? |
|
#2
|
||||
|
||||
|
Enzo,
I apologise for being rude but your variable names are not very meaningful: nob, n, lPtr, Label1, Label2 etc...?? I suggest that descriptive names such as intNoOfBeams would make your code more readable!!! Try adding a breakpoint at the start of this code section then step through the code using F8. If you add a watch on the variable n, what is its value at the time of the error? The only observations I can make is that you should probably make use of a For...Next loop instead of a Do..While. Also, you seem to have your end with statement within the loop which means that subsequent iterations will not be referring to your structure. And finally, you are doing a redim without using the preserve keyword which will mean that your array is empty!! Try the following code and let me know what happens if you step through it in debug mode: Code:
Case 88
Get #1, lPtr + 2, source5
With source5
If Len(.Time.Year) > 0 Then
FormatedYear = Right(.Time.Year, 2)
End If
nob = CLng(.n)
ReDim Preserve source5.Beams(1 To nob)
ReDim dathdrOld.Data(1 To (24 + (nob * 28)))
lblUNBTime.Caption = "Date: " & Format(.Time.Day, dd) & "-" & Format(.Time.Month, mm) & "-" & FormatedYear & ""
Label1.Caption = "Time: " & Format(.Time.Hour, "00") & ":" & Format(.Time.Min, "00") & ":" & Format(.Time.sec, "00") & "." & Format(.Time.sec100, "00") & "." & Format(.Time.sec10000, "00") & ""
Label4.Caption = "Counter= " & .Counter
Label5.Caption = "SV= " & (.SV * 0.1) & " m/s"
Label3.Caption = "Gyro= " & (.Gyro * 0.01)
Label6.Caption = "Pulse= " & (.Pulse * 0.01) & " m/s"
Label8.Caption = "Mode= " & .Mode & " (0=omni, 1=RDT)"
Label9.Caption = "Source Power= " & .Power & " (0=low, 1=high)"
Label10.Caption = "GainStbd= " & .GainStbd
Label11.Caption = "GainPort= " & .GainPort
Label12.Caption = "Reserved= " & .Reserved
Label13.Caption = "Number of Beam= " & .n
For n = 1 To nob
Label15.Caption = "Depth= " & .Beams(n).Depth & "cm"
Label16.Caption = "Across= " & .Beams(n).Across & "cm"
Label17.Caption = "Along= " & .Beams(n).Along & "cm"
Label18.Caption = "TravelTime= " & (.Beams(n).TravelTime * 0.05) & "ms"
Label20.Caption = "Amplitude= " & .Beams(n).Amplitude
Label19.Caption = "Quality= " & .Beams(n).Quality
Label21.Caption = "TimeOffset= " & (.Beams(n).TimeOffset * 0.5) & "ms"
Label22.Caption = "Heave= " & .Beams(n).Heave & "mm"
Label23.Caption = "Roll= " & (.Beams(n).Roll * 0.005)
Label24.Caption = "Pitch= " & (.Beams(n).Pitch * 0.005)
Label25.Caption = "Angle= " & (.Beams(n).Angle * 0.005)
res = MsgBox("Continue Getting Bathymetry Beam " & crt & "?", vbYesNo + vbDefaultButton1)
If res = vbNo Then
Exit Do
Else
crt = crt + 1
End If
Next
MsgBox ("Count: " & crt)
lPtr = lPtr + 2 + (24 + (nob * 28)) + 1 + checksum
End With
Last edited by sync_or_swim : June 28th, 2006 at 04:26 AM. |
|
#3
|
|||
|
|||
|
Just curious...., why ?
ReDim Preserve source5.Beams(1 To nob) Why not just ReDim Preserve Beams(1 To nob) Be careful not to declare a variable for the form with the same name. |
|
#4
|
||||
|
||||
|
Well spotted Darius I knew there was something bothering me about the re dim statement!!! would it be:
Code:
ReDim Preserve .Beams(1 To nob) though? |
|
#5
|
|||
|
|||
|
Code:
Private Type UNBGENERALBATHYMETRY
Time As UNBTIME
Counter As Integer 'Unsigned Short
SV As Integer 'Unsigned Short
Gyro As Integer
Pulse As Integer 'Unsigned Short
Mode As Byte
Power As Byte
GainStbd As Byte
GainPort As Integer
Reserved As Integer
n As Integer 'Unsigned Short
Beams() As UNBGENERALBEAM
End Type
Case 88
Get #1, start_pt + 2, source5
With source5
If Len(.Time.year) > 0 Then
FormatedYear = Right(.Time.year, 2)
End If
Shown_Beam = 1
No_of_Beams = CLng(.n)
No_of_Beams = CInt(No_of_Beams)
ReDim source1.data(1 To (24 + (No_of_Beams * 28)))
ReDim Preserve .Beams(No_of_Beams)
End With
Get #1, start_pt + 2, source5
With source5
lblUNBTime.Caption = "Date: " & Format(.Time.day, dd) & "-" & Format(.Time.month, mm) & "-" & FormatedYear & ""
Label1.Caption = "Time: " & Format(.Time.hour, "00") & ":" & Format(.Time.min, "00") & ":" & Format(.Time.sec, "00") & "." & Format(.Time.sec100, "00") & "." & Format(.Time.sec10000, "00") & ""
Label4.Caption = "Counter= " & .Counter
Label5.Caption = "SV= " & (.SV * 0.1) & " m/s"
Label3.Caption = "Gyro= " & (.Gyro * 0.01)
Label6.Caption = "Pulse= " & (.Pulse * 0.01) & " m/s"
Label8.Caption = "Mode= " & .Mode & " (0=omni, 1=RDT)"
Label9.Caption = "Source Power= " & .Power & " (0=low, 1=high)"
Label10.Caption = "GainStbd= " & .GainStbd
Label11.Caption = "GainPort= " & .GainPort
Label12.Caption = "Reserved= " & .Reserved
Label13.Caption = "Number of Beam= " & .n
'End With
For Shown_Beam = 1 To No_of_Beams
Label15.Caption = "Depth= " & .Beams(Shown_Beam).Depth & "cm"
Label16.Caption = "Across= " & .Beams(Shown_Beam).Across & "cm"
Label17.Caption = "Along= " & .Beams(Shown_Beam).Along & "cm"
Label18.Caption = "TravelTime= " & (.Beams(Shown_Beam).TravelTime * 0.05) & "ms"
Label20.Caption = "Amplitude= " & .Beams(Shown_Beam).Amplitude
Label19.Caption = "Quality= " & .Beams(Shown_Beam).Quality
Label21.Caption = "TimeOffset= " & (.Beams(Shown_Beam).TimeOffset * 0.5) & "ms"
Label22.Caption = "Heave= " & .Beams(Shown_Beam).Heave & "mm"
Label23.Caption = "Roll= " & (.Beams(Shown_Beam).Roll * 0.005)
Label24.Caption = "Pitch= " & (.Beams(Shown_Beam).Pitch * 0.005)
Label25.Caption = "Angle= " & (.Beams(Shown_Beam).Angle * 0.005)
'End With
res = MsgBox("Continue Getting Bathymetry Beam " & crt & "?", vbYesNo + vbDefaultButton1)
If res = vbNo Then
Exit For
Else
crt = crt + 1
End If
Next Shown_Beam
End With
MsgBox ("Count: " & crt)
start_pt = start_pt + 2 + (24 + (No_of_Beams * 28)) + 1 + checksum
i already change that. however, it seems can not be execute the ReDim statement. The subscript out of range error occurs again. |
|
#6
|
|||
|
|||
|
So a little more is revealed, sorry for the sugestion, but I didn't knew that it was a type definition ( source5 was a structure and I should knew because of the get instruction). Your previous way was right.
ReDim Preserve source5.Beams(1 To nob) A sugestion, can you put a msgbox before the compromising instruction, to see if at least one time worked and the n value where the program fail. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Help...Subscript out of range |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|