Link to home
Start Free TrialLog in
Avatar of boorna00
boorna00

asked on

Text Box that can change dynamically?

Did anyone see the movie War Games where the computer clicked through a bunch of characters before displaying it on the screen.  That is what I need to do with a pre-determinted 14 character output.  If anyone has any ideas please let me know.
Avatar of wsh2
wsh2

Never saw the movie.. please explain more.. <lol> and a <smile>.
you mean generate random letters and numbers before stopping on the correct one?
Try this...
Create a form, with a command button named command1, and a text box named text1 and copy this code to the form:

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Private Sub Command1_Click()
Dim i As Integer
Dim s(6) As String
s(0) = "a"
s(1) = "b"
s(2) = "c"
s(3) = "d"
s(4) = "e"
s(5) = "f"
For i = 0 To 5
    Text1.Text = s(i)
    DoEvents
    Sleep 500
Next i
End Sub

You can control the speed of the scrolling by increasing or decreasing the sleep value.
Ohhhhh.. Azra I think you got it !!!! Ok, here is a very simple example.. <smile>

1. Start a new Standard.Exe project.
2. Add 2 Labels to your form.. and name them Label1 and Label2.
3. Add 2 Timers to your form.. and name them Timer1 and Timer2.
4. Copy and Paste the following into the code window.

<----- Copy Begin ----->

Option Explicit
Private m_strChars As String
Private m_intCount As Integer
Private m_intLimit As Integer

Private Sub Form_Load()
   
   Label1.Caption = ""
   Label1.Move 10, 10, 1000, 1000
   Label1.FontSize = 40
   Label1.FontBold = True
   Label1.FontItalic = False
   
   Label2.Caption = ""
   Label2.Move 1000, 10, 1000, 1000
   Label2.FontSize = 40
   Label2.FontBold = True
   Label2.FontItalic = False
   
   Timer1.Interval = 50
   Timer1.Enabled = False
   Timer2.Interval = 50
   Timer2.Enabled = False
   
   m_strChars = "ABCDEFGHIJKLMNOPRRSTUVWXYZ"
   m_intCount = 0
   m_intLimit = 50
   Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

   If m_intCount > m_intLimit _
   Then
      Timer1.Enabled = False
      Label1.Caption = "H"
      Label1.FontItalic = True
      m_intCount = 0
      Timer2.Enabled = True
   Else
      m_intCount = m_intCount + 1
      Label1.Caption = Mid(m_strChars, _
         (Rnd * Len(m_strChars) + 1), _
         1)
   End If
   Label1.Refresh
   
End Sub
Private Sub Timer2_Timer()

   If m_intCount > m_intLimit _
   Then
      Timer2.Enabled = False
      Label2.Caption = "I"
      Label2.FontItalic = True
   Else
      m_intCount = m_intCount + 1
      Label2.Caption = Mid(m_strChars, _
         (Rnd * Len(m_strChars) + 1), _
         1)
   End If
   Label1.Refresh
   
End Sub

<----- Copy End ----->


Here's another:

Option Explicit

Private sString As String
Private sTmp As String
Private sBuild As String
Private lPos As Long

Private Sub Command1_Click()
    Text1.Text = ""
    Timer1.Enabled = True
End Sub

Private Sub Form_Load()
    Text1.Text = ""
    sString = "OneTwoThreeFour"
    lPos = 1
    Timer1.Enabled = False
    Timer1.Interval = 55
    Randomize
End Sub

Private Sub Timer1_Timer()
    If (Text1.Text = sString) Then
        Timer1.Enabled = False
        Exit Sub
    End If
    'Rnd range values
    Dim lUpper As Long, lLower As Long
    'String (character) to match
    Dim sSearch As String
    sSearch = Mid(sString, lPos, 1)
    'Restrict random search to range
    lUpper = Asc(sSearch) + 5
    lLower = Asc(sSearch) - 5
    'Pick a random char
    sTmp = Chr(Int((lUpper - lLower + 1) * Rnd + lLower))
    'Test for match
    If sSearch = sTmp Then
        lPos = lPos + 1
        sBuild = sBuild & sTmp
        Text1.Text = sBuild
    Else
        Text1.Text = sBuild & sTmp
    End If
End Sub
wsh2 I modified yours a bit to suit what I think boorna is looking for using one label and one timer:



Private m_strChars As String
Private m_intCount As Integer
Private m_intLimit As Integer
Private myString As String
Private currString As String
Private i As Integer



Private Sub Form_Load()
   myString = "STRING TO TYPE"
   
   Timer1.Interval = 50
   Timer1.Enabled = False
   
   m_strChars = "ABCDEFGHIJKLMNOPRRSTUVWXYZ "
   m_intCount = 0
   m_intLimit = 50
   Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

   If m_intCount > m_intLimit Then
      Label1.Caption = Left(myString, i)
      currString = Label1.Caption
      m_intCount = 0
      i = i + 1
   Else
      m_intCount = m_intCount + 1
      Label1.Caption = currString & Mid(m_strChars, _
         (Rnd * Len(m_strChars) + 1), _
         1)
   End If
   Label1.Refresh
   If Label1.Caption = myString Then Timer1.Enabled = False
End Sub


ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
We have enough code here we can make a sequel to that movie now  =)
Let's start? :-)
I hope they haven't copyright for this "Password generating" method.
BTW, about code, I forgot to remove this string:
i = Rnd * 14 + 1
First time I tried to set correct letters randomly, but, IMHO, from beginning to end is better
Cheers
Avatar of boorna00

ASKER

Thank you everyone for you help.  Ark's answer is the one that worked out the best.