v3 plugins
v3 vbscript
v2 vbscript
color match
convert curve equichordal
history hide
mesh mapper
open with V4
sel pts on crv
whats that
pure code
clean code


Ok we already have managed to calculate the distance between the entered points. Now we want to ask the user for the desired new distance. Copy and paste the following code in the cleared _EditScript window:





dblNewDistance = Rhino.GetReal("Enter new Distance")

MsgBox "New Distance = " & CStr(dblNewDistance)



Easy - but what if the user does something unexpected and enters "bla"? HAH - Rhino.GetReal ignores strings and goes on asking for a numerical value (cool). But what if the user doesn't want to enter anything and presses ESC to cancel the script? Jo, then we have a problem, and the script reports an error because if Rhino.GetReal returns null, then MsgBox cannot tell us anything because CStr() couldn't convert null (nada, rien) to a string.

Therefor a programer always has to check if everything happened like expected. Unfortunately this makes programing sometimes a pain, because catching all potential errors often takes much more time than programing the real task.

So we have to check if something has been entered, before we evoke the message box. Try this in the _EditScript window:



dblNewDistance = Rhino.GetReal("Enter new Distance")

If dblNewDistance <> vbNull Then

MsgBox "New Distance = " & CStr(dblNewDistance)

End If



If now the user presses ESC Rhino.GetReal returns null which means something different than the numerical "0". In the next line the script checks if our variable is not null, if this is true the code up to End If is proceeded. If this is NOT true = false then the script goes on after End If . But since nothing follows after that nothing else will happen.

Ofcourse now we would have to check also if the entered points were valid before we calculate the distance, and then we had to check if the calculated distance is somewhat reasonable to go on scaling the object. But for now we ignore all potential errors and clean VBscript programing stile. We go on having a focus on the niceties of RhinoScript.


© 3DE < ^ >