For now My homing with reference work good.... but not like in my dream

I am able to Home with only .25-.75 inch of move, anywhere on my table stroke, I need to scan 2 index on my linear encoder
I use G31 to find my reference mark on my scale, but g31 use the machine 'software position' , for calcul the position with index, I need perfect encoder position,
after find my position with G31, I return back very slowly ( 0.5 ipm) to be able to find my index with loop in VB, I am able to GetOEMDRO(29) and set variable to calcul, I need to scan 2 index like this,
but I don't catch Index pulse every times, the VB was too slow......
--->I need function similar to G31, but when the Index pulse, save zero of my encoder...