Object reference not set to an instance of an object

Hi ,
I am new in GH and I am trying to create two arrays with VB.
I have on Error msg and two warning as in the topic.
Can’t figure it out where the proble is.
The script is below.
Thanks,
E.T.

Private Sub RunScript(ByVal Length As Object, ByVal NoLamel As Object, ByVal CThickness As Object, ByRef A As Object, ByRef B As Object) 
    'A is the matrix of the indeces and B is the matric of the thickness values

    Dim x ,y, z As Double
    Dim i As Integer
    Dim Th2 As Double
    Dim A1() As Double
    Dim B1() As Double

    Th2 = (x - z) / (y - 1)

    A1(0) = 0
    A1(1) = 1
    A1(2) = 2
    A1(3) = 3
    B1(0) = 0
    B1(1) = 0
    B1(2) = Th2
    B1(3) = Th2


    For i = 2 To 2 * y + 1
      i = i + 2
      If i <= y + 2 And i > y  Then
        A1(i) = i
        A1(i + 1) = i + 1
        B1(i) = B1(i - 1) + z
        B1(i + 1) = B1(i - 1) + z
      End If

      If i > y + 2 Then
        A1(i) = i
        A1(i + 1) = i + 1
        B1(i) = i / 2 * Th2 + z
        B1(i + 1) = i / 2 * Th2 + z
      End If

   If i < y Then
        A1(i) = i
        A1(i + 1) = i + 1
        B1(i) = i / 2 * Th2
        B1(i + 1) = i / 2 * Th2
      End If

    Next

    A = A1
    B = B1

  End Sub

I think in Vb you need to assign arrays length when you declare them? Try:

Dim A1(3) As Double
Dim B1(3) As Double

Tom

Yes, you definitely need to assign the arrays’ length before you can use them. That’s true in most languages, not just VB.

ok Thanks ! seems to work but I am confused with my Th2 is zero instead of the true value

In the code posted x,y and z are all zero, Is this not what you want?
Tom

Im Guessing you changed the names of these inputs from x,y,z? (Length, NoLamel, CThickness)

If that is true:

Add This:
x = Length
y = NoLamel
z = CThickness

Before:
Th2 = (x - z) / (y - 1)

use VS17 to code GH with, intellisense is the bomb, you know you screwed up, as you screw up (mostly)