Using Microstation VBA, I am trying to read text at specific location. I have text placed in specific locations in dgn file that I now need to read. I do not want to read text at other locations. I defined a variable "dTxtLoc" as double and assigned a value to it. I then read a text and checked if Origin.X value was equal to dTxtLoc. Even when I used the same value as Origin.X, the code does not treat them as equal. Tried to comparwe these as string values but even then it did not treat them as equal. What am I missing?
Anuj Srivastava said:when I used the same value as Origin.X, the code does not treat them as equal.
Anuj Srivastava said:Dim xVal As DoublexVal = 0.779060869565217 'this is the value of TxtInput.Origin.X in locals window of VBA and hardcoded in program to check
If ((TxtInput.Origin.X - xVal) = 0) Then MsgBox TxtInput.Text EndIf
As Jan wrote, comparing floating-point numbers is tricky. The different between two floating-point numbers is unlikely ever to be (integer) 0.
Anuj Srivastava said: Tried to compare these as string values but even then it did not treat them as equal
Treating floating-point numbers as Strings is bizarre. A computer is far better at handling numbers than you. You need to study computer science and number theory.
String
As Jan suggested, try Point3dEqualTolerance() to compare two points.
Point3dEqualTolerance()
Regards, Jon Summers LA Solutions