Page 1 of 1

Accessing sales order lines by line number ( index )

PostPosted: Mon Aug 10, 2015 3:53 pm
by indikad
I need to loop through OR access the sales order lines using the incremental number ( NOT in a For Each loop )
however my syntax gives me an error "Overload resolution failed because no accessible "Item" can be called without a narrowing conversion"
on compilaiton - see my code below. The issue is on the msgbox line
appreciate if someone can help.

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      If TypeOf JiwaForm Is JiwaSalesUI.SalesOrder.SalesOrderEntryForm  Then         
           Dim SalesOrdForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)         
'         AddHandler  SalesOrdForm.SalesOrder.Created , AddressOf SalesOrderCreated   
         AddHandler SalesOrdForm.SalesOrder.CreateEnd , AddressOf SalesOrderCreateEnd
       End If
    End Sub
   Public Sub SalesOrderCreateEnd(ByVal sender As Object ,ByVal  e As  System.EventArgs )
      Dim oSalesOrder As JiwaSales.SalesOrder.SalesOrder   = DirectCast( sender , JiwaSales.SalesOrder.SalesOrder )
      Dim lOrdLine As Long       
      For lOrdLine = 1 To oSalesOrder.SalesOrderLines.Count 
         msgbox(   oSalesOrder.SalesOrderLines.Item(lOrdLine).PartNo.ToString())         
      Next
      
   End Sub

Re: Traversing sales order lines by line number

PostPosted: Tue Aug 11, 2015 8:36 am
by DannyC
Indika,
This might help

Code: Select all
      
For Each lOrdLine As JiwaSales.SalesOrder.SalesOrderLine In oSalesOrder.SalesOrderLines
      Msgboxl(lOrdLine.PartNo & "    " & lOrdLine.ItemNo )
Next


You may be able to help me with some outstanding questions...!

Re: Traversing sales order lines by line number

PostPosted: Tue Aug 11, 2015 12:53 pm
by indikad
Hi Danny - thanks for the attention.

I am aware of the For each way of looping.
as per my original post - I need a another way WITHOUT the use of "For Each"

also at times I need to access the line item and edit it using something like
Code: Select all
_oCurrentSalesOrder.SalesOrderLines("Linendex").QuantityOrdered = 500  ' this code does not work

Re: Accessing sales order lines by line number ( index )  Topic is solved

PostPosted: Tue Aug 18, 2015 4:38 pm
by Mike.Sheen
indikad wrote:I need to loop through OR access the sales order lines using the incremental number ( NOT in a For Each loop )
however my syntax gives me an error "Overload resolution failed because no accessible "Item" can be called without a narrowing conversion"
on compilaiton - see my code below. The issue is on the msgbox line
appreciate if someone can help.

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      If TypeOf JiwaForm Is JiwaSalesUI.SalesOrder.SalesOrderEntryForm  Then         
           Dim SalesOrdForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)         
'         AddHandler  SalesOrdForm.SalesOrder.Created , AddressOf SalesOrderCreated   
         AddHandler SalesOrdForm.SalesOrder.CreateEnd , AddressOf SalesOrderCreateEnd
       End If
    End Sub
   Public Sub SalesOrderCreateEnd(ByVal sender As Object ,ByVal  e As  System.EventArgs )
      Dim oSalesOrder As JiwaSales.SalesOrder.SalesOrder   = DirectCast( sender , JiwaSales.SalesOrder.SalesOrder )
      Dim lOrdLine As Long       
      For lOrdLine = 1 To oSalesOrder.SalesOrderLines.Count 
         msgbox(   oSalesOrder.SalesOrderLines.Item(lOrdLine).PartNo.ToString())         
      Next
      
   End Sub


Instead of

Code: Select all
Dim lOrdLine As Long


Try

Code: Select all
Dim lOrdLine As Integer

Re: Accessing sales order lines by line number ( index )

PostPosted: Tue Aug 18, 2015 5:01 pm
by indikad
Thanks Mike. Will update soon.