Grasshopper

algorithmic modeling for Rhino

hi - i am very new to grasshopper but somehow got into vb - i need to
1) define a string
2) add dynamically to the string from a for loop
3) print the string

i think it goes something like this:


Dim myString As String
Dim i As Integer

for i = 0 to 9
addString (", " (" & i & "))

Print(myString)

unfortunately my addString command doesnt exist - and this doesnt work - does anyone have an idea? i would like the list to be one long line separated by commas

thanks
mette

Views: 272

Replies to This Discussion

Use this:

Dim mystring As String
myString = ""
For i As int32 = 0 To 9
mystring = mystring & i & ","
print(mystring)
Next
thank you!!! this was exactly what i needed!
ohh sorry a new problem arised - can ask again?

i have a list of 9 values that i want to position in a string as a boolean true or false
the entire length of the string is 264
the 9 values are positions where the number should be 1 (true)

i think i should be doing something like this:

there is a inputList coming into the VB unit (otherwise called a). this is the list of 9 values.

Dim i As int32
Dim n As int32 'n is my temp value for true

Dim knitList(264) As int32

For i = 0 To Len(inputList)
n = inputList(i)
knitList(n) = 1
Next

' i should now have a list with 264 values with 9 true statements in it
' i now want to change the list into a string separated with commas

Dim mystring As String
Dim j As Int32

myString = ""
For j = 0 To Len(knitList)

mystring = mystring & knitList(j) & ","


Next
print(mystring)

but as before this doesnt work...

sorry to ask again
best
Mette
Your code is very buggy... I hope this helps:

Dim knitList as New List(Of Int32)
For j as int32 = 0 To 263
knitList.add(0) 'first fill your list with all 0s
Next


For i as int32 = 0 To inputList.Count-1 'i is declared right here, don't declare it before
Dim n as int32 = inputList.Item(i) 'n is temporary, so keep it within the loop
knitList.RemoveAt(n) 'now remove all the values you want to replace
knitList.Insert(n,1) 'now fill in the ones where you removed stuff
Next

The rest should follow the same logic.
hi Suryansh
thanks so much - the clearing of the lists made all the difference!
best
Mette

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service