An Unwanted Comma appears in TextBox 
Author Message
 An Unwanted Comma appears in TextBox

The "scenario" I'm dealing with is nearly identical to the 'Print Dialog
Box / Pages to Print" entry text box.
I want "user" to be able to enter question #'s (from a db table), in
"random" order, from which to create an exam.
The (entry) text box is "KeyPress-protected" to reject anything but 0-9
or commas to separate the integers.
"So far, so good..."
In trying to "Error-trap/Idiot-proof" the program, I want to detect if
the user enters an invalid (integer) number (i.e. greater than the
highest-number question in the table). And, for added insurance (as the
MsgBox states) I wish to delete the invalid entry.

I've gone "round-and-round" with the following, including separating it
into 2 subs ("Fix_It" called from the middle of this mess).

Still ... (even having added the 2 lines highlighted with *****)... I
continue to end-up with an 'unwanted/un-asked-for' comma added at the
beginning of the TextBox (?!) This messes-up the actual "Count"
(displayed in Label4) which lets the user see how many Selex%
(selections) he's made. [Read "PS" at bottom]

I expect the following will be pretty "messed-up" after posting.  If you
can make sense of it, and explain what's happening, I'd be most
grateful.

Private Sub Count_Qs()              ' "Count" 'integers entered' to
Text2.
Dim T$, A$, N$                      ' Text2 "Contents"
Dim P%, Ts%, Full%, Nu%
T$ = Text2.Text
Full% = Len(T$)
Open "CountBuf" For Output As #1    ' Using 'Print' instead of 'Write'
lets "Input#2,A$" grab 1 char only.
Print #1, T$                        ' a Comma(,) = Ascii 44 (Chk if user
"omits" a comma
Close #1                            ' i.e. a MsgBox if a 4-digit integer
is entered.)
Static Selex%                       ' Begin counting at Zero
Selex% = 0

Open "CountBuf" For Input As #2

    Do While Not EOF(2)
    Input #2, A$
        If Val(A$) > TblRecz% Then      ' user entered a # > highest Q#
in table.
            MsgBox ("The number entered exceeds the highest-order Q.# in
the available list. Deleting.")
            Screen.MousePointer = 11    ' Hourglass (for "slowpokes")

                P% = Len(A$)
                Ts% = Full% - P%
                N$ = Left(T$, Ts%)
                Nu% = Len(N$)
                    If Asc(N$) = 44 Then    '*********
                        N$ = Right(N$, Nu% - 1) '*****
                    End If
                Text2.Text = N$
                Screen.MousePointer = 1     ' no more Hourglass
                Exit Do
        End If
    Selex% = Selex% + 1
    Loop

Label4.Caption = Selex%
Close #2
End Sub
__________________________________
PS:
Everything "works" alright, including displaying the number of
selections made (Selex%), until an invalid # is entered.
Then, the invalid number gets deleted, BUT ... the unwanted comma
appears at beginning of TextBox.
If "all else fails", I'll relegate myself to changing the form:  having
a single "Enter Choice" box, and an accompanying "Selections
Made"/Display textbox. But ... I'll still be "blue" from not having
solved the problem!



Sun, 06 May 2001 03:00:00 GMT  
 An Unwanted Comma appears in TextBox
This won't work. If N$ = a comma, then len(N$) = 1. Right$(N$, len-1) then
means Right$(N$,0) which does nothing. Make it: If N$ = "," then N$=""

John Tegelaar

Quote:

>The "scenario" I'm dealing with is nearly identical to the 'Print Dialog
>Box / Pages to Print" entry text box.

<SNIP>

Quote:
>                P% = Len(A$)
>                Ts% = Full% - P%
>                N$ = Left(T$, Ts%)
>                Nu% = Len(N$)
>                    If Asc(N$) = 44 Then    '*********
>                        N$ = Right(N$, Nu% - 1) '*****
>                    End If

<SNIP>


Mon, 07 May 2001 03:00:00 GMT  
 An Unwanted Comma appears in TextBox
I  REALLY appreciate your taking time to read-thru my long-winded problem ...!
. . . <unfortunately> ... I don't think we're "there" yet.
If you can spare the proverbial 2 minutes , please try the following :

Put a  TextBox  and a  Label  on a form ;
Paste-in the following Text1_KeyPress code.
- - - - - - - - - - - - - - - - - - - - - - - - - - -

Private Sub Text1_KeyPress(KeyAscii As Integer)

    If KeyAscii = 44 Then   ' user entered a comma : so ...
    Count_Qs                ' "Count" 'integers entered'
    Exit Sub
ElseIf KeyAscii = 8 Then    'Allow "Backspacing".
    KeyAscii = 8
    Exit Sub                'and allow integers.
ElseIf KeyAscii < 48 Or KeyAscii > 57 Then
    KeyAscii = 0
End If

End Sub

End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Then , paste-in the following Subroutine: * * * * * *
- - - - - - - - - - - - - - - - - - - - - - - - - - -

Private Sub Count_Qs()              ' "Count" 'integers entered' to Text2.

Dim T$, A$, N$                      ' Text2 "Contents"
Dim P%, Ts%, Full%, Nu%

T$ = Text2.Text                     ' To determine the number of characters in
string, use the Len function.
Full% = Len(T$)
Open "CountBuf" For Output As #1    ' Using 'Print' instead of 'Write' lets
"Input#2,A$" grab 1 char only!
Dim T$, A$, N$
Dim P%, Ts%, Full%, Nu%

T$ = Text1.Text                     ' To determine the number of characters in
string, use the Len function.
Full% = Len(T$)
Open "CountBuf" For Output As #1    ' Using 'Print' instead of 'Write' lets
"Input#2,A$" grab 1 char only!
Print #1, T$                        ' a Comma(,) = Ascii 44 (Chk if user
"omits" a comma
Close #1                            ' i.e. a MsgBox if a 4-digit integer is
entered.)
Static Selex%                       ' Begin counting at Zero
Selex% = 0
Dim TblRecz%        ' Here for Test only (GlobalVar)
TblRecz% = 150    ' For TEST only ( determined by Recordset count elsewhere...)

