2 different numbers.....

S

Supra

how do i get 2 different number in same row? using random
example:

4 2
5 6
7 4
1 7
9 8
3 3 <===== i want different number but not same as opposite
8 5
6 8
2 1

in my code:

Dim Nine_numbers(9) as short
Dim nm, mm As Integer, nine(9), nineA(9) As Object, innn, mmm As Short
Dim j, k As Integer
For innn = 1 To 9
nine(innn) = innn
Next
For innn = 1 To 9
Do
Dim rng As New Random
k = rng.Next(1, 10)
Loop Until nine(k) > 0
nine(k) = 0
szArray(innn) = k
TextBox82.Text = szArray(1)
TextBox91.Text = szArray(2)
TextBox100.Text = szArray(3)
TextBox83.Text = szArray(4)
TextBox92.Text = szArray(5)
TextBox101.Text = szArray(6)
TextBox84.Text = szArray(7)
TextBox93.Text = szArray(8)
TextBox102.Text = szArray(9)
Debug.WriteLine(szArray(innn))
Next

For mmm = 1 To 9
nineA(mmm) = mmm
Next
For mmm = 1 To 9
Do
Dim rng As New Random
j = rng.Next(1, 10)
Loop Until nineA(j) > 0
nineA(j) = 0
szArray(mmm) = j
TextBox85.Text = szArray(1)
TextBox94.Text = szArray(2)
TextBox103.Text = szArray(3)
TextBox86.Text = szArray(4)
TextBox95.Text = szArray(5)
TextBox104.Text = szArray(6)
TextBox87.Text = szArray(7)
TextBox96.Text = szArray(8)
TextBox105.Text = szArray(9)
Debug.WriteLine(szArray(mmm))
Next

ne iideas?
regards
 
P

Peter Proost

Hi,

there probably will be better ways but this does seem to do the trick for me

just open a new windows forms project add a button to it and copy paste this
code, the makeGrid part is just to show the use of a textbox array

hth
Greetz Peter

Private textboxGrid(8, 1) As TextBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
makeGrid()
fillRandom()
End Sub

Private Sub makeGrid()
Dim x As TextBox
Dim xPos, yPos As Integer
yPos = 20
For row As Integer = 0 To 8
xPos = 20
For column As Integer = 0 To 1
x = New TextBox
x.Name = (CStr(row) & CStr(column))
x.Location = New Point(xPos, yPos)
x.BorderStyle = BorderStyle.FixedSingle
x.Width = 20
x.Height = 20
x.Text = ""
Me.Controls.Add(x)
textboxGrid(row, column) = x
xPos += 21
Next
yPos += 21
Next
End Sub

Private Sub fillRandom()
Dim blnOk As Boolean
For row As Integer = 0 To 8
blnOk = False
Do While blnOk = False
textboxGrid(row, 0).Text = CStr(CInt(Rnd() * 9) + 1)
textboxGrid(row, 1).Text = CStr(CInt(Rnd() * 9) + 1)
If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text Then
blnOk = True
End If
Loop
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ Button1.Click
fillRandom()
End Sub
 
S

Supra

nope. u have duplicate numbers in same column

Peter said:
Hi,

there probably will be better ways but this does seem to do the trick for me

just open a new windows forms project add a button to it and copy paste this
code, the makeGrid part is just to show the use of a textbox array

hth
Greetz Peter

Private textboxGrid(8, 1) As TextBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
makeGrid()
fillRandom()
End Sub

Private Sub makeGrid()
Dim x As TextBox
Dim xPos, yPos As Integer
yPos = 20
For row As Integer = 0 To 8
xPos = 20
For column As Integer = 0 To 1
x = New TextBox
x.Name = (CStr(row) & CStr(column))
x.Location = New Point(xPos, yPos)
x.BorderStyle = BorderStyle.FixedSingle
x.Width = 20
x.Height = 20
x.Text = ""
Me.Controls.Add(x)
textboxGrid(row, column) = x
xPos += 21
Next
yPos += 21
Next
End Sub

