Please give me some suggestions while the code gets that error when i run it.

Private Sub cmdRectangle_Click()

Dim Speed, r As Double
Dim x1, x2, x3, y1, y2, y3, z1, z2, z3 As Double
Dim NewValueX1, NewValueY1, NewValueZ1, NewValueX2, NewValueY2, NewValueZ2 As Double

If Text1.Text <> "" Or Text2.Text <> "" Or Text3.Text <> "" Then
x1 = CDbl(Text1.Text)
y1 = CDbl(Text2.Text)
z1 = CDbl(Text3.Text)
End If
If Text4.Text <> "" Or Text5.Text <> "" Or Text6.Text <> "" Then
x2 = CDbl(Text4.Text)
y2 = CDbl(Text5.Text)
z2 = CDbl(Text6.Text)
End If
If Text7.Text <> "" Or Text8.Text <> "" Or Text9.Text <> "" Then
x3 = CDbl(Text7.Text)
y3 = CDbl(Text8.Text)
z3 = CDbl(Text9.Text)
End If

r = 0
Speed = CInt(Text13.Text)
If Speed >= 50 And Speed < 100 Then
r = 0.167
ElseIf Speed >= 100 And Speed < 200 Then
r = 0.667
ElseIf Speed = 200 Then
r = 2.667
End If

Dim CheckRectangle As Integer
// when the code run here, it will show the error message//
CheckRectangle = NewPointOnRectangle(x1, y1, z1, x2, y2, z2, x3, y3, z3, r, NewValueX1, NewValueY1, NewValueZ1, NewValueX2, NewValueY2, NewValueZ2, NewCenterX1, NewCenterY1, NewCenterZ1)

If CheckRectangle < 0 Then
Exit Sub
End If
-----------------------------------------------------------------------
Public Function NewPointOnRectangle(ByVal x1 As Double, ByVal y1 As Double, ByVal z1 As Double, ByVal x2 As Double, ByVal y2 As Data, ByVal z2 As Double, ByVal x3 As Double, ByVal y3 As Double, ByVal z3 As Double, ByVal r As Double, ByRef NewX As Variant, NewY As Variant, NewZ As Variant, NewXX As Variant, NewYY As Variant, NewZZ As Variant, NewFilletCenterX As Variant, NewFilletCenterY As Variant, NewFilletCenterZ As Variant) As Integer
Dim FilletCenterX, FilletCenterY, FilletCenterZ As Double
Dim LineFillet As Integer
Dim x4, y4, z4 As Double

x4 = x3
y4 = y3
z4 = z3
x3 = x2
y3 = y2
z3 = z2

If (z1 = z2) And (z1 = z4) And (z2 = z4) Then
LineFillet = LinesFillet2D(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, r, FilletCenterX, FilletCenterY, FilletCenterZ)
If LineFillet = -1 Then
NewPointOnRectangle = -1
Exit Function
Else
NewX = x2
NewY = y2
NewZ = z2
NewXX = x3
NewYY = y3
NewZZ = z3
NewFilletCenterX = FilletCenterX
NewFilletCenterY = FilletCenterY
NewFilletCenterZ = FilletCenterZ
End If
Else
LineFillet = LinesFilletArc(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, r, FilletCenterX, FilletCenterY, FilletCenterZ)
If LineFillet = -1 Then
NewPointOnRectangle = -1
Exit Function
Else
NewX = x2
NewY = y2
NewZ = z2
NewXX = x3
NewYY = y3
NewZZ = z3
NewFilletCenterX = FilletCenterX
NewFilletCenterY = FilletCenterY
NewFilletCenterZ = FilletCenterZ
End If
End If
NewPointOnRectangle = 0
End Function

your function doesnt return anything, so you cant set an int equal to null

Could you please explain me clearly why the function doesn't return anything?

In order to return a variable you need to say something like
Return NewPointOnRectangle

all your saying is
NewPointOnRectangle = 0
which sets NewPointOnRectangle equal to 0 then doesnt do anything with it

In order to return a variable you need to say something like
Return NewPointOnRectangle

all your saying is
NewPointOnRectangle = 0
which sets NewPointOnRectangle equal to 0 then doesnt do anything with it

You're wrong. I tried the following code on my machine and it worked!!

Sub main()
    Call MsgBox("myfunc = " & CStr(myfunc))
End Sub

Function myfunc() As Integer
    myfunc = 1
End Function

Hoppy

I can two problems with your code.

1. There is no End Sub for the sub routine ' Private Sub cmdRectangle_Click()'

2. In the function ' Public Function NewPointOnRectangle' you have defined a variable as 'ByVal y2 As Data'. If this is a user defined type you need to define it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.