Home > Software engineering >  VB to guess the number of games
VB to guess the number of games

Time:09-20




Want to make a guess the number game
Originally want to guess wrong show big or guess after a number of small, after three times circulation again told the end of the game, rather than guess wrong should be told that after a game
Please everyone a great god busy busy help look at what went wrong?

CodePudding user response:

All pictures, want to change is not copied,

You put the timers to become public variables, rather than on the process, at the end of the guess the number, to reset it,

CodePudding user response:

 Private Sub Command3_Click () 
Dim I, m, a, b, times As Integer
A=Text1. Text 'acquisition system generated random number and is assigned to variable a
B=Text2. Text 'the user input values assigned to variables b
Times=1
For m=1 To 17
Print the
Next m

The Do While times & lt;=3
If b=a Then
Print "congratulations, you guessed it! Guess the number for "& amp; A. & amp; "Congratulations you get a chance to draw!"
Command5, Visible=True
Command2. Visible=True
Command4. Visible=True
The Exit Do
ElseIf b & gt; Then a
Text2. Text=""
Text2. SetFocus
Print b & amp; "Guess big, change small points, try again!"


ElseIf b & lt; Then a
Text2. Text=""
Text2. SetFocus
Print b & amp; "Guess, change bigger, try again!"

End the If
Times=times + 1
Loop

If times & gt; 3 Then
I=MsgBox (" guess the number of failure, game over!" & VbCrLf & amp; "The right answer as" & amp; A. & amp; ! "" You can click on display random button ")
Print "guess the number of failed, game over!"
Print "the right answer as" & amp; A
End the If
End Sub

CodePudding user response:

1. Numerical range is 1 to 20, only give three times the opportunity is not reasonable, in theory is the need for up to five times the opportunity,
2 ^ (if there was just enough k is greater than your maximum random number, then in theory the most need to k times opportunity)

2. You For m=1 to 17 "wrap" to adjust the output position, is not reasonable, low efficiency, and will be affected by "theme Settings" system,
, accurate and efficient method is to use an Me. CurrentY=XXXXX the For loop, instead of you
According to your current Windows interface, if you do not change the "unit of measure" window, then the XXXXX=3000 May be with you For loop similar results,
You can adjust the size of the values, see the effect,

3. The variable defined statement written is not correct, need one by one for each variable in VB6 specified type, or variable types will be is the Variant types,

These three has nothing to do with your "results", just want to say with you some of the "basics",
You problem is not difficult, you think carefully, tracking the implementation process, where you can find the problem,

CodePudding user response:

 Option Explicit 
Dim times As Integer

Private Sub Command1_Click ()
Text1=""
Randomize
Text1. Tag=Int (Rnd () * 20) + 1
Times=0
Text2=""
Text2. SetFocus
End Sub

Private Sub Command3_Click ()
As Integer Dim a, b As Integer
A=Text1. The Tag
B=Text2. Text

If b=a Then
Text1=a
MsgBox "congratulations, you guessed it!"
The Exit Sub
End the If

Times=times + 1

If times & gt; 5 Then=
MsgBox (" guess the number of failure, game over!" )
Times=0
Text1=a
The Exit Sub
ElseIf b & gt; Then a
MsgBox "guess big, small points, try again!"
The Else
MsgBox "guess small to larger, try again!"
End the If
Text2. SetFocus
Text2. SelStart=0
Text2. SelLength=Len (Text2)
End Sub

Private Sub Form_Load ()
Text1=""
Text2=""
Begin the game End Sub
Command1 is (to generate a random number); Command3 is submit input number,

CodePudding user response:

Guess the number of policy issues,

A, the rule of thirds
This is the most direct association based on the third floor 1, will choose the right locations in the area of the position, gradually narrow the scope, to guess the number within 20, the rule of thirds can guess up to 5 times,
 
1, 10, 5, 3, 2, 1
2, 10, 5, 3, 2
3 10, 5, 3
4 to 10, 5, 3, 4
5, 10, 5
June 10, 5, 8, 7, 6
7, 10, 5, 8, 7
8 to 10, 5, 8
9, 10, 5, 8, 9
10 10
November 10, 15, 13, 12, 11
12, 10, 15, 13, 12
13 10, 15, 13
10 of 14, 15, 13, 14
15, 10, 15
16 10, 15, 18, 17, 16
17 10, 15, 18, 17
18 10, 15, 18
19 10, 15, 18, 19
20, 10, 15, 18, 19, 20
3.7 times on average,

2, 0.618 method (golden)
This is often used for large parameter selection experiment of a kind of optimum seeking method, selection is the unknown area is located at 0.618 points, however, for less than 20 guess the number, it is no advantage,
 1, 12, 6, 4, 2, 1 
2 12, 6, 4, 2
3 12, 6, 4, 2, 3
4, 12, 6, 4
May 12, 6, 4, 5
6, 12
July 12, 6, 9, 8, 7
August 12, 6, 9, 8
September 12, 6, 9
10, 12, 6, 9, 11, 10
11, 12, 6, 9, 11
12 12
13 12, 17, 15, 14, 13
14, 12, 17, 15, 14
15, 12, 17, 15
12 of 16, 17, 15, 16
17 12, 17
12, 17, 19, 18
19 12, 17, 19
20, 12, 17, 19, 20
is an average of 3.7 times,

CodePudding user response:

reference 5 floor of123 reply:
guess the number of strategies,

A, the rule of thirds
This is the most direct association based on the third floor 1, will choose the right locations in the area of the position, gradually narrow the scope, to guess the number within 20, the rule of thirds can guess up to 5 times,
 
.......
3.7 times on average,

2, 0.618 method (golden)
This is often used for large parameter selection experiment of a kind of optimum seeking method, selection is the unknown area is located at 0.618 points, however, to guess the number within 20, it has no advantage,
 
.......
is an average of 3.7 times,


I am a "to" the rule of thirds, you did not guess wrong,
However, these two methods of "advantage", you made a mistake?
Don't you put a sound method name on the "tall", it is the best method?
I wrote a piece of code to test, really is in "1 to 20," the results of two methods,
Dichotomy is obvious, but the larger the after prevailed,


Ok, I admit it: maybe my "gold separation method" of the code is not correct, so the result is "reverse",
When I followed the "1 to 20" process of gold separation method is less than 12 when the "sequence" really is not the same as you, more than 12 series is the same,
"Dichotomy" code, as you know, so I don't have to stick out,
So, could you hold your "gold separation method" guess the number of code posted look, okay?

My "test method" is like this:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related