Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 27th, 2006, 11:23 PM
Enzo Enzo is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: HK
Posts: 178 Enzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 15 h 43 m 26 sec
Reputation Power: 4
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?

Reply With Quote
  #2  
Old June 28th, 2006, 04:23 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 34 m 58 sec
Reputation Power: 1243
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.

Reply With Quote
  #3  
Old June 28th, 2006, 09:35 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
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.

Reply With Quote
  #4  
Old June 28th, 2006, 10:46 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 34 m 58 sec
Reputation Power: 1243
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?

Reply With Quote
  #5  
Old June 28th, 2006, 10:45 PM
Enzo Enzo is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: HK
Posts: 178 Enzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 15 h 43 m 26 sec
Reputation Power: 4
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.

Reply With Quote
  #6  
Old June 29th, 2006, 06:56 PM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Help...Subscript out of range


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT