disabling the space key or removing a space from a string 
Author Message
 disabling the space key or removing a space from a string


Quote:
> Dose anyone know how to disable a key Example being the space key. or how
to
> take out letters from a string if you don't knwo there position??

If you've got VB6, then use the Replace function and replace all " " with
"".  If you are using something else, you will have to manually use the
Instr function and find spaces, then zap them from there.  If for some odd
reason you need the length of the string to work those other functions, use
the Len(stringName) function.

Quote:
> i can use

>  trim(strString)

>  to get rid of ending spaces but i don't know how to get the space out of
a
> string like this "hi there" if i don't know the lenght of the string
mainly
> becasue i want the string not to have the space to begin with becasue it
> will be displayed as it is typed.

> also is there a way that i can set up a text box so that only numbers cam
be
> typed??

Yeah, there are several ways.  You could just use a Masked Edit box and
limit the character input to numbers.  However, there can be problems with
that.  You can also check things in the KeyPress and KeyUp events and then
change them to character 0 if it isn't a number.  However, there are some
problems with that too (like what happends when someone presses the Negative
sign or a decimal point or two.  Also, what happends when someone just
pastes stuff in from the clipboard?).

If you want, you can goto my web page and download my Numeric Input Box
ActiveX control.  It will include some features which you may or may not
want, but it is also free with complete source code, so you could read what
I've written to keep things numerical.  (I'm afraid my code may be a little
messy, though, because I wrote that one only as a quick test).

--
Howard Henry 'Gawyn Ballpeen' Schlunder
Gawyn Developments; Core developer
http://www.*-*-*.com/ ~hschlund/



Sun, 06 Jan 2002 03:00:00 GMT  
 disabling the space key or removing a space from a string
Dose anyone know how to disable a key Example being the space key. or how to
take out letters from a string if you don't knwo there position??

i can use

 trim(strString)

 to get rid of ending spaces but i don't know how to get the space out of a
string like this "hi there" if i don't know the lenght of the string mainly
becasue i want the string not to have the space to begin with becasue it
will be displayed as it is typed.

also is there a way that i can set up a text box so that only numbers cam be
typed??




Mon, 07 Jan 2002 03:00:00 GMT  
 disabling the space key or removing a space from a string
The reply that Howard gave is perfect.
There is an alternative though, and that is to
disable the space key.

In the keypress code of your textbox (I assume), you can check
for spaces and set keyascii to 0, which will remove them.
Of course the space will not be added to the textbox.
try something like this:
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 32 Then KeyAscii = 0
    'or if you want to give feedback then use this:
    If KeyAscii = 32 Then
        KeyAscii = 0
        beep
        statusbar.panels(1).text = "Please don't type spaces here as they cause
me stress!"
    endif
End Sub

I had been using this in the past, but I think I'll use Howard's Replace
function from
now on!

Good luck
AJ

Quote:

> Dose anyone know how to disable a key Example being the space key. or how to
> take out letters from a string if you don't knwo there position??

> i can use

>  trim(strString)

>  to get rid of ending spaces but i don't know how to get the space out of a
> string like this "hi there" if i don't know the lenght of the string mainly
> becasue i want the string not to have the space to begin with becasue it
> will be displayed as it is typed.

> also is there a way that i can set up a text box so that only numbers cam be
> typed??





Mon, 07 Jan 2002 03:00:00 GMT  
 disabling the space key or removing a space from a string
Here is a way which, despite having some minor faults, is the easiest for
you to understand. All you have to do to modify it for your own needs is
type into the string (s1) whatever characters you want the Text Box to
accept. The example, as it stands, will accept the characters a to g, the
decimal point and the numbers 0 to 9. It will also, as it stands, accept the
backspace key and (if the Text Box multiline property is True) the carriage
return key.

Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim s1 As String
'
s1 = "abcdefg.0123456789"
'
s1 = s1 + Chr$(8) ' if you want the backspace to work
s1 = s1 + Chr$(13) ' if you want the Return key to work
If InStr(s1, LCase(Chr(KeyAscii))) = 0 Then
 Beep
 KeyAscii = 0
End If
End Sub

Mike


Quote:
> Dose anyone know how to disable a key Example being the space key. or how
to
> take out letters from a string if you don't knwo there position??

> i can use

>  trim(strString)

>  to get rid of ending spaces but i don't know how to get the space out of
a
> string like this "hi there" if i don't know the lenght of the string
mainly
> becasue i want the string not to have the space to begin with becasue it
> will be displayed as it is typed.

> also is there a way that i can set up a text box so that only numbers cam
be
> typed??





Mon, 07 Jan 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Space Space Space Space Space Space Space

2. Space Space Space Space Space Space Space

3. Space Space Space Space Space Space Space

4. string replace with wildcard number of spaces between strings - removing blank lines

5. Function to Squeeze multiple spaces in a string to one space

6. Removing spaces from a string

7. Removing spaces from a string

8. Removing all spaces from a string

9. Removing Spaces In A String

10. Removing multiple spaces in a string

11. Function to remove the CR/LF and spaces from a string

12. How to remove spaces from strings?

 

 
Powered by phpBB® Forum Software