473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

text box calculation

Help,

I am new to visual basic programming and I was wondering how to allow a
textbox
to do a calculation by pressing enter

ie I want to type the following into a textbox 25.2 * 2 press enter on the
keyboard
and the textbox to display 50.4 Any Ideas ???????
Jul 17 '05 #1
7 10295
check out the keypress event
you'll see "keyascii" is given as an arg
keyascii is a number representing the ascii code of the key pressed.
that should get you started

"Amanda" <bo***@bonzai.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...
Help,

I am new to visual basic programming and I was wondering how to allow a
textbox
to do a calculation by pressing enter

ie I want to type the following into a textbox 25.2 * 2 press enter on the keyboard
and the textbox to display 50.4 Any Ideas ???????

Jul 17 '05 #2

"Hal Rosser" <hm******@bellsouth.net> skrev i en meddelelse
news:db******************@bignews3.bellsouth.net.. .
check out the keypress event
you'll see "keyascii" is given as an arg
keyascii is a number representing the ascii code of the key
pressed.
that should get you started


How should that solve his problem ? He's looking for Expression
Evaluator code.
--
/\ preben nielsen
\/\ pr**@post.tele.dk
Jul 17 '05 #3

"Amanda" <bo***@bonzai.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...
| Help,
|
| I am new to visual basic programming and I was wondering how to allow
a
| textbox
| to do a calculation by pressing enter
|
| ie I want to type the following into a textbox 25.2 * 2 press enter
on the
| keyboard
| and the textbox to display 50.4 Any Ideas ???????
|
|

Do you have the Microsoft Script Control in your list of components? If
so, then add one to your form. You then just need this simple event
handler:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
On Error Resume Next
Text1.Text = ScriptControl1.Eval(Text1.Text)
End If
End Sub

You might want to make Text1 multi-line, so you don't get a beep when
you press enter.
Jul 17 '05 #4

"preben nielsen" <pr**@post.tele.dk> wrote in message
news:41***********************@dread14.news.tele.d k...

"Hal Rosser" <hm******@bellsouth.net> skrev i en meddelelse
news:db******************@bignews3.bellsouth.net.. .
check out the keypress event
you'll see "keyascii" is given as an arg
keyascii is a number representing the ascii code of the key
pressed.
that should get you started


How should that solve his problem ? He's looking for Expression
Evaluator code.


Did I say it would "solve his problem" ? no - I said it shouild get him
started.
I know its unheard of in some circles - but its a starting point for the OP
to "Write Code" that will evaluate the expression.
Jul 17 '05 #5
Many thanks for the tip Steve, it works a dream.

Regards

Martin

"Steve Gerrard" <my********@comcast.net> wrote in message
news:oe********************@comcast.com...

"Amanda" <bo***@bonzai.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...
| Help,
|
| I am new to visual basic programming and I was wondering how to allow
a
| textbox
| to do a calculation by pressing enter
|
| ie I want to type the following into a textbox 25.2 * 2 press enter
on the
| keyboard
| and the textbox to display 50.4 Any Ideas ???????
|
|

Do you have the Microsoft Script Control in your list of components? If
so, then add one to your form. You then just need this simple event
handler:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
On Error Resume Next
Text1.Text = ScriptControl1.Eval(Text1.Text)
End If
End Sub

You might want to make Text1 multi-line, so you don't get a beep when
you press enter.

Jul 17 '05 #6
Thank you Steve it works flawlessly.

"Steve Gerrard" <my********@comcast.net> wrote in message
news:oe********************@comcast.com...

"Amanda" <bo***@bonzai.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...
| Help,
|
| I am new to visual basic programming and I was wondering how to allow
a
| textbox
| to do a calculation by pressing enter
|
| ie I want to type the following into a textbox 25.2 * 2 press enter
on the
| keyboard
| and the textbox to display 50.4 Any Ideas ???????
|
|

Do you have the Microsoft Script Control in your list of components? If
so, then add one to your form. You then just need this simple event
handler:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
On Error Resume Next
Text1.Text = ScriptControl1.Eval(Text1.Text)
End If
End Sub

You might want to make Text1 multi-line, so you don't get a beep when
you press enter.

Jul 17 '05 #7

"Nicola" <bo***@bonzai.co.uk> wrote in message
news:42********@mk-nntp-2.news.uk.tiscali.com...
| Thank you Steve it works flawlessly.
|

You are welcome. Hopefully you weren't in a hurry :)
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: grayFalcon | last post by:
Hello! I've got a small problem here. I'm trying to write some code that would generate a drop-down menue for me, where I'd just need to enter the menu- and submenu items into an array. The...
0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
6
by: Adrian Lin | last post by:
Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge...
16
by: Rob | last post by:
Assume 3 controls on a form.... Textbox1, Textbox2, and Textbox3 If you want Textbox3 to equal Val(Textbox1) + Val(Textbox2).. How do you hardcode this to Textbox3 ?
1
by: vincec | last post by:
Hi need some help from you guysin using visual C++. I am thinking of opening a text file after some calculation. For example, after i press the "calculation", then at the OnCalculation function, it...
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
13
by: Ulv | last post by:
I have a table (TblItems) with fields Lenght, Width and Height as decimalfields. I also have the fields Desc, a text field. In a form I have created this line of code after updating: Desc =...
1
by: aman909 | last post by:
Hello, I have a unbound text box on a form. This gives a total from a calculation. I would like this total from the unbound text box to appear on another form. I just need the total on the...
14
by: David C. Stone | last post by:
Is there a way in CSS to adjust the baseline position of text marked up with either <sup></supor <sub></sub>, relative to the surrounding text? Reason for asking is that the default rendering in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.