hidden letters in text box

S

Shakeel Ahmad

i have a form with two text boxes and two command buttons.....

txtquestion
txtanswer
cmdOK
cmdHide

In the txtquestion there should be a function that when some one will write
in it..,, after every space it should hide the first letter...and should
start typing from the second letter again after the space first letter
should remain hidden.....

and oncliking the cmdOK it should show all the hidden letters as a word in
the second textbox....

but it should start hiding these letters after clicking the cmdhide button,
otherwise it should show all the letters...

one of the main function for this form:

the cmdHide button should not be appeard on the form.... it should have a
shortcut key which only i would know.....

plz answer...

Thanks and Regards..

Shakeel Ahmad.
 
R

Russ

The txtquestion box action is unclear.
Let us say someone types in three words: First Second Third
And _ = invisible character.
Do you want every letter to disappear as soon as it is typed?
__________________
Do you want the first letter of each word to disappear as soon as a space
character is typed?
_irst _econd _hird
Do want it to act like a textbox only one character wide, where the previous
character disappears as soon as a character is typed?
_d
 
S

Shakeel Ahmad

Your second guess is right.

_irst _econd _hird.
and by clicking the ok button, in the second txtbox it should sow (FST) the
hidden letters of first txtbox.

but as i wrote in my first msg, this function should work by cliking the
cmdhide button, otherwise it should show all the letters....
 
D

Doug Robbins - Word MVP

You are going to have a problem with this requirement: -

the cmdHide button should not be appeard on the form.... it should have a
shortcut key which only i would know.....

because if the cmdHide button is not visible, an accelerator key assigned to
it will not work.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Russ

Shakeel,

Here is some code for txtquestion TextBox. It works in a UserForm dialog.
It replaces the first letter of each word with a question mark, but you
could use an underscore character, if you want. It might misbehave if you
edit the text by the delete key because it is logging each keystroke, but
doesn't remove characters in the log while the delete key is used in the
textbox. Also the last word is not modified unless a space is typed at the
end; because using this method, there is no way to know when the typing has
stop. Dynamically modifying the text causes a lot of headaches. It would be
better to just use an input box that can be freely edited until the OK
button is pressed, then adjust the output to look like what you want. The
full original string is stored in strTxtBxOrig.

Put these four lines in the userform <DECLARATIONS> section:
Option Explicit
Public strTxtBxOrig As String
Public SkipOver As Boolean
Public strTxtBxWork As String

'This Sub goes in the userform code area:
Private Sub txtquestion_Change()
Dim aIndex As Long
Dim strTxtBxArray As Variant
With txtquestion
If Not SkipOver Then
strTxtBxOrig = strTxtBxOrig & Right(.Value, 1)
If Right(.Value, 1) = " " Then
strTxtBxOrig = Trim(strTxtBxOrig) & " "
SkipOver = True
strTxtBxWork = ""
strTxtBxArray = Split(strTxtBxOrig, " ")
For aIndex = 0 To UBound(strTxtBxArray) - 1
strTxtBxWork = strTxtBxWork & "?" & _
Right(strTxtBxArray(aIndex), _
Len(strTxtBxArray(aIndex)) - 1) & " "
Next aIndex
.Value = strTxtBxWork
End If
Else
SkipOver = False
Exit Sub
End If
End With
End Sub
 
R

Russ

Shakeel,
I was able to revise the subroutine to allow using the *backspace* key for
rudimentary editing of mistakes. Other types of editing like insertion
between characters is not logged.

Make sure these three lines are in the userform <DECLARATIONS> section:
Public strTxtBxOrig As String
Public LengthTxtBxOrig As Long
Public strTxtBxWork As String

Delete the 'Public SkipOver As Boolean' line from before.


'This revised Sub replaces the other in the userform code area:

Private Sub txtquestion_Change()
Dim aIndex As Long
Dim strTxtBxArray As Variant
With txtquestion
If Len(.Value) <> LengthTxtBxOrig Then
If Len(.Value) < LengthTxtBxOrig Then
strTxtBxOrig = Left(strTxtBxOrig, Len(.Value))
Else
strTxtBxOrig = strTxtBxOrig & Right(.Value, 1)
End If
LengthTxtBxOrig = Len(strTxtBxOrig)
If Right(.Value, 1) = " " Then
strTxtBxOrig = Trim(strTxtBxOrig) & " "
strTxtBxWork = ""
strTxtBxArray = Split(strTxtBxOrig, " ")
For aIndex = 0 To UBound(strTxtBxArray) - 1
strTxtBxWork = strTxtBxWork & "?" & _
Right(strTxtBxArray(aIndex), _
Len(strTxtBxArray(aIndex)) - 1) & " "
Next aIndex
.Value = strTxtBxWork
End If
End If
End With
End Sub

If UserForm is the name of the form then clicking a blank spot on the form
will show the current contents of the original string by using this sub.

Private Sub UserForm_Click() 'change to WhateverNameIs_Click, if necessary.
MsgBox strTxtBxOrig & "$" '$ helps show where string ends.
End Sub
 
T

Tony Strazzeri

You are going to have a problem with this requirement: -

the cmdHide button should not be appeard on the form.... it should have a
shortcut key which only i would know.....

because if the cmdHide button is not visible, an accelerator key assigned to
it will not work.

Maybe not!
If you place the button somewhere beyond the edge of the userform it
will still work.
ie. Make the form wider.
Put the button to the right of the form's previous right edge
move the right edge back .

Cheers
TonyS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

please help 0
Need help modifying code 0
hidden letters 0
docmd.findrecord 1
Drop cap problem 3
Type ahead combo box 2
Help with Function: Compare text and and edit in cells 2
Line Breaks 1

Top