Grasshopper

algorithmic modeling for Rhino

Hi;

just had a very basic question, (but in Rhinoscript, sorry!)

Does VB "GoTo" command work in Rhinoscript? if yes how?

i try to use "GoTo" command in Rhinoscript but it doesn't work .. 

error: "expected statement" .. (of course i named the line to which i wanted to "GoTo"!)

 just paste a simple code as an example to show what's not working:

 

   Dim obj

   Line03: obj=Rhino.GetObject ("pick curve") 

   If Not IsCurve(obj) Then 

   GoTo line03

   Else  Call Rhino.print ("ok!") 

   End If

   End Sub

 

any heLpPp?

thnXx

Views: 5965

Replies to This Discussion

Yes VB.Net does have a GoTo statement

NO you should NOT use it.

I cannot think of any situation that would warrant a GoTo statement.  Any branching in logic can be achieved by if, case statements, loops, and/or function calls.

 

I come across this pure hatred of Goto more often. My own feelings on the matter are not quite as polarised. I'd concede that the old VB GoTo statement which used Line Numbers as targets was indeed very problematic, but when you use Named Labels as targets it is a perfectly valid construct. I'd much rather use a GoTo statement than nesting three if blocks and keeping flag bools around if that's the alternative.

 

One thing I did notice is that whenever I do use a GoTo statement, it always ends up evaporating when I restructure the code. There's a lesson in here somewhere, but I can't quite put my finger on it. Maybe it's that GoTo itself is not evil, but it does tend to highlight evil code.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Does Peek and poke still exists? You can make your own Pixels if you Know the Adress ....

Dim obj
Dim counter
counter=0

Do
counter=counter+1
obj=Rhino.GetObject("pick curve")
Loop While (Not Rhino.isCurve(obj) And counter<10)

If(counter=10) Then
Rhino.Print("No Curve Picked")
Else
Rhino.Print("Ok")
End If
'It's better to use loop...

ThnxX a lot GzeRo and Damien,

 

i just want to know is it a technical problem that "GoTo" does'nt work in Rhinoscript or..?

'cause everyone hates it .. :D

 

Ciao

GoTo isn't available in VBScript. You'll need to use Loops, Ifs or Exit statements to manage your runtime flow.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

"Everyone" hates GoTo statments not because of what they are, but because of its general history and what is "used" to be.  Way back when GoTo statements used to only be able to refer to line numbers.  So as long as the code never changed and whatever statement was on Line N stayed on Line N, then everything was fine.  But if you changed anything earlier in that code file, all of the sudden there's a completely different statement on Line N, and that can cause a whole lot of issues.  More "modern" GoTo statements have the capability of labeling the line you're going to, which gets around that.

 

The reason I don't like GoTo statements is that its generally an indication that a piece of code could be rewritten or restructured (aka refactored) so that the logic is much more clear.  The other reason why I don't like it is that its not very apparent to others (or even you going back to old code) why the GoTo statement is there or what that statement that's gone to is supposed to do.  When you modify the structure of your code and break small pieces of logic into functions, it is much more apparent what that function is meant to do and much more evident in the code that calls that function.  It produces code that's much more readable, debuggable, and maintainable.

 

There isn't anything technically wrong with GoTo statments as they are a "feature" of .Net.  But just because its not wrong doesn't make it right. 

ah ah reminds me of my old atari 800 (the one with big cartriges of mario bros., donkey kong, pacman...) I still have it stored somewhere, allong with some Basic v0.0.0.0.0.1 interpreter on a floppy!

thnXx David and the others ...!

 

another "beginners" question will appear in a few moments,. if u let me :D

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service