473,804 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10311
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.c o.uk> wrote in message
news:41******** @mk-nntp-2.news.uk.tisca li.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******@bells outh.net> skrev i en meddelelse
news:db******** **********@bign ews3.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.c o.uk> wrote in message
news:41******** @mk-nntp-2.news.uk.tisca li.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.t ele.dk...

"Hal Rosser" <hm******@bells outh.net> skrev i en meddelelse
news:db******** **********@bign ews3.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********@com cast.net> wrote in message
news:oe******** ************@co mcast.com...

"Amanda" <bo***@bonzai.c o.uk> wrote in message
news:41******** @mk-nntp-2.news.uk.tisca li.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********@com cast.net> wrote in message
news:oe******** ************@co mcast.com...

"Amanda" <bo***@bonzai.c o.uk> wrote in message
news:41******** @mk-nntp-2.news.uk.tisca li.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.c o.uk> wrote in message
news:42******** @mk-nntp-2.news.uk.tisca li.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
1603
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 items are to be displayed as text. Now, I want to have the layers with the submenues to appear more or less under the appropriate main menu items. For this I need to be able to calculate how many pixels a given text uses up on the screen of the user....
0
2487
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 to use a parent window that allows the user to launch the calculation in a seperate window, so that they could still click "stop" to write a value to a database or set a session level variable that the calculation would check to see if it should...
6
1870
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 calculations in which genetic matrices are saved in text files instead of being held in arrays that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put...
16
2233
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
1966
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 will do some calcuation the it is written to a text file called "result.txt". Then i would like it to open the text file automatically after the calculation instead of i going to the folder to open it to view. Anyone know how to do so? Thanks
5
6263
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 user modifies any of the x, y and z values.
13
2128
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 = Lenght & " x " & Width & " x " & Height If the values is 100, 100, 100 the result is 100 x 7920 x 100. No matter what value I put into the width field It comes out with the same 7920. Why??
1
1630
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 other form, not the calculation. How do i do this?
14
37117
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 most browsers always increases the spacing between the line of text containing these elements and those above/below that lack it. I can easily reduce the size of the subscript or superscript
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.