Private Sub fillRandom()
Dim blnOk As Boolean
For row As Integer = 0 To 8
blnOk = False
Do While blnOk = False
textboxGrid(row, 0).Text = CStr(CInt(Rnd() * 9) + 1)
textboxGrid(row, 1).Text = CStr(CInt(Rnd() * 9) + 1)
If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text Then
blnOk = True
End If
Loop
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ Button1.Click
fillRandom()
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht
 
P

Peter Proost

you said:
how do i get 2 different number in same row? using random
example:

but it shouldn't be to difficult to alter my example

Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht nope. u have duplicate numbers in same column

Peter Proost wrote:
Hi,

there probably will be better ways but this does seem to do the trick for me

just open a new windows forms project add a button to it and copy paste this
code, the makeGrid part is just to show the use of a textbox array

hth
Greetz Peter

Private textboxGrid(8, 1) As TextBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
makeGrid()
fillRandom()
End Sub

Private Sub makeGrid()
Dim x As TextBox
Dim xPos, yPos As Integer
yPos = 20
For row As Integer = 0 To 8
xPos = 20
For column As Integer = 0 To 1
x = New TextBox
x.Name = (CStr(row) & CStr(column))
x.Location = New Point(xPos, yPos)
x.BorderStyle = BorderStyle.FixedSingle
x.Width = 20
x.Height = 20
x.Text = ""
Me.Controls.Add(x)
textboxGrid(row, column) = x
xPos += 21
Next
yPos += 21
Next
End Sub

Private Sub fillRandom()
Dim blnOk As Boolean
For row As Integer = 0 To 8
blnOk = False
Do While blnOk = False
textboxGrid(row, 0).Text = CStr(CInt(Rnd() * 9) + 1)
textboxGrid(row, 1).Text = CStr(CInt(Rnd() * 9) + 1)
If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text Then
blnOk = True
End If
Loop
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ Button1.Click
fillRandom()
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht
how do i get 2 different number in same row? using random
example:

4 2
5 6
7 4
1 7
9 8
3 3 <===== i want different number but not same as opposite
8 5
6 8
2 1

in my code:

Dim Nine_numbers(9) as short
Dim nm, mm As Integer, nine(9), nineA(9) As Object, innn, mmm As Short
Dim j, k As Integer
For innn = 1 To 9
nine(innn) = innn
Next
For innn = 1 To 9
Do
Dim rng As New Random
k = rng.Next(1, 10)
Loop Until nine(k) > 0
nine(k) = 0
szArray(innn) = k
TextBox82.Text = szArray(1)
TextBox91.Text = szArray(2)
TextBox100.Text = szArray(3)
TextBox83.Text = szArray(4)
TextBox92.Text = szArray(5)
TextBox101.Text = szArray(6)
TextBox84.Text = szArray(7)
TextBox93.Text = szArray(8)
TextBox102.Text = szArray(9)
Debug.WriteLine(szArray(innn))
Next

For mmm = 1 To 9
nineA(mmm) = mmm
Next
For mmm = 1 To 9
Do
Dim rng As New Random
j = rng.Next(1, 10)
Loop Until nineA(j) > 0
nineA(j) = 0
szArray(mmm) = j
TextBox85.Text = szArray(1)
TextBox94.Text = szArray(2)
TextBox103.Text = szArray(3)
TextBox86.Text = szArray(4)
TextBox95.Text = szArray(5)
TextBox104.Text = szArray(6)
TextBox87.Text = szArray(7)
TextBox96.Text = szArray(8)
TextBox105.Text = szArray(9)
Debug.WriteLine(szArray(mmm))
Next

ne iideas?
regards
 
S

Supra

yes. but i random number in each column but compare row. what u do u
do random number have having same number in COLUMN but not in row not
ilike 775422133 in column but in order prevented same number in column
like i did previous code::
Loop Until (Nine_numbers3(inum3) > 0)
Nine_numbers3(inum3) = 0
szArray(n) = inum3
that is code will prevent same numbers. i was attempting subsistue in
ur sample code...
For row As Integer = 0 To 8
blnOk = False
Do
' blnOk = False
textboxGrid(row, 0).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 1).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 2).Text = Int(9 * Rnd() + 1)
' If textboxGrid(row, 0).Text <> textboxGrid(row,
1).Text <> textboxGrid(row, 2).Text Then
' blnOk = True
' End If
Loop Until textboxGrid(row, 0).Text > 0
Next
but can't figuring it out..... i will have to work around.
regards,
 
