Logical Mistake

A

Anna

Hi: In the listbox name lstOpenAccounts there are three hundred values.
In another listbox name lstseldist there are two values but it could be
three or four. Assume from the first listbox name lstOpenAccounts I
select 150 Accounts and in the second list box name lstseldist there
are two name for accounts distribution. If its a 150 values in
lstOpenAccounts then 75 each will be distribute to each name which are
in lstseldist but the program gives 76 to one and 74 to another. Its
total is 150 but the distribution is wrong. The Program goes to Case
Else in function distributeByQuantity but it not distribute values
correctly. Dont know what logic i use so that the accounts will be
distributed correctly. NEEDS HELP



Private Sub cmdAssignAccounts_Click()
Dim multiUserDistCount As Integer

Screen.MousePointer = vbHourglass
Set AcctsToDist = Nothing
If optEvenDollarDist.Value = True Then
distributeByEvenDollar
Else
distributeByQuantity (multiUserDistCount)
End If

Screen.MousePointer = vbNormal

'Calls frmUserReassign
If lstOpenAccounts.SelCount > 0 Then
frmUserReAssign.AcctCol = Nothing
frmUserReAssign.AcctCol = AcctsToDist
Set Criteria.AccountCollection = Nothing
frmUserReAssign.Show vbModal
lstOpenAccounts.Clear
cmdSelectAll.Caption = "Select All"
End If
End Sub
---------------------------------------------------------------
Public Function FindSelectedListBoxItems(LstBx As Control) As
Collection
Dim i As Long
Dim colCollection As New Collection

For i = (LstBx.ListCount - 1) To 0 Step -1
If LstBx.Selected(i) Then
colCollection.Add LstBx.List(i)
End If
Next
Set FindSelectedListBoxItems = colCollection
Set colCollection = Nothing 'New Collection
End Function

---------------------------------------------------------------
Private Sub distributeByQuantity(multiUserDistCount As Integer)
Dim distributeTo As Collection, acctsToDistribute As Collection
Dim i As Integer, c As Integer, x As Integer, j As Integer
Dim account As String, targetAIdIndex As Integer

'Calls function in modProcessingFunctions
Set distributeTo = FindSelectedListBoxItems(lstDist)
Set acctsToDistribute = FindSelectedListBoxItems(lstOpenAccounts)


'Used to maintain correct user
x = 1
j = 1

Set AcctsToDist = New Collection

Select Case multiUserDistCount
Case 0
For i = 1 To acctsToDistribute.Count
account = acctsToDistribute(i)
targetAIdIndex = 0
'get acct location in criteria.accountcollection
Do While targetAIdIndex <= lstOpenAccounts.ListCount
If lstOpenAccounts.List(targetAIdIndex) = account Then
'set j = collection index
j = targetAIdIndex + 1
'exit while loop
targetAIdIndex = lstOpenAccounts.ListCount
End If
targetAIdIndex = targetAIdIndex + 1
Loop
'save old assign_id and set new one

Criteria.AccountCollection(j).Old_Assign_Id =
Criteria.AccountCollection(j).Assign_ID
Criteria.AccountCollection(j).Assign_ID =
Trim(distributeTo(1))
AcctsToDist.Add (Criteria.AccountCollection(j))
Next
Case Else
'Used to verify each user receives the same amt
c = 0
'distribute each account


For i = 1 To acctsToDistribute.Count
'true when c = multiuserdistcount, goes to next user
If multiUserDistCount = c - 1 Then
c = 0
x = x + 1
End If
account = acctsToDistribute(i)
targetAIdIndex = 0
'get acct location in criteria.accountcollection
Do While targetAIdIndex < lstOpenAccounts.ListCount
If lstOpenAccounts.List(targetAIdIndex) = account
Then
'set j = collection index
j = targetAIdIndex + 1
'exit while loop
targetAIdIndex = lstOpenAccounts.ListCount
End If
targetAIdIndex = targetAIdIndex + 1
Loop

Criteria.AccountCollection(j).Old_Assign_Id =
Criteria.AccountCollection(j).Assign_ID
Criteria.AccountCollection(j).Assign_ID =
Trim(distributeTo(x))

AcctsToDist.Add Criteria.AccountCollection(j)
'Adds account count to user
c = c + 1
Next
End Select
 
H

Herfried K. Wagner [MVP]

Anna,

Anna said:
Hi: In the listbox name lstOpenAccounts there are three hundred values.
In another listbox name lstseldist there are two values but it could be
three or four. Assume from the first listbox name lstOpenAccounts I
select 150 Accounts and in the second list box name lstseldist there
are two name for accounts distribution.

As your question seems to be related to VB6, I suggest to post it to one of
the VB6 groups which can be found in the "microsoft.public.vb.*" hierarchy.
This group ("microsoft.public.dotnet.languages.vb") targets VB.NET, which is
no technical successor of VB6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top