Solved

Text Box that can change dynamically?

Posted on 2000-03-31
10
136 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:boorna00
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
Never saw the movie.. please explain more.. <lol> and a <smile>.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
you mean generate random letters and numbers before stopping on the correct one?
0
 
LVL 3

Expert Comment

by:jjmartin
Comment Utility
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.
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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 ----->


0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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


0
 
LVL 27

Accepted Solution

by:
Ark earned 100 total points
Comment Utility
Hi
May I take part at this to? Like wsh2, I've never seen this movie, but saw many other with "password generations". IMHO, in Hollywood they would make something like this:
'AzraSound - sorry, I was so lazy to declare variables that I got yours

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, n As Integer

Private Sub Form_Load()
   myString = "StRiNg TO tYpE"
   Label1.Font.Size = 18
   Label1.Font.Bold = True
   Timer1.Interval = 50
   Timer1.Enabled = False
     
   m_strChars = "1234567890abcdefghijklmnoprqstuvwxyzABCDEFGHIJKLMNOPRRSTUVWXYZ "
   m_intCount = 0
   m_intLimit = 50
   Timer1.Enabled = True
   currString = String$(14, " ")
   Label1.Caption = currString
End Sub

Private Sub Timer1_Timer()
   If m_intCount > m_intLimit Then
      n = n + 1
      i = Rnd * 14 + 1
      Mid$(currString, n, 1) = Mid$(myString, n, 1)
      m_intCount = 0
   Else
      m_intCount = m_intCount + 1
      For i = n + 1 To 14
          Mid$(currString, i) = Mid(m_strChars, (Rnd * Len(m_strChars) + 1), 1)
      Next i
   End If
   Label1 = currString
   If Label1.Caption = myString Then Timer1.Enabled = False
End Sub

' If you need, you can change Label with Text

Cheers
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
We have enough code here we can make a sequel to that movie now  =)
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
0
 

Author Comment

by:boorna00
Comment Utility
Thank you everyone for you help.  Ark's answer is the one that worked out the best.

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now