P

Peter Proost

Hi I'm going home now, but I'll try to help you 2morrow (I'm not sure if I'll have access to a .net computer tonight)

Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht yes. but i random number in each column but compare row. what u do u do random number have having same number in COLUMN but not in row not ilike 775422133 in column but in order prevented same number in column like i did previous code::
Loop Until (Nine_numbers3(inum3) > 0)
Nine_numbers3(inum3) = 0
szArray(n) = inum3
that is code will prevent same numbers. i was attempting subsistue in ur sample code...
For row As Integer = 0 To 8
blnOk = False
Do
' blnOk = False
textboxGrid(row, 0).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 1).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 2).Text = Int(9 * Rnd() + 1)
' If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text <> textboxGrid(row, 2).Text Then
' blnOk = True
' End If
Loop Until textboxGrid(row, 0).Text > 0
Next
but can't figuring it out..... i will have to work around.
regards,


Peter Proost wrote:
how do i get 2 different number in same row? using random
example:

but it shouldn't be to difficult to alter my example

Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht nope. u have duplicate numbers in same column

Peter Proost wrote:
Hi,

there probably will be better ways but this does seem to do the trick for me

just open a new windows forms project add a button to it and copy paste this
code, the makeGrid part is just to show the use of a textbox array

hth
Greetz Peter

Private textboxGrid(8, 1) As TextBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
makeGrid()
fillRandom()
End Sub

Private Sub makeGrid()
Dim x As TextBox
Dim xPos, yPos As Integer
yPos = 20
For row As Integer = 0 To 8
xPos = 20
For column As Integer = 0 To 1
x = New TextBox
x.Name = (CStr(row) & CStr(column))
x.Location = New Point(xPos, yPos)
x.BorderStyle = BorderStyle.FixedSingle
x.Width = 20
x.Height = 20
x.Text = ""
Me.Controls.Add(x)
textboxGrid(row, column) = x
xPos += 21
Next
yPos += 21
Next
End Sub

Private Sub fillRandom()
Dim blnOk As Boolean
For row As Integer = 0 To 8
blnOk = False
Do While blnOk = False
textboxGrid(row, 0).Text = CStr(CInt(Rnd() * 9) + 1)
textboxGrid(row, 1).Text = CStr(CInt(Rnd() * 9) + 1)
If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text Then
blnOk = True
End If
Loop
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ Button1.Click
fillRandom()
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht
how do i get 2 different number in same row? using random
example:

4 2
5 6
7 4
1 7
9 8
3 3 <===== i want different number but not same as opposite
8 5
6 8
2 1

in my code:

Dim Nine_numbers(9) as short
Dim nm, mm As Integer, nine(9), nineA(9) As Object, innn, mmm As Short
Dim j, k As Integer
For innn = 1 To 9
nine(innn) = innn
Next
For innn = 1 To 9
Do
Dim rng As New Random
k = rng.Next(1, 10)
Loop Until nine(k) > 0
nine(k) = 0
szArray(innn) = k
TextBox82.Text = szArray(1)
TextBox91.Text = szArray(2)
TextBox100.Text = szArray(3)
TextBox83.Text = szArray(4)
TextBox92.Text = szArray(5)
TextBox101.Text = szArray(6)
TextBox84.Text = szArray(7)
TextBox93.Text = szArray(8)
TextBox102.Text = szArray(9)
Debug.WriteLine(szArray(innn))
Next

