Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-06-2018, 01:03 AM
phoenixmoto phoenixmoto is offline vba add and subtract code Windows 7 64bit vba add and subtract code Office 2007
Banned
vba add and subtract code
 
Join Date: Jul 2018
Posts: 11
phoenixmoto is on a distinguished road
Default vba add and subtract code

Sub phoenixmoto()
With UserForm1


.wow.Value = True
With .comb
.AddItem "addition"
.AddItem "subtraction"
End With
.comb.Value = "subtraction"

.TextBox1.Value = 10
.TextBox2.Value = 20
.TextBox3.Value = 30
.Show
End With
Unload UserForm1
End Sub



Private Sub cancel_Click()
hide
End Sub


Private Sub ok_Click()
Dim a As Variant, b As Variant, c As Variant
If TextBox1.Value = "" Then
MsgBox "a field is empty"
Exit Sub
End If
If TextBox2.Value = "" Then
MsgBox "b field is empty"
Exit Sub
End If
If TextBox3.Value = "" Then
MsgBox "c field is empty"
Exit Sub
End If

a = TextBox1.Value
b = TextBox2.Value
c = TextBox3.Value

If wow.Value = True Then
Select Case comb
Case "addition"
Call ad(a, b, c)
Case "subtraction"
Call minus(a, b, c)
End Select
End If
hide
End Sub


Sub ad(a As Variant, b As Variant, c As Variant)
ThisDocument.TextBox10.Value = amrit(a, b, c)
End Sub
Sub minus(a As Variant, b As Variant, c As Variant)
ThisDocument.TextBox10.Value = sam(a, b, c)
End Sub
Public Function amrit(a As Variant, b As Variant, c As Variant) As Variant
amrit = (a + b + c)
End Function
Public Function sam(a As Variant, b As Variant, c As Variant) As Variant
sam = (a - b - c)
End Function

here in this code function sam works fine and delivers -40 as answer but function amrit does concatination(102030) instead of sum(i.e 60)
how + symbol is working like &
Reply With Quote
  #2  
Old 11-06-2018, 01:25 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline vba add and subtract code Windows 7 64bit vba add and subtract code Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,417
Pecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to all
Default

You should know by now that code MUST be wrapped with code tags to make it easier to read and copy.

Edit your first post,select your code and click the #button
Thank you
Reply With Quote
  #3  
Old 11-06-2018, 01:26 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline vba add and subtract code Windows 7 64bit vba add and subtract code Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,417
Pecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to all
Default

Also post in the correct subforum in the future ( VBA Word)
Reply With Quote
  #4  
Old 11-06-2018, 01:35 AM
phoenixmoto phoenixmoto is offline vba add and subtract code Windows 7 64bit vba add and subtract code Office 2007
Banned
vba add and subtract code
 
Join Date: Jul 2018
Posts: 11
phoenixmoto is on a distinguished road
Default

i did not understand your reply . please provide answer
Reply With Quote
  #5  
Old 11-06-2018, 04:45 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline vba add and subtract code Windows 7 64bit vba add and subtract code Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,417
Pecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to allPecoflyer is a name known to all
Default

Please read and comply with post #2 Thank you
Reply With Quote
  #6  
Old 11-06-2018, 05:05 AM
gmayor's Avatar
gmayor gmayor is offline vba add and subtract code Windows 10 vba add and subtract code Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,180
gmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of light
Default

Change all the Variant variables to Long variables and it will work as you intend.
It would also have been preferable to have added your further question to your earlier post rather than start a new one.
To add code tags, select Go Advanced select the code and use the # button.
It is advisable to use Option Explicit to start your modules as this forces you to declare variables and makes errors easier to spot. You can set the VBA editor options to do this automatically.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 11-06-2018, 02:06 PM
macropod's Avatar
macropod macropod is offline vba add and subtract code Windows 7 64bit vba add and subtract code Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,433
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Cross-posted at: http://www.vbaexpress.com/forum/show...?64008-vba-add
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
phoenixmoto: You have persistently cross-posted and duplicated posted you various discussions, ignoring all reminders of the expected etiquette here and the rules at VBA Express. Accordingly, I am terminating your account here.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
subtract date and time and convert to decimal hours ? DBenz Excel 5 01-26-2017 05:38 AM
vba add and subtract code Subtract value if cell contains X term Jue92 Excel 4 11-01-2016 01:45 AM
Subtract value from one cell into another otuatail Excel 3 02-01-2016 03:21 AM
Use a numerical merge field to subtract that number of months MichaelSpedding Mail Merge 8 11-11-2015 01:11 PM
vba add and subtract code How to Subtract value in table, based on two different conditions nitemath2 Excel 1 06-19-2015 01:28 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 12:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft