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

Trying to sum numbers contained in memo field

I came across a function to sum numbers in this thread:
http://bytes.com/topic/access/answer...field-sum-them

I tried to use it, and it works fine for numbers without 00.
However, when summing 1500 + 400 if gives 19 as answer.
Please help me to use the function correctly.
Feb 15 '13 #1

✓ answered by TheSmileyCoder

Here is a variation of the code from the other post. It will not work on doubles, and there may be other bugs. Use at your own risk :)

Expand|Select|Wrap|Line Numbers
  1. Public Function TSCf_CalcTotals(varMEMO As Variant) As Variant
  2. Dim lngLenOfString As Long
  3. Dim lngTotal As Long
  4. Dim strMemo As String
  5. 'Check for empty memo
  6.    If varMEMO & "" = "" Then
  7.       'Memo is empty/null, return null
  8.       TSCf_CalcTotals = Null
  9.       Exit Function
  10.    End If
  11.  
  12. 'Convert variant to memo
  13.    strMemo = CStr(varMEMO)
  14.  
  15. lngLenOfString = Len(strMemo)
  16. Dim l As Long
  17. Dim i As Integer 'Store currentsub string length
  18. l = 1
  19. i = 1
  20. Do
  21.    'Check substring to see if it is numeric
  22.    If IsNumeric(Mid(strMemo, l, i)) Then
  23.       'current substring is numeric
  24.       i = i + 1
  25.       Do Until Not IsNumeric(Mid(strMemo, l, i)) Or l + i > lngLenOfString + 1
  26.          i = i + 1
  27.       Loop
  28.       'substring is no longer numeric.
  29.          'Backtrack 1 strep
  30.             i = i - 1
  31.          'convert substring to long, and add to total
  32.             lngTotal = lngTotal + CLng(Mid(strMemo, l, i))
  33.             l = l + i
  34.    Else
  35.       'substring not numeric, move to next
  36.       l = l + 1
  37.    End If
  38.    'Reset i
  39.    i = 1
  40.  
  41. Loop Until l > lngLenOfString
  42. TSCf_CalcTotals = lngTotal
  43.  
  44.  
  45. End Function

2 1201
TheSmileyCoder
2,322 Expert Mod 2GB
Here is a variation of the code from the other post. It will not work on doubles, and there may be other bugs. Use at your own risk :)

Expand|Select|Wrap|Line Numbers
  1. Public Function TSCf_CalcTotals(varMEMO As Variant) As Variant
  2. Dim lngLenOfString As Long
  3. Dim lngTotal As Long
  4. Dim strMemo As String
  5. 'Check for empty memo
  6.    If varMEMO & "" = "" Then
  7.       'Memo is empty/null, return null
  8.       TSCf_CalcTotals = Null
  9.       Exit Function
  10.    End If
  11.  
  12. 'Convert variant to memo
  13.    strMemo = CStr(varMEMO)
  14.  
  15. lngLenOfString = Len(strMemo)
  16. Dim l As Long
  17. Dim i As Integer 'Store currentsub string length
  18. l = 1
  19. i = 1
  20. Do
  21.    'Check substring to see if it is numeric
  22.    If IsNumeric(Mid(strMemo, l, i)) Then
  23.       'current substring is numeric
  24.       i = i + 1
  25.       Do Until Not IsNumeric(Mid(strMemo, l, i)) Or l + i > lngLenOfString + 1
  26.          i = i + 1
  27.       Loop
  28.       'substring is no longer numeric.
  29.          'Backtrack 1 strep
  30.             i = i - 1
  31.          'convert substring to long, and add to total
  32.             lngTotal = lngTotal + CLng(Mid(strMemo, l, i))
  33.             l = l + i
  34.    Else
  35.       'substring not numeric, move to next
  36.       l = l + 1
  37.    End If
  38.    'Reset i
  39.    i = 1
  40.  
  41. Loop Until l > lngLenOfString
  42. TSCf_CalcTotals = lngTotal
  43.  
  44.  
  45. End Function
Feb 15 '13 #2
Thanks, this works perfect.
Feb 18 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Alfredo Agosti | last post by:
Hi folks, I have an Access 2000 db with a memo field. Into the memo field I put text with bold attributes, URL etc etc What I need to to is converting the rich text contained into the memo...
2
by: Jeremy | last post by:
I have a pretty straightforward database that is designed to record free-form information about products (date, source and a memo field). This is searched and updated via a form. For new records,...
2
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to input data from strings to a memo field. I would like to know how to check first to see if there is text there currently and if so...
4
by: Mal | last post by:
I have an ACC 2000 database that has a strange behaviour I have a small table, with just a few fields... My report has very simple grouping and sorting, no code bar a NODATA event. I have a...
6
by: Matt | last post by:
I'm having difficulty with trying to update a Access memo field through an SQL statement where the value I'm trying to pass is longer than 255 characters. The field is being truncated. I'm using...
4
by: Mark Reed | last post by:
Hi All, here is what I am trying to achieve. I have a memo field on a form which users will need to add to as and when. I do not want them to be able to edit information which already exists...
6
by: Dave | last post by:
Hope someone can help! I have a memo fiels in which there are a few numbers including dates but what I want to do is extract a number which is 6 figures long. Can anyone help me? Thanks Dave
3
by: Roy | last post by:
Hi All, I have a table in A2K application.I get a memo field via download from a .csv file.The contents are as below: field name is TicketStatus, For example,a single ticket,TicketID 12345 ...
5
by: cosmodango | last post by:
I have spent several days on this. I hope someone can help me. I am using Acccess 2000. I have a memo field where I have cut and pasted bulleted/numbered lists from Microsoft Word. I want to...
11
tdw
by: tdw | last post by:
Hi all, I have tried a few different methods to accomplish this, but with no luck. I will post the code for the latest attempt at the end of this post. I work at a land surveying company. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.