For mmm = 1 To 9
nineA(mmm) = mmm
Next
For mmm = 1 To 9
Do
Dim rng As New Random
j = rng.Next(1, 10)
Loop Until nineA(j) > 0
nineA(j) = 0
szArray(mmm) = j
TextBox85.Text = szArray(1)
TextBox94.Text = szArray(2)
TextBox103.Text = szArray(3)
TextBox86.Text = szArray(4)
TextBox95.Text = szArray(5)
TextBox104.Text = szArray(6)
TextBox87.Text = szArray(7)
TextBox96.Text = szArray(8)
TextBox105.Text = szArray(9)
Debug.WriteLine(szArray(mmm))
Next

ne iideas?
regards
 
S

Supra

have nice day trip :)

Peter said:
Hi I'm going home now, but I'll try to help you 2morrow (I'm not sure
if I'll have access to a .net computer tonight)

Greetz Peter

--
Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe trying
to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected] <mailto:[email protected]>>
schreef in bericht yes. but i random number in each column but compare row. what u
do u do random number have having same number in COLUMN but not
in row not ilike 775422133 in column but in order prevented same
number in column like i did previous code::
Loop Until (Nine_numbers3(inum3) > 0)
Nine_numbers3(inum3) = 0
szArray(n) = inum3
that is code will prevent same numbers. i was attempting
subsistue in ur sample code...
For row As Integer = 0 To 8
blnOk = False
Do
' blnOk = False
textboxGrid(row, 0).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 1).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 2).Text = Int(9 * Rnd() + 1)
' If textboxGrid(row, 0).Text <> textboxGrid(row,
1).Text <> textboxGrid(row, 2).Text Then
' blnOk = True
' End If
Loop Until textboxGrid(row, 0).Text > 0
Next
but can't figuring it out..... i will have to work around.
regards,
 
P

Peter Proost

Hi try it with this code in the fillrandom sub, it should work:

Private Sub fillRandom()
Dim left As New ArrayList
Dim right As New ArrayList
Dim blnOk As Boolean = False
Dim intGetal As Integer
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If left.IndexOf(intGetal) < 0 Then
left.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If right.IndexOf(intGetal) < 0 And intGetal <> CInt(left(i)) Then
right.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next

For i As Integer = 0 To 8
textboxGrid(i, 0).Text = CStr(left(i))
textboxGrid(i, 1).Text = CStr(right(i))
Next

End Sub


hth Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht have nice day trip :)

Peter Proost wrote:

Hi I'm going home now, but I'll try to help you 2morrow (I'm not sure if I'll have access to a .net computer tonight)

Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht yes. but i random number in each column but compare row. what u do u do random number have having same number in COLUMN but not in row not ilike 775422133 in column but in order prevented same number in column like i did previous code::
Loop Until (Nine_numbers3(inum3) > 0)
Nine_numbers3(inum3) = 0
szArray(n) = inum3
that is code will prevent same numbers. i was attempting subsistue in ur sample code...
For row As Integer = 0 To 8
blnOk = False
Do
' blnOk = False
textboxGrid(row, 0).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 1).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 2).Text = Int(9 * Rnd() + 1)
' If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text <> textboxGrid(row, 2).Text Then
' blnOk = True
' End If
Loop Until textboxGrid(row, 0).Text > 0
Next
but can't figuring it out..... i will have to work around.
regards,


Peter Proost wrote:
how do i get 2 different number in same row? using random
example:

but it shouldn't be to difficult to alter my example

Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht nope. u have duplicate numbers in same column

Peter Proost wrote:
Hi,

there probably will be better ways but this does seem to do the trick for me

just open a new windows forms project add a button to it and copy paste this
code, the makeGrid part is just to show the use of a textbox array

hth
Greetz Peter

Private textboxGrid(8, 1) As TextBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
makeGrid()
fillRandom()
End Sub

Private Sub makeGrid()
Dim x As TextBox
Dim xPos, yPos As Integer
yPos = 20
For row As Integer = 0 To 8
xPos = 20
For column As Integer = 0 To 1
x = New TextBox
x.Name = (CStr(row) & CStr(column))
x.Location = New Point(xPos, yPos)
x.BorderStyle = BorderStyle.FixedSingle
x.Width = 20
x.Height = 20
x.Text = ""
Me.Controls.Add(x)
textboxGrid(row, column) = x
xPos += 21
Next
yPos += 21
Next
End Sub

