I have two different files, fileA contains employee data (ID and townCode) while file B contains field office data (OfficeID, Town, TownCode, officeCapacity) and a town can contain more than one office. i want to distribute these employees to the offices in the town against their names evenly

What I have tried:

I read the 2 files simulteanously and created another file to hold the last office it was distributed to. My challenge is that the distribution is not even and it picks only 2 offices for the distribution

    For Each line In File.ReadLines(src1)
       Dim STRDATA() As String = line.Split({","c})
       employeeID = STRDATA(0)
       EmpTownCode = STRDATA(1)

       For Each lines In File.ReadLines(src2)
           Dim STRDATA2() As String = lines.Split({","c})

           OfficeID = STRDATA2(0)
           StrTownName = STRDATA2(1)
           StrTownCode = STRDATA2(2)
           OfficeCapacity = STRDATA2(3)
           For Each last In File.ReadLines(src3)
               lastCentre = last.Substring(0, 16)
           Next

           If StrRegTown = StrTownCode Then
               If StrCentreRef = lastCentre.Last Then
                   Exit For
               End If
               FileOpen(intoutfilenum, outfilepath, OpenMode.Append)
               WriteLine(intoutfilenum, EmployeeID, TownCode, OfficeID, OfficeCapacity)
               FileClose(intoutfilenum)
               FileOpen(intoutfilenum2, outfilepath2, OpenMode.Append)
               WriteLine(intoutfilenum2, OfficeID)
               FileClose(intoutfilenum2)
               Exit For
           End If

The code above doesn't appear to do what you asked. Back to your design (algorithm) to see where it diverged.

Some want members to write the code or app for them. I don't see that here. What I do see is help for a function, a line of code or such but not the entire solution or app.

Remember I can read the comments you made and removed so to discuss the steps you created and to compare them to your code to see where it diverged I'd have to see and read that design document. Some tend to rush into code before they have how it will work step by step. Or "I know what the result should be" and think that's enough. (it's not.)

There are places you can get apps and code written for you such as fiverr.com.

-> Back to what you have above. I don't see that code doing what you asked. Specifically it doesn't seem to keep track of office capacity and when it gets full then what to do when that happens.

commented: I have also tried to read the office file into an array-list, that didn't work too. if office capacity is full, another shift starts. +0

Reply to the discussion rather than comment. By your comments so far you need to work out the steps it takes to get to your goal.

That's called design. Design first, code later.

I don't see where StrRegTown comes from. As this is set outside the outer loop your algorithm is only ever going to match offices in one town. If this isn't what you intend, perhaps you should use EmpTownCode instead.

I also don't understand where StrCentreRef comes from or what part it plays in the algorithm. Again because it is set outside your loop it will restrict your results to only one centre. But perhaps this is what you intend.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.