473,426 Members | 1,408 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,426 software developers and data experts.

how to do math functions on data in a form before saving to SQL 20

In the code below I’m trying to figure out how to dynamically perform math
functions in a form. To start, I would like to subtract
TxtITotal.Text from TxtPTotal.Text and display the results in
TxtProLoss.Text before sending the data to the database. I have no
idea where to begin.

Any help would be greatly appreciated,

Thank you,

Mark
Public Class Form1
Dim StrServer As String = "servername"
Dim strUserName As String = "username"
Dim strPassword As String = "password"
Dim strDB As String = "ABC"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Conn As New ADODB.Connection

Conn.Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;User ID=" & strUserName & _
";password=" & strPassword & ";Initial Catalog=" & strDB &
";Data Source=" & StrServer)

Dim strSql As String

strSql = "INSERT INTO SP_Trading_1 (acct, sSymbol, tDateS, tDateB,
contracts, strike, sValue, bValue, iTotal, pTotal, Pl) VALUES (" & _
CDbl("0" & TxtAcc.Text) & ",'" & sSymbol.Text & "','" &
DTSDate.Text & "','" & DTBDate.Text & "'," & CDbl("0" & TxtContract.Text) & _
"," & CDbl("0" & TxtStrike.Text) & "," & CDbl("0" &
TxtSellV.Text) & "," & CDbl("0" & TxtbVal.Text) & "," & _
CDbl("0" & TxtITotal.Text) & "," & CDbl("0" & TxtPTotal.Text) &
"," & CDbl("0" & TxtProLoss.Text) & ")"

Conn.Execute(strSql)
Conn.Close()
Conn = Nothing

End Sub

Private Sub TxtAcc_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TxtAcc.TextChanged

End Sub

Private Sub DTSDate_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DTSDate.TextChanged

End Sub

Private Sub DTBDate_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DTBDate.TextChanged

End Sub

Private Sub TxtContract_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TxtContract.TextChanged

End Sub

Private Sub TxtStrike_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtStrike.TextChanged

End Sub

Private Sub TxtSellV_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtSellV.TextChanged

End Sub

Private Sub TxtbVal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtbVal.TextChanged

End Sub

Private Sub TxtITotal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtITotal.TextChanged

End Sub

Private Sub TxtPTotal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtPTotal.TextChanged

End Sub

Private Sub TxtProLoss_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TxtProLoss.TextChanged

End Sub

Private Sub sSymbol_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles sSymbol.TextChanged

End Sub
End Class

Nov 23 '05 #1
4 1756
ma*********@newsgroups.nospam wrote:
In the code below I’m trying to figure out how to dynamically perform math
functions in a form. To start, I would like to subtract
TxtITotal.Text from TxtPTotal.Text and display the results in
TxtProLoss.Text before sending the data to the database. I have no
idea where to begin.

Any help would be greatly appreciated,

Thank you,

Mark
Public Class Form1
Dim StrServer As String = "servername"
Dim strUserName As String = "username"
Dim strPassword As String = "password"
Dim strDB As String = "ABC"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Conn As New ADODB.Connection

Conn.Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;User ID=" & strUserName & _
";password=" & strPassword & ";Initial Catalog=" & strDB &
";Data Source=" & StrServer)

Dim strSql As String

strSql = "INSERT INTO SP_Trading_1 (acct, sSymbol, tDateS, tDateB,
contracts, strike, sValue, bValue, iTotal, pTotal, Pl) VALUES (" & _
CDbl("0" & TxtAcc.Text) & ",'" & sSymbol.Text & "','" &
DTSDate.Text & "','" & DTBDate.Text & "'," & CDbl("0" & TxtContract.Text) & _
"," & CDbl("0" & TxtStrike.Text) & "," & CDbl("0" &
TxtSellV.Text) & "," & CDbl("0" & TxtbVal.Text) & "," & _
CDbl("0" & TxtITotal.Text) & "," & CDbl("0" & TxtPTotal.Text) &
"," & CDbl("0" & TxtProLoss.Text) & ")"

Conn.Execute(strSql)
Conn.Close()
Conn = Nothing

End Sub

Private Sub TxtAcc_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TxtAcc.TextChanged

End Sub

Private Sub DTSDate_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DTSDate.TextChanged

End Sub

Private Sub DTBDate_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DTBDate.TextChanged

End Sub

Private Sub TxtContract_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TxtContract.TextChanged

End Sub

Private Sub TxtStrike_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtStrike.TextChanged

End Sub

Private Sub TxtSellV_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtSellV.TextChanged

End Sub

Private Sub TxtbVal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtbVal.TextChanged

End Sub

Private Sub TxtITotal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtITotal.TextChanged

End Sub

Private Sub TxtPTotal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtPTotal.TextChanged

End Sub

Private Sub TxtProLoss_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TxtProLoss.TextChanged

End Sub

Private Sub sSymbol_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles sSymbol.TextChanged

End Sub
End Class


When do you want the form to update?
TxtProLoss.Text = cstr(cint(TxtITotal.Text ) - cint(TxtPTotal.Text))

That will do that calc. if you want to do it after one of those two
textfield changes do it in the textchanged functions you have listed in
your code.

Chris
Nov 23 '05 #2
Awesome!

I entered the code in the textfield change for TxtPTotal

Private Sub TxtPTotal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtPTotal.TextChanged
TxtProLoss.Text = CStr(CInt(TxtITotal.Text) - CInt(TxtPTotal.Text))
End Sub

The code does calculate after entering the value in TxtPTotal text box, but
what if I need to change the value in the TxtITotal text box?
How do I code this section to allow changes to either box?

Thanks,

Mark
"Chris" wrote:
ma*********@newsgroups.nospam wrote:
In the code below I’m trying to figure out how to dynamically perform math
functions in a form. To start, I would like to subtract
TxtITotal.Text from TxtPTotal.Text and display the results in
TxtProLoss.Text before sending the data to the database. I have no
idea where to begin.

Any help would be greatly appreciated,

Thank you,

Mark
Public Class Form1
Dim StrServer As String = "servername"
Dim strUserName As String = "username"
Dim strPassword As String = "password"
Dim strDB As String = "ABC"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Conn As New ADODB.Connection

Conn.Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;User ID=" & strUserName & _
";password=" & strPassword & ";Initial Catalog=" & strDB &
";Data Source=" & StrServer)