Private Sub fillRandom()
Dim blnOk As Boolean
For row As Integer = 0 To 8
blnOk = False
Do While blnOk = False
textboxGrid(row, 0).Text = CStr(CInt(Rnd() * 9) + 1)
textboxGrid(row, 1).Text = CStr(CInt(Rnd() * 9) + 1)
If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text Then
blnOk = True
End If
Loop
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ Button1.Click
fillRandom()
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht
how do i get 2 different number in same row? using random
example:

4 2
5 6
7 4
1 7
9 8
3 3 <===== i want different number but not same as opposite
8 5
6 8
2 1

in my code:

Dim Nine_numbers(9) as short
Dim nm, mm As Integer, nine(9), nineA(9) As Object, innn, mmm As Short
Dim j, k As Integer
For innn = 1 To 9
nine(innn) = innn
Next
For innn = 1 To 9
Do
Dim rng As New Random
k = rng.Next(1, 10)
Loop Until nine(k) > 0
nine(k) = 0
szArray(innn) = k
TextBox82.Text = szArray(1)
TextBox91.Text = szArray(2)
TextBox100.Text = szArray(3)
TextBox83.Text = szArray(4)
TextBox92.Text = szArray(5)
TextBox101.Text = szArray(6)
TextBox84.Text = szArray(7)
TextBox93.Text = szArray(8)
TextBox102.Text = szArray(9)
Debug.WriteLine(szArray(innn))
Next

For mmm = 1 To 9
nineA(mmm) = mmm
Next
For mmm = 1 To 9
Do
Dim rng As New Random
j = rng.Next(1, 10)
Loop Until nineA(j) > 0
nineA(j) = 0
szArray(mmm) = j
TextBox85.Text = szArray(1)
TextBox94.Text = szArray(2)
TextBox103.Text = szArray(3)
TextBox86.Text = szArray(4)
TextBox95.Text = szArray(5)
TextBox104.Text = szArray(6)
TextBox87.Text = szArray(7)
TextBox96.Text = szArray(8)
TextBox105.Text = szArray(9)
Debug.WriteLine(szArray(mmm))
Next

ne iideas?
regards
 
S

Supra

:)

Peter said:
Hi try it with this code in the fillrandom sub, it should work:

Private Sub fillRandom()
Dim left As New ArrayList
Dim right As New ArrayList
Dim blnOk As Boolean = False
Dim intGetal As Integer
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If left.IndexOf(intGetal) < 0 Then
left.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If right.IndexOf(intGetal) < 0 And intGetal <>
CInt(left(i)) Then
right.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next

For i As Integer = 0 To 8
textboxGrid(i, 0).Text = CStr(left(i))
textboxGrid(i, 1).Text = CStr(right(i))
Next

End Sub


hth Greetz Peter

--
Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe trying
to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected] <mailto:[email protected]>>
schreef in bericht have nice day trip :)
 
P

Peter Proost

Yes you can after you copy paste this fillRandom, there was a nice little endless loop in my previous fill random:
for example if the left and right numbers were like this:
4 3
7 9
2 7
3 6
5 8
8 2
6 5
9 4
1

then it would try to add 1 as the last number to the right column but that isn't allowed so an endless loop because all other numbers are already added to the two array's

This is the new code, hth greetz Peter:

Private Sub fillRandom()
Dim left As New ArrayList
Dim right As New ArrayList
Dim blnOk As Boolean = False
Dim intGetal As Integer
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If left.IndexOf(intGetal) < 0 Then
left.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If right.IndexOf(intGetal) < 0 And intGetal <> CInt(left(i)) Then
right.Add(intGetal)
blnOk = True
Else
If i < 8 Then
blnOk = False
Else
If intGetal = CInt(left(i)) Then
blnOk = True
i = -1
right.Clear()
End If
End If
End If
Loop
Next

For i As Integer = 0 To 8
textboxGrid(i, 0).Text = CStr(left(i))
textboxGrid(i, 1).Text = CStr(right(i))
Next

End Sub

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht can i continue more clicking than stopping at 8 times?

