-----------------------------------------------------------------------------------------------
y00010000000000 Call ESS_VB6_Begin(VB.Form, frmGuess)
-----------------------------------------------------------------------------------------------
c00010500jbz350 Private bolESS_Focus_MainForm = False As Boolean
s99990001jbz350 Private Sub MainForm_FocusChanged (HasFocus As Boolean)
s99990001jbz355     bolESS_Focus_MainForm = HasFocus
s99990001jbz360 End Sub
-----------------------------------------------------------------------------------------------
y00020000000000 Call ESS_VB6_Begin(VB.CommandButton, cmdGuess)
-----------------------------------------------------------------------------------------------
c00020500jbz350 Private bolESS_Focus_cmdGuess = False As Boolean
c00020000jbz350 Public cmdGuess As Button
s99990002jbz350 Private Sub cmdGuess_FocusChanged (HasFocus As Boolean)
s99990002jbz355     bolESS_Focus_cmdGuess = HasFocus
s99990002jbz360 End Sub
-----------------------------------------------------------------------------------------------
y00030000000000 Call ESS_VB6_Begin(VB.TextBox, txtNumber)
-----------------------------------------------------------------------------------------------
c00030500jbz350 Private bolESS_Focus_txtNumber = False As Boolean
c00030000jbz350 Public txtNumber As TextField
s99990003jbz350 Private Sub txtNumber_FocusChanged (HasFocus As Boolean)
s99990003jbz355     bolESS_Focus_txtNumber = HasFocus
s99990003jbz360 End Sub
-----------------------------------------------------------------------------------------------
y00040000000000 Call ESS_VB6_Begin(VB.Label, lblMsg)
-----------------------------------------------------------------------------------------------
c00040500jbz350 Private bolESS_Focus_lblMsg = False As Boolean
c00040000jbz350 Public lblMsg As Label
s99990004jbz350 Private Sub lblMsg_FocusChanged (HasFocus As Boolean)
s99990004jbz355     bolESS_Focus_lblMsg = HasFocus
s99990004jbz360 End Sub
-----------------------------------------------------------------------------------------------
y00050000000000 Public Const ESS_VB6_Att_VB_Exposed = False
-----------------------------------------------------------------------------------------------
c00050000jbz350 Public Const ESS_VB6_Att_VB_Exposed = False
-----------------------------------------------------------------------------------------------
y00060000000000 Public Const ESS_VB6_Att_VB_Name = "frmGuess"
-----------------------------------------------------------------------------------------------
c00060000jbz350 Public Const ESS_VB6_Att_VB_Name = "MainForm"
-----------------------------------------------------------------------------------------------
y00070000000000 ESS_PublicX gintChosen As Integer
-----------------------------------------------------------------------------------------------
c00070000jbz350 Public gintChosen = 0 As Short
-----------------------------------------------------------------------------------------------
y00080000000000 ESS_PublicX ESS_Vb6_frmMain As String
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
y00090000000000 ESS_PublicX ESS_Vb6_frmLayout As String
-----------------------------------------------------------------------------------------------
c00090000jbz350 Public ESS_Vb6_frmLayout As String
-----------------------------------------------------------------------------------------------
y00100000000000 Sub Main()
-----------------------------------------------------------------------------------------------
b00000104jbz010     #Region Project Attributes
b00000104jbz011         #MainFormWidth: 600
b00000104jbz012         #MainFormHeight: 600
b00000104jbz013     #End Region
b00000104jbz014     
b00000104jbz015     Sub Process_Globals
b00000104jbz016         Private fx As JFX
b00000104jbz017         Private MainForm As Form
b00000104jbz018         Private xui As XUI
e00000109jbz010     End Sub
e00000309jbz010     Sub AppStart (Form1 As Form, Args() As String)
e00000309jbz011         MainForm = Form1
e00000311jbz010         MainForm.RootPane.LoadLayout("Layout1")
e00000311jbz011         MainForm.Show
e00000311jbz012         gvh.AddKeyListener("gvh", MainForm)
d00000202jbz010         Private gvh As GameViewHelper
f00000005jbz010     End Sub
s00000000jbz350     Private Sub gvh_KeyPressed (KeyCode As String) As Boolean
s00000000jbz351         Public Shift = 0 As Short
s00000000jbz352         ESS_VB6_Key_Release = 0
s00000000jbz353         
s99990000jbz350         If ESS_VB6_Key_Release = 0 Or ESS_VB6_Key_Release = 1 Then
s99990000jbz351             Return True
s99990000jbz352         Else
s99990000jbz353             Return False
s99990000jbz354         End If
s99990000jbz355     End Sub
-----------------------------------------------------------------------------------------------
y00110000000000     Randomize ' Initialize random-number generator.
-----------------------------------------------------------------------------------------------
e00110002jbz350     ESS_VB6_RandomizeNoParm
-----------------------------------------------------------------------------------------------
y00120000000000     gintChosen = Int((100 - 1 + 1) * Rnd + 1)
-----------------------------------------------------------------------------------------------
t00120060jbz010     Sub ESS_VB6_Int(x As Double) As Long
t00120060jbz011         '*********************************************************************************
t00120060jbz012         ' VB6 *
t00120060jbz013         ' Returns the integer portion of a number. The required number argument is a *
t00120060jbz014         ' Double or any valid numeric expression. If number contains Null, Null is *
t00120060jbz015         ' returned. *
t00120060jbz016         ' Remove the fractional part of number and return the resulting integer value. *
t00120060jbz017         ' If number is negative, Int returns the first negative integer less than or *
t00120060jbz018         ' equal to number. For example, Int converts -8.4 to -9. *
t00120060jbz019         '*********************************************************************************
t00120060jbz020         If x >= 0 Then
t00120060jbz021             Return Floor(x)
t00120060jbz022         Else
t00120060jbz023             Return Ceil(x)
t00120060jbz024         End If
t00120060jbz025     End Sub
d00120200jbz010     Public ESS_VB6_Rnd_Prv = -1 As Float
d00120200jbz011     Public ESS_VB6_Rnd_Same = -1 As Float
d00120200jbz012     Public ESS_VB6_Rnd_Seed = -1 As Float
d00120200jbz013     Public ESS_VB6_Rnd_Switch = FALSE As Boolean
t00120126jbz010     Sub ESS_VB6_Rnd(v As Float) As Float
t00120126jbz011         
t00120126jbz012         Dim dRnd As Double 'holds the random number (kinda)
t00120126jbz013         Dim sX As String 'work variable
t00120126jbz014         
t00120126jbz015         '*********************************************************************************
t00120126jbz016         '
t00120126jbz017         'VB6 If Number is Rnd generates
t00120126jbz018         ' Less than zero The same number every time, using Number as the seed.*
t00120126jbz019         ' Greater than zero The next number in the pseudo-random sequence.
t00120126jbz020         ' Equal to zero The most recently generated number.
t00120126jbz021         ' Not supplied The next number in the pseudo-random sequence.
t00120126jbz022         '
t00120126jbz023         'VB6 - If Randomize is not used, theRnd function (with no arguments)
t00120126jbz024         ' uses the same number as a seed the first time it is called,
t00120126jbz025         ' and thereafter uses the last generated number as a seed value.
t00120126jbz026         '*********************************************************************************
t00120126jbz027         
t00120126jbz028         '*********************************************************************************
t00120126jbz029         ' if no seed has been set, set one *
t00120126jbz030         '*********************************************************************************
t00120126jbz031         If ESS_VB6_Rnd_Switch = False Then
t00120126jbz032             ESS_VB6_RandomizeNoParm
t00120126jbz033         End If
t00120126jbz034         
t00120126jbz035         '*********************************************************************************
t00120126jbz036         ' compute the "next" random number based on "a" seed *
t00120126jbz037         '*********************************************************************************
t00120126jbz038         dRnd = 1
t00120126jbz039         Do While dRnd = 1
t00120126jbz040             'dRnd = Rnd(0, 999999999) / 1000000000 'number between 0 and 1 .789123456
t00120126jbz041             dRnd = Rnd(-32767, 32767)
t00120126jbz042             dRnd = dRnd + 32767
t00120126jbz043             dRnd = dRnd / 100000
t00120126jbz044             If dRnd < 0 Or dRnd >= 1 Then
t00120126jbz045                 dRnd = 1
t00120126jbz046             Else
t00120126jbz047                 dRnd = (ESS_VB6_Rnd_Seed * 100000) * dRnd '45982.2237811 = (.5827 * 100000) * .789123456)
t00120126jbz048                 sX = MoveDecimalToFront(dRnd) '.459822237811
t00120126jbz049                 dRnd = sX '.459822237811
t00120126jbz050             End If
t00120126jbz051         Loop
t00120126jbz052         
t00120126jbz053         '*********************************************************************************
t00120126jbz054         ' if "the same" random number hasn't been set, set it *
t00120126jbz055         '*********************************************************************************
t00120126jbz056         If ESS_VB6_Rnd_Same < 0 Then
t00120126jbz057             ESS_VB6_Rnd_Same = dRnd
t00120126jbz058         End If
t00120126jbz059         
t00120126jbz060         '*********************************************************************************
t00120126jbz061         ' if "the previous" random number hasn't been set, set it *
t00120126jbz062         '*********************************************************************************
t00120126jbz063         If ESS_VB6_Rnd_Prv < 0 Then
t00120126jbz064             ESS_VB6_Rnd_Prv = dRnd
t00120126jbz065         End If
t00120126jbz066         
t00120126jbz067         '*********************************************************************************
t00120126jbz068         ' if the caller wants the same random number, send it *
t00120126jbz069         '*********************************************************************************
t00120126jbz070         If v < 0 Then
t00120126jbz071             dRnd = ESS_VB6_Rnd_Same
t00120126jbz072         End If
t00120126jbz073         
t00120126jbz074         '*********************************************************************************
t00120126jbz075         ' if the caller wants the previous random number, send it *
t00120126jbz076         '*********************************************************************************
t00120126jbz077         If v = 0 Then
t00120126jbz078             dRnd = ESS_VB6_Rnd_Prv
t00120126jbz079         End If
t00120126jbz080         
t00120126jbz081         '*********************************************************************************
t00120126jbz082         ' if the caller wants the next number in the pseudo-random sequence, send it *
t00120126jbz083         '*********************************************************************************
t00120126jbz084         
t00120126jbz085         
t00120126jbz086         '*********************************************************************************
t00120126jbz087         ' remember the "current" random number *
t00120126jbz088         '*********************************************************************************
t00120126jbz089         ESS_VB6_Rnd_Prv = dRnd
t00120126jbz090         
t00120126jbz091         '*********************************************************************************
t00120126jbz092         ' return the random number *
t00120126jbz093         '*********************************************************************************
t00120126jbz094         Return dRnd
t00120126jbz095         
t00120126jbz096     End Sub
t00120128jbz010     
t00120128jbz011     Sub MoveDecimalToFront(num As Double) As String
t00120128jbz012         Dim numStr As String
t00120128jbz013         Dim intPart As String
t00120128jbz014         Dim decPart As String
t00120128jbz015         Dim decimalPos As Int
t00120128jbz016         Private retStr As String
t00120128jbz017         
t00120128jbz018         ' Convert the number to a string
t00120128jbz019         numStr = num
t00120128jbz020         
t00120128jbz021         ' Find the position of the decimal point
t00120128jbz022         decimalPos = numStr.IndexOf(".") + 1
t00120128jbz023         
t00120128jbz024         If decimalPos > 0 Then
t00120128jbz025             ' If there is a decimal point, split the number into integer and decimal parts
t00120128jbz026             intPart = ESS_VB6_Left(numStr, decimalPos - 1)
t00120128jbz027             decPart = ESS_VB6_Mid2(numStr, decimalPos + 1)
t00120128jbz028         Else
t00120128jbz029             ' If there is no decimal point, treat the entire number as the integer part
t00120128jbz030             intPart = numStr
t00120128jbz031             decPart = ""
t00120128jbz032         End If
t00120128jbz033         
t00120128jbz034         ' Combine the parts to move the decimal point to the front
t00120128jbz035         If decPart <> "" Then
t00120128jbz036             retStr = "0." & intPart & decPart
t00120128jbz037         Else
t00120128jbz038             retStr = "0." & intPart
t00120128jbz039         End If
t00120128jbz040         
t00120128jbz041         Return retStr
t00120128jbz042     End Sub
t00170100jbz010             Sub ESS_VB6_Mid2(theStr As String, startPos As Int) As String
t00170100jbz011                 '*********************************************************************************
t00170100jbz012                 ' VB6 *
t00170100jbz013                 'length is an optional parameter to mthe Mid function *
t00170100jbz014                 '*********************************************************************************
t00170100jbz015                 Private retStr As String 'holds the returned value
t00170100jbz016                 retStr = ESS_VB6_Mid3(theStr, startPos, -1)
t00170100jbz017                 Return retStr
t00170100jbz018             End Sub
t00170102jbz010             
t00170102jbz011             Sub ESS_VB6_Mid3(theStr As String, startPos As Int, theLength As Int) As String
t00170102jbz012                 '*********************************************************************************
t00170102jbz013                 ' VB6 *
t00170102jbz014                 ' string Required. String expression from which characters are returned. If *
t00170102jbz015                 ' string contains Null, Null is returned. *
t00170102jbz016                 ' start Required; Long. Character position in string at which the part to be *
t00170102jbz017                 ' taken begins. If start is greater than the number of characters *
t00170102jbz018                 ' in string, Mid returns a zero-length string (""). *
t00170102jbz019                 'length Optional; Variant (Long). Number of characters to return. If omitted *
t00170102jbz020                 ' or if there are fewer than length characters in the text *
t00170102jbz021                 ' (including the character at start), all characters from the *
t00170102jbz022                 ' start position to the end of the string are returned. *
t00170102jbz023                 '*********************************************************************************
t00170102jbz024                 '*********************************************************************************
t00170102jbz025                 ' V4X *
t00170102jbz026                 ' Substring(BeginIndex) Returns a new string which is a substring of the *
t00170102jbz027                 ' original string. The new string will include the character at *
t00170102jbz028                 ' BeginIndex and will extend to the end of the string. *
t00170102jbz029                 ' Substring2(BeginIndex, EndIndex) Returns a new string which is a substring of *
t00170102jbz030                 ' the original string. The new string will include the character at *
t00170102jbz031                 ' BeginIndex and will extend to the character at EndIndex, not *
t00170102jbz032                 ' including the last character. Note that EndIndex is the end index *
t00170102jbz033                 ' and not the length like in other languages. *
t00170102jbz034                 '*********************************************************************************
t00170102jbz035                 Private endPos As Int 'holds computed end index
t00170102jbz036                 Private begPos As Int 'holds computed begin index
t00170102jbz037                 If theStr = Null Then
t00170102jbz038                     Return Null
t00170102jbz039                 End If
t00170102jbz040                 If theLength = -1 Then
t00170102jbz041                     theLength = theStr.Length
t00170102jbz042                 End If
t00170102jbz043                 begPos = startPos - 1
t00170102jbz044                 If begPos > (theStr.Length - 1) Then
t00170102jbz045                     Return ""
t00170102jbz046                 End If
t00170102jbz047                 If theLength = 0 Then
t00170102jbz048                     Return ""
t00170102jbz049                 End If
t00170102jbz050                 endPos = begPos + theLength - 1
t00170102jbz051                 If endPos > (theStr.Length - 1) Then
t00170102jbz052                     endPos = begPos + theStr.Length - 1
t00170102jbz053                 End If
t00170102jbz054                 Return theStr.Substring2(begPos, endPos)
t00170102jbz055             End Sub
p00170070jbz350             decimalPos + 1 = ESS_VB6_Mid3 (ALen(3, 3))
e00120070jbz350     gintChosen = ESS_VB6_Int((100 - 1 + 1) * (ESS_VB6_Rnd(1)) + 1)
-----------------------------------------------------------------------------------------------
y00130000000000     Debug.Print gintChosen
-----------------------------------------------------------------------------------------------
e00130004jbz350     Log(gintChosen)
-----------------------------------------------------------------------------------------------
y00140000000000     frmMain.Show
-----------------------------------------------------------------------------------------------
e00140070jbz354     'FRMMAIN.Show
-----------------------------------------------------------------------------------------------
y00150000000000 End Sub
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
y00160000000000 Private Sub txtNumber_KeyDown(KeyCode As Integer, Shift As Integer)
-----------------------------------------------------------------------------------------------
s00160010jbz355     If bolEss_Focus_TXTNUMBER = True Then
p00162002jbz010         Private Sub txtNumber_KeyDown ( KeyCode As String , Shift As Short )
-----------------------------------------------------------------------------------------------
y00180000000000             If KeyCode = vbKeyReturn Then
-----------------------------------------------------------------------------------------------
p00180000jbz350                 If KeyCode = "Enter" Then
-----------------------------------------------------------------------------------------------
y00190000000000                     KeyCode = 0
-----------------------------------------------------------------------------------------------
p00190070jbz350                     ' KeyCode = 0
p00190070jbz355                     ESS_VB6_Key_Release = 1
c00190070jbz360                     Public ESS_VB6_Key_Release = 0 As Short
-----------------------------------------------------------------------------------------------
y00200000000000                     Call cmdGuess_Click
-----------------------------------------------------------------------------------------------
p00200070jbz350                     cmdGuess_Click
-----------------------------------------------------------------------------------------------
y00210000000000                 End If
-----------------------------------------------------------------------------------------------
p00210000jbz350             End If
-----------------------------------------------------------------------------------------------
y00220000000000         End Sub
-----------------------------------------------------------------------------------------------
s00220090jbz015     End If
s00220090jbz013     txtNumber_KeyDown(KeyCode , Shift )
p00229802jbz360 End Sub
-----------------------------------------------------------------------------------------------
y00230000000000 Private Sub cmdGuess_Click()
-----------------------------------------------------------------------------------------------
p00232003jbz010     Private Sub cmdGuess_Click ( )
-----------------------------------------------------------------------------------------------
y00240000000000         ESS_DimX intTheGuess As Integer 'holds the user's guess
-----------------------------------------------------------------------------------------------
c00240003jbz350         Private intTheGuess = 0 As Short
-----------------------------------------------------------------------------------------------
y00250000000000         If IsNumeric(txtNumber.Text) = True Then
-----------------------------------------------------------------------------------------------
p00250000jbz350             If IsNumber(txtNumber.TEXT) = True Then
-----------------------------------------------------------------------------------------------
y00260000000000                 intTheGuess = txtNumber.Text
-----------------------------------------------------------------------------------------------
p00260070jbz350                 intTheGuess = txtNumber.TEXT
-----------------------------------------------------------------------------------------------
y00270000000000                 If intTheGuess > gintChosen Then
-----------------------------------------------------------------------------------------------
p00270000jbz350                     If intTheGuess > gintChosen Then
-----------------------------------------------------------------------------------------------
y00280000000000                         lblMsg.Caption = "my number is lower than " & Trim(Str(intTheGuess))
-----------------------------------------------------------------------------------------------
t00280020jbz010                         Sub ESS_VB6_Trim(sExp As String) As String
t00280020jbz011                             '*********************************************************************************
t00280020jbz012                             ' VB6 *
t00280020jbz013                             ' Returns a Variant (String) containing a copy of a specified string without *
t00280020jbz014                             ' leading and trailing spaces *
t00280020jbz015                             ' required string is any valid string expression. If string contains Null, *
t00280020jbz016                             ' Null is returned. *
t00280020jbz017                             '*********************************************************************************
t00280020jbz018                             Private sX = "" As String 'work variable
t00280020jbz019                             If sExp = Null then
t00280020jbz020                                 sX = Null
t00280020jbz021                             Else
t00280020jbz022                                 sX = sExp.Trim
t00280020jbz023                             End if
t00280020jbz024                             Return sX
t00280020jbz025                         End Sub
t00280040jbz010                         Sub ESS_VB6_Str(sExp As Double) As String
t00280040jbz011                             '*********************************************************************************
t00280040jbz012                             ' VB6 *
t00280040jbz013                             ' converts a number to a string *
t00280040jbz014                             '*********************************************************************************
t00280040jbz015                             Private sX = "" As String
t00280040jbz016                             sX = sExp
t00280040jbz017                             If sExp > 0 Then
t00280040jbz018                                 sX = " " & sX
t00280040jbz019                             End If
t00280040jbz020                             Return sX
t00280040jbz021                         End Sub
p00280070jbz350                         lblMsg.Text = "my number is lower than " & ESS_VB6_Trim(ESS_VB6_Str(intTheGuess))
-----------------------------------------------------------------------------------------------
y00290000000000                     ElseIf intTheGuess < gintChosen Then
-----------------------------------------------------------------------------------------------
p00290000jbz350                     Else If intTheGuess < gintChosen Then
-----------------------------------------------------------------------------------------------
y00300000000000                         lblMsg.Caption = "my number is higher than " & Trim(Str(intTheGuess))
-----------------------------------------------------------------------------------------------
p00300070jbz350                         lblMsg.Text = "my number is higher than " & ESS_VB6_Trim(ESS_VB6_Str(intTheGuess))
-----------------------------------------------------------------------------------------------
y00310000000000                     Else
-----------------------------------------------------------------------------------------------
p00310000jbz350                     Else
-----------------------------------------------------------------------------------------------
y00320000000000                         lblMsg.Caption = "(" & Trim(Str(intTheGuess)) & ") Well Done!!!"
-----------------------------------------------------------------------------------------------
p00320070jbz350                         lblMsg.Text = "(" & ESS_VB6_Trim(ESS_VB6_Str(intTheGuess)) & ") Well Done!!!"
-----------------------------------------------------------------------------------------------
y00330000000000                     End If
-----------------------------------------------------------------------------------------------
p00330000jbz350                 End If
-----------------------------------------------------------------------------------------------
y00340000000000             Else
-----------------------------------------------------------------------------------------------
p00340000jbz350             Else
-----------------------------------------------------------------------------------------------
y00350000000000                 lblMsg.Caption = "Please enter a number between 1 and 100"
-----------------------------------------------------------------------------------------------
p00350070jbz350                 lblMsg.Text = "Please enter a number between 1 and 100"
-----------------------------------------------------------------------------------------------
y00360000000000             End If
-----------------------------------------------------------------------------------------------
p00360000jbz350         End If
-----------------------------------------------------------------------------------------------
y00370000000000         txtNumber.Text = ""
-----------------------------------------------------------------------------------------------
p00370070jbz350         txtNumber.TEXT = ""
-----------------------------------------------------------------------------------------------
y00380000000000         txtNumber.SetFocus
-----------------------------------------------------------------------------------------------
p00380070jbz350         TXTNUMBER.SelectAll
p00380070jbz355         TXTNUMBER.RequestFocus
-----------------------------------------------------------------------------------------------
y00390000000000     End Sub
-----------------------------------------------------------------------------------------------
p00399803jbz360 End Sub