Dim strSql As String

strSql = "INSERT INTO SP_Trading_1 (acct, sSymbol, tDateS, tDateB,
contracts, strike, sValue, bValue, iTotal, pTotal, Pl) VALUES (" & _
CDbl("0" & TxtAcc.Text) & ",'" & sSymbol.Text & "','" &
DTSDate.Text & "','" & DTBDate.Text & "'," & CDbl("0" & TxtContract.Text) & _
"," & CDbl("0" & TxtStrike.Text) & "," & CDbl("0" &
TxtSellV.Text) & "," & CDbl("0" & TxtbVal.Text) & "," & _
CDbl("0" & TxtITotal.Text) & "," & CDbl("0" & TxtPTotal.Text) &
"," & CDbl("0" & TxtProLoss.Text) & ")"

Conn.Execute(strSql)
Conn.Close()
Conn = Nothing

End Sub

Private Sub TxtAcc_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TxtAcc.TextChanged

End Sub

Private Sub DTSDate_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DTSDate.TextChanged

End Sub

Private Sub DTBDate_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DTBDate.TextChanged

End Sub

Private Sub TxtContract_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TxtContract.TextChanged

End Sub

Private Sub TxtStrike_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtStrike.TextChanged

End Sub

Private Sub TxtSellV_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtSellV.TextChanged

End Sub

Private Sub TxtbVal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtbVal.TextChanged

End Sub

Private Sub TxtITotal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtITotal.TextChanged

End Sub

Private Sub TxtPTotal_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtPTotal.TextChanged

End Sub

Private Sub TxtProLoss_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TxtProLoss.TextChanged

End Sub

Private Sub sSymbol_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles sSymbol.TextChanged

End Sub
End Class


When do you want the form to update?
TxtProLoss.Text = cstr(cint(TxtITotal.Text ) - cint(TxtPTotal.Text))

That will do that calc. if you want to do it after one of those two
textfield changes do it in the textchanged functions you have listed in
your code.

Chris

Nov 23 '05 #3
Hi

I think you may try to handle the TxtITotal's TextChanged event too.
Private Sub TxtITotal_TextChanged(ByVal sender As System.Object, ByVal
e
As System.EventArgs) Handles TxtPTotal.TextChanged
TxtProLoss.Text = CStr(CInt(TxtITotal.Text) - CInt(TxtPTotal.Text))
End Sub

so that either TxtITotal.Text or TxtPTotal.Text changed the TxtProLoss.Text
will be recalculated.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 23 '05 #4
Hi Mark,

Did my suggestion help you?
If you still have any concern, please feel free to post here.
Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 23 '05 #5

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

Similar topics

1
by: Robert Mark Bram | last post by:
Howdy All! I am trying to write a very brief comparison of the Date and Math objects in terms of instance v static objects. What I have below is my best so far. Any criticisms or suggestions are...
1
by: limelight | last post by:
I have discovered a math error in the .NET framework's Log function. It returns incorrect results for varying powers of 2 that depend on whether the program is run from within the IDE or from the...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
3
by: Christopher Koh | last post by:
how do you stop Access from saving any changed data in your tables and queries? like i just add or change data on the table/query tables,then click on X (exit)because i have no intention of saving...
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
11
by: Sambo | last post by:
I have the following module: ------------------------------- import math def ac_add_a_ph( amp1, ph1, amp2, ph2 ): amp3 = 0.0 ph3 = 0.0 ac1 = ( 0, 0j ) ac2 = ( 0, 0j )
7
by: Mark Healey | last post by:
Do the trig functions in math.h work in degrees, radians or what? For some reason it doesn't say which in "man math.h" IIRC the arctan of a slope gives the angle. So, shouldn't atanf((float)1)...
20
by: J de Boyne Pollard | last post by:
MThe library functions which are included to allow process Mlaunch, forking, and termination, imply that it is both Mpossible and desirable for a process to fork itself. This is Ma fundamental...
9
by: DaiOz | last post by:
Hi guys im doing a course which includes some JavaScript and I need help with the following question please, The code I have so far is below but I don't think its right please help as I need...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
1
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.