• 0

VB6 Dynamic Array Error


Question

ok.. here's my situation.. i've defined a dynamic array, it does not have a defined size, i've done this before with no errors. For some reason in this application its giving me a Subscript out of range error when I try to add to the ubound of the array.... I've tried everything I can possibly think of.. codes below please see if any of you more experienced coders see anything wrong...

Dim ticks() As String

Private Sub Command1_Click()
Dim i As String
Dim daytick As Long
Dim hourtick As Long
Dim mintick As Long


If itemnametxt.Text = "" Or notetxt.Text = "" Or daytxt.Text = "" And hourtxt.Text = "" And mintxt.Text = "" Then
    MsgBox "You must complete the form!"
    Exit Sub
End If

If daytxt.Text <> "" Then
  daytick = daytxt.Text * 86400
  End If
If hourtxt.Text <> "" Then
  hourtick = hourtxt.Text * 3600
  End If
If mintxt.Text <> "" Then
  mintick = mintxt.Text * 60
  End If

    ReDim Preserve ticks(UBound(ticks) + 1)
    ticks(UBound(ticks)) = daytick + hourtick + mintick
    i = UBound(ticks)
    List1.AddItem i + " " + itemnametxt.Text
    Timer1.Enabled = True
    Frame1.Visible = False
    Call resetform
End Sub

Thanks!

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

anyone?? I've tried it a few different ways.. but all return the same error..

ANY HELP?

it works with control arrays..

Link to comment
Share on other sites

  • 0

Dim ticks() As String
Private Sub Form_Load()

ReDim ticks(0)

End Sub

Private Sub Command1_Click()
Dim i As String
Dim daytick As Long
Dim hourtick As Long
Dim mintick As Long


If itemnametxt.Text = "" Or notetxt.Text = "" Or daytxt.Text = "" And hourtxt.Text = "" And mintxt.Text = "" Then
   MsgBox "You must complete the form!"
   Exit Sub
End If

If daytxt.Text <> "" Then
 daytick = daytxt.Text * 86400
 End If
If hourtxt.Text <> "" Then
 hourtick = hourtxt.Text * 3600
 End If
If mintxt.Text <> "" Then
 mintick = mintxt.Text * 60
 End If

   ReDim Preserve ticks(UBound(ticks) + 1)
   ticks(UBound(ticks)) = daytick + hourtick + mintick
   i = UBound(ticks)
   List1.AddItem i + " " + itemnametxt.Text
   Timer1.Enabled = True
   Frame1.Visible = False
   Call resetform
End Sub

Try this, Hope this helps :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.