Issue with List in Class Code

margret

Well-Known Member
Licensed User
Longtime User
I have a FTP class I am working on and have the sub listed below. At the end of the upload I get an invalid index error. I am passing the list to the class sub and the message box shows the same size for both. Yet the uploadprogress gives the index error before the size shown in the message box below is reached. I think it has something to do with Files_List2. It is declared in Class_Globals as Private. Private Files_List2 As List. The sub in this class is called from the main Activity with:
B4X:
'In main Activity
Sub V_Click
    Dim uplist As List
   uplist.Initialize
   uplist = File.listfiles(File.DirInternal)
   FTP.FTP_UpLoadSet(File.DirInternal, uplist, "test/files")
End Sub

B4X:
'Sub in FTP Class Module
Sub FTP_UpLoadSet(LocalPath As String, UpLoadList As List, ServerPath As String)
   Files_List2.Initialize
   Files_List2 = UpLoadList
   Msgbox(UpLoadList.Size, Files_List2.Size) 'This line shows they are the same
   SingleUp = False
   If Files_List2.Size > 0 Then
      UpLoadComplete = False
      aSet = 0
      LP = LocalPath
      GF = Files_List2.Get(aSet)
      FP = ServerPath & iif(Right(ServerPath, 1) = "/", "", "/")
      FTP.UploadFile(LP, GF, False, FP & GF)
   Else
      SingleUp = True
      Msgbox("No Files Found...", "")
   End If
End Sub

It's like it's working on a copy of the Files_List2 in the uploadset sub and the uploadprogress sub is using the one defined in Class_Globals. Any ideas?
 
Last edited:

margret

Well-Known Member
Licensed User
Longtime User
Issue Solved

I changed the sub to receive the folder name and not a list. I pull the list from the Class Sub using the passed folder name. I use the same List variable as before and it corrected the issue. Seems populating the list from the Class handles the list correctly where passing the list and assigning it to this List variable creates the issue.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Glad you solved it :)
I am curious though, if using the .addall would solve the problem too:
 
Upvote 0
Top