Reputation: 0 Apprentice
- New Members
- Active Posts:
- 7 (0.02 per day)
- 20-March 12
- Profile Views:
- Last Active:
- Mar 21 2012 07:42 AM
- Dream Kudos:
Posts I've Made
Posted 21 Mar 2012just realized that part.thanks very much @sela007!
i modified the swap() function to be like below and it seems to be working now.
Private Sub swap(ByRef a As Integer, ByRef b As Integer) ' swaps the values, and swaps for all corresponding columns after that to keep each column together Dim temp, temp2 As Integer temp = a temp2 = b b = temp a = temp2 End Sub
i dont know how to thank you.millions of thanks to you!
now i have to retrieve the Team names from my database to replace the numbers as team.
hope it will be easy.
Posted 21 Mar 2012yes. ByVal or ByRef, it underlines under
the error says
'Value of type integer cannot be converted to two-dimensional array'
Posted 21 Mar 2012hey thanks. i really hope that if i can solve the swap() function, this program will run.
Posted 21 Mar 2012@m_wylie85 is that what function swap() in C++ really does? thanks.
is there any predefined function in vb.net for the same function?
@sela007 thanks for your effort.i'm quite bad in algorithm.
well, i have succeed in running the unscheduled matches. its just the scheduled part that give me headache. the swap function is really killing me.
plus, EXIT WHILE below is translated from BREAK; in C++.
am i translating it correctly?
i think the loop is infinite loop when i use EXIT WHILE.
If count = 2 Then 084 con = False 085 Exit While 086 087 End If 088 b = b + 1 089 End While
Posted 21 Mar 2012i'm sorry.my bad.
actually i'm translating all the codes from C++ program.
i tried to google what swap() function do in C++, but i can't find the definition.
i think it is to swap the value inside the two-dimensional array.
the swap() function below is wrong.it return an integer, not an array.
Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerate.Click Dim team As Integer Dim redo As Char Dim cost As Double Dim match As Integer = 0 Dim r1, r2 As Integer Dim count As Integer = 0 Dim a, b As Integer Dim result, result2, result3, result4, result5, result6 As String Dim counterString As String Dim con As Boolean = False Dim Gen As System.Random Gen = New System.Random(My.Computer.Clock.TickCount) team = CInt(txtTeam.Text) a = 1 While a < team match = match + a a = a + 1 End While 'to run the unschedule matches Dim s(match - 1, 2) As Integer Dim counter As Integer = 1 a = 1 While a < team b = a + 1 While b <= team s(counter - 1, 0) = a s(counter - 1, 1) = b result = System.Convert.ToString(s(counter - 1, 0)) result2 = System.Convert.ToString(s(counter - 1, 1)) counterString = System.Convert.ToString(counter) result3 = "Match " + counterString + " : Team " + result + " VS Team " + result2 lstResult.Items.Add(result3) counter = counter + 1 b = b + 1 End While a = a + 1 End While 'to run scheduled matches con = False While con = False a = 0 While a < 5 ' swapping pairs randomly before start scheduling r1 = Gen.Next(1, match + 1).ToString r2 = Gen.Next(1, match + 1).ToString swap(s(r1, 0), s(r2, 0)) swap(s(r1, 1), s(r2, 1)) a = a + 1 End While con = True count = 0 a = 1 While a <= team b = 0 While b < match If s(b, 0) = a Or s(b, 1) = a Then count = count + 1 Else count = 0 End If If count = 2 Then con = False Exit While End If b = b + 1 End While a = a + 1 End While End While 'Displaying result a = 1 While a <= match result4 = System.Convert.ToString(s(a - 1, 0)) result5 = System.Convert.ToString(s(a - 1, 1)) counterString = System.Convert.ToString(a) result6 = "Match " + counterString + " : Team " + result4 + " VS Team " + result5 lstResult.Items.Add(result6) a = a + 1 End While End Sub Private Sub swap(ByVal swapArr(,) As Integer, ByVal row As Integer) ' swaps the values, and swaps for all corresponding columns after that to keep each column together Dim temp As Integer For column = 0 To swapArr.GetUpperBound(1) - 1 temp = swapArr(column, row) swapArr(column, row) = swapArr(column, row + 1) swapArr(column, row + 1) = temp Next End Sub
- Member Title:
- New D.I.C Head
- Age Unknown
- Birthday Unknown
ifmis hasn't added any friends yet.