Basic List Access Problems

CharlesIPTI

Active Member
Licensed User
Longtime User
Good morning everyone

Why doesn't this get the next item in the list? The parameter
iPosition is passed from a loop and is assuredly incremented each time


B4X:
Sub GetSpecificOrderNoPerBinPosition(iPosition As Int) As typ_cOrderAssignment

   Dim tmpOrdObj As typ_OrderObject
   Dim tmpOrgAssign As typ_cOrderAssignment
   
   tmpOrgAssign.Initialize
   tmpOrdObj.Initialize
   
   
   tmpOrdObj = postMain.lstOrders.get(iPosition)
   tmpOrgAssign.ordId = tmpOrdObj.orderID
   tmpOrgAssign.pos = iPosition
   
   Return tmpOrgAssign
   
End Sub


its called from here:


B4X:
   For x = 0 To iBinCount -1        ' lstOrderAssignments.Size -1                     
                        
                        Dim currOrdData As typ_cOrderAssignment
                                                
                           Try
                              currOrdData = daObject.GetSpecificOrderNoPerBinPosition(x)
                           Catch
                                          
                           End Try

So no matter what value iPosition is it keeps giving me the last item from the list...
 

Ricky D

Well-Known Member
Licensed User
Longtime User
Are you doing anything with curOrdData after the try catch code?

It's quite hard to see all the code. Can you zip a project we can test?

Regards, Ricky
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
?!?!?

Well yes of course,,, but that's pointless at this moment , if the Sub keeps returning the EXACT SAME instance I can't do anything with it. I would just start fleshing out the UI elements, but that's what got me here,, they were all listing the same order ID ..

I've spat out messsage boxes to confirm the list content and its always the same instance getting pulled.

I of course did the same confirmation way back a few methods when filling the list and there is unique content being placed into the list
 
Last edited:
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Assume

I assume this Get(x) method works and I dont have to manually update the X variable in a for loop do I


Because this works::

B4X:
   Dim X As Int

            X = 0
            If mapLocList.Size > 0 Then
               Do While X < mapLocList.Size
                   localMapLocObj = mapLocList.Get(X)
                tmpLocationNm = localMapLocObj.locNm.Trim   
                      
                         If tmpLocationNm = m_localScanRetVal Then
                         m_CurrentLocationID = localMapLocObj.dbId
                         bFoundMapLoc = True
                     End If
                           X = X +1
               Loop
            End If
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
   Type typ_griggle(Alpha As String, Beta As Int)
   Dim gObj As typ_griggle

End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)


'Activity.LoadLayout("twelve")


lstDebug.Initialize



For F = 0 To 12

   gObj.Initialize
   gObj.Alpha = "Al:" 
   gObj.Beta =  F
   

lstDebug.Add(gObj)

Next
   Msgbox("LIST SIZE: " &  lstDebug.size, "")
   
For F = 0 To 12

Dim NewObjInst As typ_griggle
NewObjInst.initialize
NewObjInst = lstDebug.Get(F)
Msgbox(NewObjInst.Beta & "Beta", "")
Next


You don't need my project this does the EXACT Same thing
It will open 13 messageboxes that all say 12BETA

Correction this one looks like its only placing the same data in the list
 
Last edited:
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
B4X:
 For x = 0 To iBinCount -1        ' lstOrderAssignments.Size -1

Hard to tell without seeing more of what is going on, but here are some thoughts:

What is the value of iBinCount?

How many items are in the list?

If iBinCount is being set to "lstOrderAssignments.Size -1" then why are you taking 1 off again in the For statement?

Why are you calling the sub in a Try...Catch, and is it possible that an error is occurring preventing the correct data from getting pulled but you don't know because the error is being trapped with Try...Catch?

Good luck! It's the "simple" things like this that will drive a person nuts! :D
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
More please

You need to Dim each object to create a new one before adding it to the list:

Yes Thank you I agree the small sample was lacking that but the original real code assuredly has the correct list content. the XML/Sax parser Dims each element correctly before adding it to the list. & I have spewed out the list content immediately after filling it to confirm

My small sample now works fine but I cant replicate the functionality in the real code
In My new test I will try reaching across modules like I'm trying to do in the real code. That's the only difference I see here so far .....................

Kevin
Code:
some thoughts:

What is the value of iBinCount?-- Its 7

