Ive pretty much described the answer above, there isn't really a formula, but I'll give a bit more detail,

The script says syrup to 5mL, the important word here being 'to', so we know the solution is mainly compromised of the syrup, thus we calculate the quantity of syrup we need first and adjust amounts of the other ingredients accordingly.

So, we have 5mL of syrup, but we need 140mL. So what do we multiply 5 by to get 140? We multiply it by 28. Now, we have the 140mL of syrup, we need to adjust the quantity of the others, bearing in mind 28 is now our 'magic number' to calculate the quantities of others.

For water we have 0.1mL and for black syrup we have 1mL. Thus we multiply each of these by 28 to get our final answers of 2.8mL water and 28mL black syrup. Now we do the same with chloral hydrate, we have 200mg so we multiply it by 28, to give us 5600mg, but we should convert this to grams as no one really works with miligrams of that high quantity, so we divide 5600 by 1000 to give us 5.6 grams.

I think my previous answer was more succinct, if anything I'm not sure me explaining it here will help you understand, but anyway, I hope it helped!