Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-06-2018, 07:54 AM
phoenixmoto phoenixmoto is offline Word VBA discussion Windows 7 64bit Word VBA discussion Office 2007
Banned
Word VBA discussion
 
Join Date: Jul 2018
Posts: 11
phoenixmoto is on a distinguished road
Default Word VBA discussion

When using public function in vba I inserted sum formula i.e.


Sum = textbox1.value + textbox2.value
When i calculate 1 and 2 it delivers 12 instead of 3 but other symbols such as *,/,- it works correctly. I did hear on internet that + and & used for concatination in vba. So is there a way to use + sign as addition symbol. Please reply.
Reply With Quote
  #2  
Old 07-06-2018, 08:43 PM
gmayor's Avatar
gmayor gmayor is offline Word VBA discussion Windows 10 Word VBA discussion Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It will work if you tell the code what the values are or the instruction + becomes the default for combining text strings e.g.

Code:
Dim Sum As Long
Dim Sum2 As String
    'Sum = Val(TextBox1.value) + Val(TextBox2.value)
    'or
    Sum = CLng(TextBox1.value) + CLng(TextBox2.value)
    Sum2 = TextBox1.value + TextBox2.value
    MsgBox Sum & vbCr & Sum2
__________________
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
  #3  
Old 07-07-2018, 02:37 AM
phoenixmoto phoenixmoto is offline Word VBA discussion Windows 7 64bit Word VBA discussion Office 2007
Banned
Word VBA discussion
 
Join Date: Jul 2018
Posts: 11
phoenixmoto is on a distinguished road
Default

What do you mean by what the values are
And how to tell the code . The sample code you replied contains functions such as sum2 or clng which I don't know please reply
Reply With Quote
  #4  
Old 07-07-2018, 03:14 AM
slaycock slaycock is offline Word VBA discussion Windows 7 64bit Word VBA discussion Office 2016
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

In the VBA IDE put your cursor on the Val or clng and press the F1 key This will bring up the help page for those key words.

The fact that you haven't already googled 'VBA VAL' or 'VBA CLNG' is pretty disappointing
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
InfoPath - User Permissions & Shared Discussion rob171171 Misc 0 09-17-2013 05:14 AM
other forums with visio discussion Guy Roth Visio 1 05-23-2012 05:42 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:28 PM.


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