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 ? 16 2228
Assuming you have already validated that the first 2 textboxes do, in fact
contain numeric data:
Textbox3.Text = CType(Textbox1. Text, Double) + CType(Textbox2. Text, Double)
Or, for better exception management:
Dim x, y, z As Double
Try
x = CType(Textbox1. Text, Double)
y = CType(Textbox2. Text, Double)
z= x + y
Catch e As Exception
Textbox3.Text = "You must enter only numeric data!"
End Try
"Rob" <rw*****@comcas t.net> wrote in message
news:AI******** ************@co mcast.com... 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 ?
Thanks Scott,
My "real" question is.... where do you put the code ? Let's say you are
using the designer... May I put "= CType(Textbox1. Text, Double) +
CType(Textbox2. Text, Double)" into a property of TextBox3... or must it be
Event driven (i.e., "On Click")
"Scott M." <s-***@nospam.nosp am> wrote in message
news:uW******** ********@TK2MSF TNGP10.phx.gbl. .. Assuming you have already validated that the first 2 textboxes do, in fact contain numeric data:
Textbox3.Text = CType(Textbox1. Text, Double) + CType(Textbox2. Text, Double)
Or, for better exception management:
Dim x, y, z As Double Try x = CType(Textbox1. Text, Double) y = CType(Textbox2. Text, Double) z= x + y Catch e As Exception Textbox3.Text = "You must enter only numeric data!" End Try
"Rob" <rw*****@comcas t.net> wrote in message news:AI******** ************@co mcast.com... 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 ?
A simple way to do it is in the textchanged event of textbox1 and textbox2
"Rob" <rw*****@comcas t.net> wrote in message
news:Q5******** *************** *******@comcast .com... Thanks Scott,
My "real" question is.... where do you put the code ? Let's say you are using the designer... May I put "= CType(Textbox1. Text, Double) + CType(Textbox2. Text, Double)" into a property of TextBox3... or must it be Event driven (i.e., "On Click") "Scott M." <s-***@nospam.nosp am> wrote in message news:uW******** ********@TK2MSF TNGP10.phx.gbl. .. Assuming you have already validated that the first 2 textboxes do, in
fact contain numeric data:
Textbox3.Text = CType(Textbox1. Text, Double) + CType(Textbox2. Text, Double)
Or, for better exception management:
Dim x, y, z As Double Try x = CType(Textbox1. Text, Double) y = CType(Textbox2. Text, Double) z= x + y Catch e As Exception Textbox3.Text = "You must enter only numeric data!" End Try
"Rob" <rw*****@comcas t.net> wrote in message news:AI******** ************@co mcast.com... 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 ?
You generally put your code into event handlers or methods that are then
called by other code.
There are many events you can choose from, but the first thing you want to
do is identify "when" do you want your code to execute. You wouldn't put
any of this code into anything that has to do with Textbox3 because you want
to see the answer when someone clicks a button (most likely), so the code
goes into the click event of the button you add to the form.
"Rob" <rw*****@comcas t.net> wrote in message
news:Q5******** *************** *******@comcast .com... Thanks Scott,
My "real" question is.... where do you put the code ? Let's say you are using the designer... May I put "= CType(Textbox1. Text, Double) + CType(Textbox2. Text, Double)" into a property of TextBox3... or must it be Event driven (i.e., "On Click") "Scott M." <s-***@nospam.nosp am> wrote in message news:uW******** ********@TK2MSF TNGP10.phx.gbl. .. Assuming you have already validated that the first 2 textboxes do, in fact contain numeric data:
Textbox3.Text = CType(Textbox1. Text, Double) + CType(Textbox2. Text, Double)
Or, for better exception management:
Dim x, y, z As Double Try x = CType(Textbox1. Text, Double) y = CType(Textbox2. Text, Double) z= x + y Catch e As Exception Textbox3.Text = "You must enter only numeric data!" End Try
"Rob" <rw*****@comcas t.net> wrote in message news:AI******** ************@co mcast.com... 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 ?
"Rob" <rw*****@comcas t.net> wrote in message
news:Q5******** *************** *******@comcast .com... Thanks Scott,
My "real" question is.... where do you put the code ? Let's say you are using the designer... May I put "= CType(Textbox1. Text, Double) + CType(Textbox2. Text, Double)" into a property of TextBox3... or must it be Event driven (i.e., "On Click")
In VB6 you'd use the Textbox1_Change and Textbox2_Change events.
Why not TextBox?_TextCh anged ?
Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles TextBox1.TextCh anged
TextBox3.Text = TextBox1.Text & TextBox2.Text
End Sub
Private Sub TextBox2_TextCh anged(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles TextBox2.TextCh anged
TextBox3.Text = TextBox1.Text & TextBox2.Text
End Sub
> In VB6 you'd use the Textbox1_Change and Textbox2_Change events. Why not TextBox?_TextCh anged ?
You could put this code into a TextChanged event, but it is not the most
common approach (and wasn't in VB 6.0 either). Generally, a button is
created explicitly for users to click to cause some calculation.
Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox1.TextCh anged TextBox3.Text = TextBox1.Text & TextBox2.Text
End Sub
Private Sub TextBox2_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox2.TextCh anged
TextBox3.Text = TextBox1.Text & TextBox2.Text
End Sub
Your code above isn't really the best approach because you have written the
same thing in 2 places. Now, sure you could create a third procedure that
the first two call so that the code isn't duplicated, but this is besides
the point. The point is to determine which *event* you want to trigger the
code.
"Scott M." <s-***@nospam.nosp am> wrote in message
news:ey******** ******@TK2MSFTN GP12.phx.gbl... In VB6 you'd use the Textbox1_Change and Textbox2_Change events.
Why not TextBox?_TextCh anged ?
You could put this code into a TextChanged event, but it is not the most common approach (and wasn't in VB 6.0 either). Generally, a button is created explicitly for users to click to cause some calculation.
Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox1.TextCh anged TextBox3.Text = TextBox1.Text & TextBox2.Text
End Sub
Private Sub TextBox2_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles TextBox2.TextCh anged
TextBox3.Text = TextBox1.Text & TextBox2.Text
End Sub
Your code above isn't really the best approach because you have written the same thing in 2 places. Now, sure you could create a third procedure that the first two call so that the code isn't duplicated, but this is besides the point. The point is to determine which *event* you want to trigger the code.
The code I gave him was the simplest possible solution and it worked. From
that he can add as much complication as he desires. KISS.
> The code I gave him was the simplest possible solution and it worked. From that he can add as much complication as he desires. KISS.
You think writing the same code in 2 different places is the simpleset
solution? Uh, well ok.
As I said earlier, it's really a matter of choosing between TextChanged and
a button's Click event handler (as you say, they both work) but there are
those who believe (me among them) that you should give the user a control to
interact with in order for an operation to be triggerd.
Both scenarios are simplistic, it's a usability issue (and with my solution,
there is less code to add).
"Scott M." <s-***@nospam.nosp am> wrote in message
news:uz******** *****@TK2MSFTNG P12.phx.gbl... The code I gave him was the simplest possible solution and it worked. From that he can add as much complication as he desires. KISS.
You think writing the same code in 2 different places is the simpleset solution? Uh, well ok.
As I said earlier, it's really a matter of choosing between TextChanged and a button's Click event handler (as you say, they both work) but there are those who believe (me among them) that you should give the user a control to interact with in order for an operation to be triggerd.
Both scenarios are simplistic, it's a usability issue (and with my solution, there is less code to add).
You'll never get it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul Edwards |
last post by:
I am writing in c# with Visual Studio 2003. I am creating
a form that shows one record from a Dataset that is
populated with only one record from SQL Server 2000. I am
using bound controls, both text boxes and Combo Boxes
(populated successfuly from same data source).
When I use the fill command for the SQLDataAdaptor I can
get the data by querying the dataset but the controls on
the form do not show the data. If I set a combo box to...
|
by: vulcaned |
last post by:
Hi All,
Hopefully I explain this well........
In Access97 I have a form which has a tab control on it, each tab has a
sub-form which is bound to its appropriate table(I'll call them
'Detail' tables). I have a 'Header' table and fields from it are
displayed on the form above the tab control.
Header table name is tblClientInfo
Detail tables are tblPolicyInfo, tblBeneInfo, tblRiderInfo
|
by: BBM |
last post by:
Hi,
I'm having trouble getting control data binding to work. As I understand
it, the simplest form of databinding requires three things:
1) A control (say a textbox) on a form or user control,
2) A field or object.member to which you want to bind,
3) A "Binding" object that connects the variable to a property of the
control ("Text" for example).
|
by: Greg |
last post by:
Binding Manager & dataset - won't add record
I've got an untyped dataset with controls bound through code. The user
can select a question number from a bound combobox, and the question
number and question text are displayed in bound textboxes. This part
works fine.
When I go to add a new record, the textboxes clear as they should. I
enter a new question number and tab to the textbox for the question
text. At this point, the text for the...
|
by: Andrew McKendrick |
last post by:
Hi,
I've noticed a bug in VB.NET (latest .NET Framework)...
- I have a TabControl on a form with several tabs.
- Each tab contains text boxes that are bound to fields in a data source
(DataBindings).
- When I display a record and then try to access the .Text property of one
of the text boxes on any tab except the current tab, the result is an Empty
string.
| |
by: timbobd |
last post by:
I have a Windows form that displays a database table in a DataGrid. When you
click on a row, the row's values get copied to bound TextBoxes below, and
when the "Save" button is clicked the database is updated (as is the DataGrid
row) with changed values in the TextBoxes. Here are some observations:
1) When changes are typed into a text box and "Save" is clicked, the changes
are reflected in the DataSet.Tables().Rows().ItemArray value, but...
|
by: jon f kaminsky |
last post by:
Hi-
I've seen this problem discussed a jillion times but I cannot seem to
implement any advice that makes it work. I am porting a large project from
VB6 to .NET. The issue is using the combo box bound to a table as a lookup,
drawing values from another table to populate the available selections. This
all worked fine in VB6.
I have distilled the problem down to a simple form drawing data from the
Northwind database for a representative...
|
by: Bill |
last post by:
Problem:
Combo box data disappears from view when a requery is done
See "Background" below for details on tables, forms & controls
On a form, I want to use the setting of bound combo box C1 to limit
what is displayed in bound combo box C2. When I display Tbl-A records
on a continuous form, and navigate away from record 1 to record 2, the
previously entered data displayed in C2 for record 1 disappears from
|
by: Frnak McKenney |
last post by:
Can I use a bound ComboBox for both browsing and editing?
I'm working on a small, standalone database application using Visual
C#.NET 2003 and an Access data file.
In order to keep the number of different screens down to a minimum,
I'm trying to use the same Windows Forms for both browsing and for
updating. This works fine for TextBoxes, but I'm running into
problems with my DropDownLists (ComboBoxes).
|
by: Mike |
last post by:
So here's the situation (.NET 2.0 btw):
I have a form, and on this form is a textbox among many other
databound controls. The textbox is bound to a field in a data table
via the Text property. In this table there are multiple columns that
cannot be NULL, which, are bound to other controls (but they're not
really important at this time).
I create a new row via the currency manager like so:
_currencyManager.AddNew()
_currentRow =...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |