Page 1 of 1

Lotto Program

Posted: Fri Apr 29, 2011 10:21 am
by cvirus
Hello, How can i improve this little program?

I need that the numbers don?t repeat themselves.
[code]
dim ran as integer, num1 as integer, num2 as integer, num3 as integer, num4 as integer
dim ran1 as integer, num5 as integer, num6 as integer
dim a as string, nums1 as string, nums2 as string, nums3 as string, nums4 as string
dim b as string, nums5 as string, nums6 as string

object img as bitmap
loadfromfile(DIR$("@")+"eur.bmp")
end object

Object form1 as form
width=400
height=250
onpaint=frmpaint
caption="EuroMilh?es"

object editbox as edit
left=30
top=20
width=50
end object

object editbox1 as edit
left=90
top=20
width=50
end object

object editbox2 as edit
left=150
top=20
width=50
end object

object editbox3 as edit
left=210
top=20
width=50
end object

object editbox4 as edit
left=280
top=20
width=50
end object

object editbox5 as edit
left=120
top=80
width=50
end object

object editbox6 as edit
left=190
top=80
width=50
end object

object btn as button
left=80
top=170
width=80
caption="Gerar N?meros"
onclick=numeros
end object

object btn1 as button
left=200
top=170
width=80
caption="Gerar Estrelas"
onclick=estrelas
end object

end object

form1.showmodal

sub numeros(s as button)
num1=RND(50)+1
nums1=str$(num1)
editbox.text=nums1

num2=RND(50)+1
nums2=str$(num2)
editbox1.text=nums2

num3=RND(50)+1
nums3=str$(num3)
editbox2.text=nums3

num4=RND(50)+1
nums4=str$(num4)
editbox2.text=nums4


num5=RND(50)+1
nums5=str$(num5)
editbox3.text=nums5


num6=RND(50)+1
nums6=str$(num6)
editbox4.text=nums6
END SUB

sub estrelas(s as button)


ran=RND(9)+1
a=str$(ran)


ran1=RND(9)+1
b=str$(ran1)

editbox5.text=a
editbox6.text=b

end sub

sub frmpaint(s as form)
s.canvas.draw(0,0,img)
end sub


[/code]

Lotto Program

Posted: Fri May 06, 2011 7:02 pm
by fred
Make something that checks the number, something like this:

Do
  number1 = Random
Loop until (number <> number2) and (number <> number3) 4,5,6 etc.

Do
  number2 = Random
Loop until (number <> number1) and (number <> number3) 4,5,6 etc.

I don`t want to spoil your programming fun so you can try it yourself :)
If needed i can help.

Lotto Program

Posted: Sun May 08, 2011 7:02 pm
by cvirus
Thank you Fred, i?ll try it out. ::)

Lotto Program

Posted: Tue May 10, 2011 7:10 pm
by fred
You don`t have to check numbers that are not made yet so something like this:

number1 = Random

Do
  number2 = Random
Loop until (number <> number1)

Do
  number3 = Random
Loop until (number <> number1) and (number <> number2)

Do
  number4 = Random
Loop until (number <> number1) and (number <> number2)  and (number <> number3)

Do
  number5 = Random
Loop until (number <> number1) and (number <> number2)  and (number <> number3) and (number <> number4)

Do
  number6 = Random
Loop until (number <> number1) and (number <> number2)  and (number <> number3) and (number <> number4) and (number <> number5)

Lotto Program

Posted: Fri Jun 03, 2011 6:40 pm
by cvirus
Hello Fred and thak you for the help.

Needs improvement

here is the code

dim ran as integer, num1 as integer, num2 as integer, num3 as integer, num4 as integer
dim ran1 as integer, num5 as integer, num6 as integer
dim a as string, nums1 as string, nums2 as string, nums3 as string, nums4 as string
dim b as string, nums5 as string, nums6 as string



object img as bitmap
loadfromfile(DIR$("@")+"eur.bmp")
end object



Object form1 as form
width=400
height=250
onpaint=frmpaint
caption="EuroMilh?es"


object editbox as edit
left=30
top=20
width=50
end object

object editbox1 as edit
left=90
top=20
width=50
end object

object editbox2 as edit
left=150
top=20
width=50
end object

object editbox3 as edit
left=210
top=20
width=50
end object

object editbox4 as edit
left=280
top=20
width=50
end object

object editbox5 as edit
left=120
top=80
width=50
end object

object editbox6 as edit
left=190
top=80
width=50
end object

object btn as button
left=80
top=170
width=80
caption="Gerar N?meros"
onclick=numeros
end object

object btn1 as button
left=200
top=170
width=80
caption="Gerar Estrelas"
onclick=estrelas
end object

end object

form1.showmodal


sub numeros(s as button)


num1=RND(50)+1
nums1=str$(num1)

do
num2=RND(50)+1
loop until (num2<>num1)
nums2=str$(num2)

do
num3=RND(50)+1
loop until (num3<>num2) and (num3<>num1)
nums3=str$(num3)

do
num4=RND(50)+1
loop until (num3<>num4) and (num4<> num2) and (num4<>num1)
nums4=str$(num4)


do
num5=RND(50)+1
loop until (num4<>num5) and (num5<>num3) and (num5<>num2) and (num5<>num1)
nums5=str$(num5)


do
num6=RND(50)+1
loop until (num5<>num6) and (num6<>num4) and (num6<>num3) and (num6<>num2) and (num6<>num1)
nums6=str$(num6)


` to the screen

editbox.text=nums1
editbox1.text=nums2
editbox2.text=nums3
editbox2.text=nums4
editbox3.text=nums5
editbox4.text=nums6
END SUB

sub estrelas(s as button)


ran=RND(9)+1
a=str$(ran)

do
ran1=RND(9)+1
loop until (ran1<>ran)
b=str$(ran1)

editbox5.text=a
editbox6.text=b

end sub