topcoder headache

  • Thread starter Thread starter Roy Lawson
  • Start date Start date
R

Roy Lawson

Anyone care to take a stab at why I am unable to send the
array of (2,3,4,5) to the pictureFrames function? This is
for tonights topcoder competition...I was the only VB
programmer in my room again so nobody to compare with.

-Roy


Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click

Dim myworkshop As New Workshop()
Dim x As Integer
x = myworkshop.pictureFrames(2,3,4,5)

End Sub
End Class
Public Class Workshop
Dim FirstCount As Integer
Dim SecondCount As Integer
Dim ThirdCount As Integer
Dim lenArray As Integer
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim Flag As Integer = 0
Dim totalFlags As Integer = 0

Public Function pictureFrames(ByVal pieces As Integer
()) As Integer
lenArray = pieces.Length
For x = 0 To lenArray - 1
FirstCount = pieces(x)
For y = x + 1 To lenArray - 1
SecondCount = pieces(y)
For z = y + 1 To lenArray - 1
ThirdCount = pieces(z)
If FirstCount + SecondCount >
ThirdCount Then
Flag = Flag + 1
End If
If SecondCount + ThirdCount >
FirstCount Then
Flag = Flag + 1
End If
If ThirdCount + FirstCount >
SecondCount Then
Flag = Flag + 1
End If
If Flag = 3 Then totalFlags =
totalFlags + 1

Next
Next
Next
Return totalFlags
End Function
End Class
 
Roy Lawson said:
Dim myworkshop As New Workshop()
Dim x As Integer
x = myworkshop.pictureFrames(2,3,4,5)

Here you pass 4 Integer values.

Public Function pictureFrames(ByVal pieces As Integer
()) As Integer

Here you expect an Array of Integers.


Solution 1:
x = myworkshop.pictureFrames(New Integer(){2,3,4,5})

Solution 2:
Public Function pictureFrames(ByVal ParamArray pieces As Integer ()) As
Integer

(Keep the call unchanged)
 
Back
Top