How many items are in the list? there's 7 --- funny I addressed the possibility of that discrepancy last week iBinCount( although not visible in my sample is list.size)


If iBinCount is being set to "lstOrderAssignments.Size -1" then why are you taking 1 off again in the For statement?

It's an old comment sorry but....
the list is zero based so to get the FIRST instance in the list you grab zero then one then Two. It's the same for my newly validated variable that correctly reflects list size, IBinCount. 7-1 = 6 , but theres 7 list items counting the one at position zero


Why are you calling the sub in a Try...Catch, and is it possible that an error is occurring preventing the correct data from getting pulled but you don't know because the error is being trapped with Try...Catch?
You should always try to trap errors for even trivial computations / processes in a try catch. Ideally they should bubble up to a main error handler for logging or display to user. I appreciate your intent so just to be thorough I added a msgbox with LastException.Message.
It gets to the next section of code just fine no errors, just botched list content:
B4X:
   Try
                              currOrdData = daObject.GetSpecificOrderNoPerBinPosition(xBinCount)
                           Catch
                           
                           Msgbox(LastException.Message, "ERROR HERE")
                           'This VERY UGLY logic will allow you out of a missing element at position X                  
                           End Try
                           
                           binCrtl = uiLogic.CreateBinControl(xBinCount, currOrdData)
                           binCtrlObjLst.Add(binCrtl)   
                           
                              If xBinCount = iBinCountSubOneRef Then
                                 bAllowEntry = True 
                              End If


So again I'm wondering of the jump across modules ??

tmpOrdObj = postMain.lstOrders.Get(iPosition)
 
Last edited:
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Not a module access problem It Still Fails !!

ANYBODY PLEASE !!!!

This is driving me More Krazy than normal

B4X:
   #Region---------------------{ Create Order Bins }-------------------- 
                     
      '*************  lstOrders 
      
                        binCtrlObjLst.Initialize()      ' Collection of Pan
                        panOrderBinsBase.Initialize("")     ' Base houses all orderBin Panels < Controls > 
                        
                        Activity.AddView(panOrderBinsBase,17.5%x,50%y,800dip,300dip)                   
                     
                        iTwoPanelWidth = panOrderBinsBase.Width/2
                        iThreePanelWidth = panOrderBinsBase.Width/3                           
   
                        If lstOrders.Size > MAX_BIN_COUNT Then                        
                           iBinCount = MAX_BIN_COUNT
                        Else
                           iBinCount = lstOrders.Size
                        End If
                                                                                                                                                                                                
                                                                                                                                                                                                                        
                        For xBinCount = 0 To iBinCount -1                       
                        
                              Dim currOrdData As typ_cOrderAssignment                                                                                                               
                              Dim tmpOrdObj As typ_OrderObject
                              'Dim tmpOrgAssign As typ_cOrderAssignment
                                                   
                              tmpOrdObj = lstOrders.Get(xBinCount)
                              currOrdData.ordId = tmpOrdObj.orderID
                              currOrdData.pos = xBinCount
                        
                        Msgbox(currOrdData.ordId,"OrderID")
                                                                                    
'                           Try
'                              currOrdData = daObject.GetSpecificOrderNoPerBinPosition(xBinCount)
'                           Catch
'                           
'                           Msgbox(LastException.Message, "ERROR HERE")
'                           'This VERY UGLY logic will allow you out of a missing element at position X                  
'                           End Try

                           binCrtl = uiLogic.CreateBinControl(xBinCount, currOrdData)
                           binCtrlObjLst.Add(binCrtl)   
                           
                              If xBinCount = iBinCountSubOneRef Then
                                 bAllowEntry = True 
                              End If             
                                                                                          
                        Next
         

   #End Region

Firstly I acknowledge the need to dim a new instance of the binCrtl object. But thats not the immediate concern.
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Resolved

Thanks all ..

Depth of nested types ( Custom Objects ) revisited
& Corrected, Xml . SAX parser was actually not perfect. but some how the list contents looked fine....

I re-structured the object initialization in the sax parser, to create unique new instances ...

similar to the first recommendation of Dimming the variable over and over each time before adding to the list. I have sub types in my type that although dimming up a new instance of the sub list of these widgets to actually fill them.... the type property that receives that sub-typ additionally needed to be dimmed.

This doesn't explain why the list content -- high level-- was seen in the list previously though..

either way its clean now.... thanks all for peeking at it for me
 
Upvote 0
Top