Peter Proost wrote:

Hi try it with this code in the fillrandom sub, it should work:

Private Sub fillRandom()
Dim left As New ArrayList
Dim right As New ArrayList
Dim blnOk As Boolean = False
Dim intGetal As Integer
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If left.IndexOf(intGetal) < 0 Then
left.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If right.IndexOf(intGetal) < 0 And intGetal <> CInt(left(i)) Then
right.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next

For i As Integer = 0 To 8
textboxGrid(i, 0).Text = CStr(left(i))
textboxGrid(i, 1).Text = CStr(right(i))
Next

End Sub


hth Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht have nice day trip :)

Peter Proost wrote:

Hi I'm going home now, but I'll try to help you 2morrow (I'm not sure if I'll have access to a .net computer tonight)

Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht yes. but i random number in each column but compare row. what u do u do random number have having same number in COLUMN but not in row not ilike 775422133 in column but in order prevented same number in column like i did previous code::
Loop Until (Nine_numbers3(inum3) > 0)
Nine_numbers3(inum3) = 0
szArray(n) = inum3
that is code will prevent same numbers. i was attempting subsistue in ur sample code...
For row As Integer = 0 To 8
blnOk = False
Do
' blnOk = False
textboxGrid(row, 0).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 1).Text = Int(9 * Rnd() + 1)
' textboxGrid(row, 2).Text = Int(9 * Rnd() + 1)
' If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text <> textboxGrid(row, 2).Text Then
' blnOk = True
' End If
Loop Until textboxGrid(row, 0).Text > 0
Next
but can't figuring it out..... i will have to work around.
regards,


Peter Proost wrote:
how do i get 2 different number in same row? using random
example:

but it shouldn't be to difficult to alter my example

Greetz Peter

--
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht nope. u have duplicate numbers in same column

Peter Proost wrote:
Hi,

there probably will be better ways but this does seem to do the trick for me

just open a new windows forms project add a button to it and copy paste this
code, the makeGrid part is just to show the use of a textbox array

hth
Greetz Peter

Private textboxGrid(8, 1) As TextBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
makeGrid()
fillRandom()
End Sub

Private Sub makeGrid()
Dim x As TextBox
Dim xPos, yPos As Integer
yPos = 20
For row As Integer = 0 To 8
xPos = 20
For column As Integer = 0 To 1
x = New TextBox
x.Name = (CStr(row) & CStr(column))
x.Location = New Point(xPos, yPos)
x.BorderStyle = BorderStyle.FixedSingle
x.Width = 20
x.Height = 20
x.Text = ""
Me.Controls.Add(x)
textboxGrid(row, column) = x
xPos += 21
Next
yPos += 21
Next
End Sub

Private Sub fillRandom()
Dim blnOk As Boolean
For row As Integer = 0 To 8
blnOk = False
Do While blnOk = False
textboxGrid(row, 0).Text = CStr(CInt(Rnd() * 9) + 1)
textboxGrid(row, 1).Text = CStr(CInt(Rnd() * 9) + 1)
If textboxGrid(row, 0).Text <> textboxGrid(row, 1).Text Then
blnOk = True
End If
Loop
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ Button1.Click
fillRandom()
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected]> schreef in bericht
how do i get 2 different number in same row? using random
example:

4 2
5 6
7 4
1 7
9 8
3 3 <===== i want different number but not same as opposite
8 5
6 8
2 1

in my code:

Dim Nine_numbers(9) as short
Dim nm, mm As Integer, nine(9), nineA(9) As Object, innn, mmm As Short
Dim j, k As Integer
For innn = 1 To 9
nine(innn) = innn
Next
For innn = 1 To 9
Do
Dim rng As New Random
k = rng.Next(1, 10)
Loop Until nine(k) > 0
nine(k) = 0
szArray(innn) = k
TextBox82.Text = szArray(1)
TextBox91.Text = szArray(2)
TextBox100.Text = szArray(3)
TextBox83.Text = szArray(4)
TextBox92.Text = szArray(5)
TextBox101.Text = szArray(6)
TextBox84.Text = szArray(7)
TextBox93.Text = szArray(8)
TextBox102.Text = szArray(9)
Debug.WriteLine(szArray(innn))
Next

