The technique used here is a scan from pH 0 to pH 14. This is done first with increments of 1 pH unit, then with 0.1, 0.01, and finally 0.001 pH unit increments.
Since we "know" the pH, we simply use [H+] along with Ka or Kb to determine the ratios of [A-]/[HA] and/or [B]/[BH+] using their respective equilibrium expressions.
Adding the "mass balance" idea that both (mmol HA)+(mmol A-) and (mmol BH+)+(mmol B) must be constant, we can then determine the exact mmol of HA, A-, BH+, and B at this hypothetical pH.
We then determine the mmol of overall charge by adding up the mmol of plus charge and subtracting the mmol of minus charge at this pH. For example, if we had 1.0 mmol of Ca2+, we would count this as 2.0 mmol of plus charge. In effect, we are just making sure that the number of extra electrons (in A-, X-, and OH-) balances the number of places they are missing (in H+, BH+, and Na+, for example).
The final calculated pH, then, is the pH at which the overall charge is closest to 0. At that pH, both charge and mass are balanced.