PC Review


Reply
Thread Tools Rate Thread

Backspace brings up an error

 
 
Greybeard
Guest
Posts: n/a
 
      25th Oct 2008
I have a userform with 4 textboxes for 4 different sets of numerical
data, which are then processed to give a result.
The basic code for each is:
Public Sub TextBox1_Change()
Dim current As Single
current = TextBox1.Text

When the correct data is put in all works fine, but if I make a
mistake and use backspace to delete the entry so I can put in the
correct numbers I get a "Run Time error 13, Type mismatch", when the
first number is deleted (ie the last to be removed by the backspace).

The debug highlights the current = terxtbox1.text line but that's it.
Can anyone please put me right so I can just change the numbers by
backspace?
Thanks
Tony
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      25th Oct 2008
Try changing the delcaration of Current to

Dim current As String


If you need to convert this to a number use the VAL function

Dim current As Single
current = Val(TextBox1.Text)


"Greybeard" wrote:

> I have a userform with 4 textboxes for 4 different sets of numerical
> data, which are then processed to give a result.
> The basic code for each is:
> Public Sub TextBox1_Change()
> Dim current As Single
> current = TextBox1.Text
>
> When the correct data is put in all works fine, but if I make a
> mistake and use backspace to delete the entry so I can put in the
> correct numbers I get a "Run Time error 13, Type mismatch", when the
> first number is deleted (ie the last to be removed by the backspace).
>
> The debug highlights the current = terxtbox1.text line but that's it.
> Can anyone please put me right so I can just change the numbers by
> backspace?
> Thanks
> Tony
>

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      25th Oct 2008
Hi,

2 ways
current = Val(TextBox1.Text)

or
If TextBox1.Text <> "" Then
current = TextBox1.Text
End If

You seem to have a data type confusion with current dimensioned as Single
while taking the value .text

Mike



"Greybeard" wrote:

> I have a userform with 4 textboxes for 4 different sets of numerical
> data, which are then processed to give a result.
> The basic code for each is:
> Public Sub TextBox1_Change()
> Dim current As Single
> current = TextBox1.Text
>
> When the correct data is put in all works fine, but if I make a
> mistake and use backspace to delete the entry so I can put in the
> correct numbers I get a "Run Time error 13, Type mismatch", when the
> first number is deleted (ie the last to be removed by the backspace).
>
> The debug highlights the current = terxtbox1.text line but that's it.
> Can anyone please put me right so I can just change the numbers by
> backspace?
> Thanks
> Tony
>

 
Reply With Quote
 
Greybeard
Guest
Posts: n/a
 
      26th Oct 2008
On 25 Oct, 10:29, Mike H <Mi...@discussions.microsoft.com> wrote:
> Hi,
>
> 2 ways
> current = Val(TextBox1.Text)
>
> or
> If TextBox1.Text <> "" Then
> * * current = TextBox1.Text
> End If
>
> You seem to have a data type confusion with current dimensioned as Single
> while taking the value .text
>
> Mike
>
> "Greybeard" wrote:
> > I have a userform with 4 textboxes for 4 different sets of numerical
> > data, which are then processed to give a result.
> > The basic code for each is:
> > Public Sub TextBox1_Change()
> > Dim current As Single
> > current = TextBox1.Text

>
> > When the correct data is put in all works fine, but if I make a
> > mistake and use backspace to delete the entry so I can put in the
> > correct numbers I get a "Run Time error 13, *Type mismatch", when the
> > first number is deleted (ie the last to be removed by the backspace).

>
> > The debug highlights the current = terxtbox1.text line but that's it.
> > Can anyone please put me right so I can just change the numbers by
> > backspace?
> > Thanks
> > Tony


Hi,
Thanks to all of you who replied.
Through lots of trial and error (no pun intended) I have actually got
it to work fine using the following in each of the 4 subs for each of
the Textboxes:
Public Sub TextBox1_Change()
Dim current As Single
On Error Resume Next
current = TextBox2.Text
End Sub
It's probably all wrong, but it does not have any adverse effects on
the overall running of the whole programme so, as a pragmatist, it's a
case of 'if it works don't fix it'.
Regards Tony
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      26th Oct 2008
You did not get it to work, you only got it to quit sending the error
message. But if it satisfies you, then that is all that matters.

"Greybeard" wrote:

> On 25 Oct, 10:29, Mike H <Mi...@discussions.microsoft.com> wrote:
> > Hi,
> >
> > 2 ways
> > current = Val(TextBox1.Text)
> >
> > or
> > If TextBox1.Text <> "" Then
> > current = TextBox1.Text
> > End If
> >
> > You seem to have a data type confusion with current dimensioned as Single
> > while taking the value .text
> >
> > Mike
> >
> > "Greybeard" wrote:
> > > I have a userform with 4 textboxes for 4 different sets of numerical
> > > data, which are then processed to give a result.
> > > The basic code for each is:
> > > Public Sub TextBox1_Change()
> > > Dim current As Single
> > > current = TextBox1.Text

> >
> > > When the correct data is put in all works fine, but if I make a
> > > mistake and use backspace to delete the entry so I can put in the
> > > correct numbers I get a "Run Time error 13, Type mismatch", when the
> > > first number is deleted (ie the last to be removed by the backspace).

> >
> > > The debug highlights the current = terxtbox1.text line but that's it.
> > > Can anyone please put me right so I can just change the numbers by
> > > backspace?
> > > Thanks
> > > Tony

>
> Hi,
> Thanks to all of you who replied.
> Through lots of trial and error (no pun intended) I have actually got
> it to work fine using the following in each of the 4 subs for each of
> the Textboxes:
> Public Sub TextBox1_Change()
> Dim current As Single
> On Error Resume Next
> current = TextBox2.Text
> End Sub
> It's probably all wrong, but it does not have any adverse effects on
> the overall running of the whole programme so, as a pragmatist, it's a
> case of 'if it works don't fix it'.
> Regards Tony
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very Quick: Backspace Key Error Tom Microsoft Word Document Management 2 30th Apr 2008 10:41 PM
notepad.exe ran only at current dir = C:\ brings up 16-bit MS-DOS error VanguardLH Windows XP General 10 2nd Dec 2007 05:16 PM
Pressing Left Alt key brings up "My Computer" Right brings up Calc =?Utf-8?B?Qml0c2t5?= Windows XP General 0 4th Aug 2007 08:46 PM
Backspace brings up unwanted menus =?Utf-8?B?SWFu?= Windows XP Help 1 21st Jun 2006 12:51 AM
disc brings up error message Aaron Seekings Windows XP Music 0 18th Aug 2003 10:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:37 AM.