For mmm = 1 To 9
nineA(mmm) = mmm
Next
For mmm = 1 To 9
Do
Dim rng As New Random
j = rng.Next(1, 10)
Loop Until nineA(j) > 0
nineA(j) = 0
szArray(mmm) = j
TextBox85.Text = szArray(1)
TextBox94.Text = szArray(2)
TextBox103.Text = szArray(3)
TextBox86.Text = szArray(4)
TextBox95.Text = szArray(5)
TextBox104.Text = szArray(6)
TextBox87.Text = szArray(7)
TextBox96.Text = szArray(8)
TextBox105.Text = szArray(9)
Debug.WriteLine(szArray(mmm))
Next

ne iideas?
regards
 
S

Supra

thank u, peter :)

Peter said:
Yes you can after you copy paste this fillRandom, there was a nice
little endless loop in my previous fill random:
for example if the left and right numbers were like this:
4 3
7 9
2 7
3 6
5 8
8 2
6 5
9 4
1

then it would try to add 1 as the last number to the right column but
that isn't allowed so an endless loop because all other numbers are
already added to the two array's

This is the new code, hth greetz Peter:

Private Sub fillRandom()
Dim left As New ArrayList
Dim right As New ArrayList
Dim blnOk As Boolean = False
Dim intGetal As Integer
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If left.IndexOf(intGetal) < 0 Then
left.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = CInt(Rnd() * 8) + 1
If right.IndexOf(intGetal) < 0 And intGetal <>
CInt(left(i)) Then
right.Add(intGetal)
blnOk = True
Else
If i < 8 Then
blnOk = False
Else
If intGetal = CInt(left(i)) Then
blnOk = True
i = -1
right.Clear()
End If
End If
End If
Loop
Next

For i As Integer = 0 To 8
textboxGrid(i, 0).Text = CStr(left(i))
textboxGrid(i, 1).Text = CStr(right(i))
Next

End Sub

--
Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe trying
to produce bigger and better idiots. So far, the Universe is winning.

"Supra" <[email protected] <mailto:[email protected]>>
schreef in bericht can i continue more clicking than stopping at 8 times?
 
S

Supra

i created Private textboxGrid(8, 8) As TextBox. but i can only go up
to 6 columns but no nore than 6. because if i do seven columns, the
textbox wouldn't dispalyed numbers and cliicking several button
again...limited to 2. and when i restarted again,,,,nothing displayed
and button is freezing. this one in below code is nothing dispalying and
clicking again...the button is freezing . any ideas u can give me me a
hints?

\\
\\
\\
For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal =cint(9 * rnd()+1)
If sixth_row.IndexOf(intGetal) < 0 And intGetal <>
CInt(left(i)) And intGetal <> CInt(right(i)) And intGetal <>
CInt(third_row(i)) And intGetal <> CInt(fourth_row(i)) _
And CInt(fifth_row(i)) Then
sixth_row.Add(intGetal)
blnOk = True
Else
blnOk = False
End If
Loop
Next


For i As Integer = 0 To 8
blnOk = False
Do While blnOk = False
intGetal = cint(9 * rnd()+1)
If seventh_row.IndexOf(intGetal) < 0 And intGetal <>
CInt(left(i)) And intGetal <> CInt(right(i)) And intGetal <>
CInt(third_row(i)) And intGetal <> CInt(fourth_row(i)) And intGetal <>
CInt(fifth_row(i)) _
And intGetal <> CInt(sixth_row(i)) Then
seventh_row.Add(intGetal)
blnOk = True
Else
If i < 8 Then
blnOk = False
Else
If intGetal = CInt(right(i)) And CInt(left(i))
And CInt(third_row(i)) And CInt(fourth_row(i)) _
And CInt(fifth_row(i)) And CInt(sixth_row(i)) Then
blnOk = True
i = -1
seventh_row.Clear()
End If
End If
End If
Loop
Next
\\
\\
\\
regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top