Open "CountBuf" For Input As #2

    Do While Not EOF(2)
    Input #2, A$
        If Val(A$) > TblRecz% Then      ' user entered a # > highest Q# in
table.

            MsgBox ("The number entered exceeds the highest-order Q.# in the
available list. Deleting.")
            Screen.MousePointer = 11    ' Hourglass (for "slowpokes")

                P% = Len(A$)
                Ts% = Full% - P%
                N$ = Left(T$, Ts%)
                Nu% = Len(N$)
                    If Asc(N$) = 44 Then  ' Asc returns 44 IF first
                                        'character is a comma
                        N$ = Right(N$, Nu% - 1)
                                 '... If so, Trim-it-off.
                    End If
                Text1.Text = N$
                Screen.MousePointer = 1     ' no more Hourglass
                Exit Do
        End If

    Selex% = Selex% + 1
    Loop

Label1.Caption = Selex%

Close #2

End Sub
- - - - - - - - - - - - - - END * * * * *
Run the "Test" .
In  Text1 , type the following :
    1,3,4,6,8,367,      <Don't forget final comma!
and you'll see "Exactly" what's happening.
PS:  the  "367"  can be anything greater than 150 (in this case).
I have another label explaining to the user to put commas between
each entry, and after the final selection...(which is "reinforced" by
tooltip prompt on the textbox too).

Quote:

> This won't work. If N$ = a comma, then len(N$) = 1. Right$(N$, len-1) then
> means Right$(N$,0) which does nothing. Make it: If N$ = "," then N$=""
> John Tegelaar


> >The "scenario" I'm dealing with is nearly identical to the 'Print Dialog
> >Box / Pages to Print" entry text box.
> <SNIP>
> >                P% = Len(A$)
> >                Ts% = Full% - P%
> >                N$ = Left(T$, Ts%)
> >                Nu% = Len(N$)
> >                    If Asc(N$) = 44 Then    '*********
> >                        N$ = Right(N$, Nu% - 1) '*****
> >                    End If
> <SNIP>



Mon, 07 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. unwanted chracters appering in textbox

2. Unwanted Placeholders in Userform Textbox

3. unwanted characters returned in textbox ( Cindy & Doug)

4. Preventing Unwanted Characters in TextBox?

5. create and append comma delimited text from textbox

6. textbox - entries separated by commas

7. textbox - entries separated by commas

8. How to make first letter of textbox appear only

9. Selecting textboxes in order the appear in doc

10. Can't get cursor to appear in textbox

11. Bindingd Dataset to Textbox appears flawed.

12. Masking a password textbox to appear as all *****

 

 
Powered by phpBB® Forum Software