OK, the first code generates an error at strSplitAt unknown function. So I deleted all of the lines and pasted in the text document, deleted the comments. How then to run the function in the immediate window with some string that needs to be a number? I don't remember doing that, although Hans suggested that I type in Convert2Num("114'27.5") in the immediate window and that converted the string to a useable number in my Access thread. This procedure will go into an Access number field event.
Let’s take this one step at a time; it works. I have been using this code in all my applications for 25 years.
The program code I have supplied is generic VBA. It will work in any MSOffice application that supports VBA: Word, Excel, Access, Powerpoint, Outlook, Project etc.
We will show this by running it in WordVBA, after which you can transfer the code to whatever application you want.
(1) Open up MSWord. Then open up and maximize the Visual Basic Editor. You should see something like the image below:-
BKnight_01.png
I started with a new document which is called (by MSWord) Document2.
I have circled the comment/decomment toolbar buttons
In the Project Explorer window you can see that the Project is called “Document2”, and that I have inserted a new module, which is called “Module1”
I always have an Option Explicit statement – you will find posts about it here in Eileen’s Lounge.
(2) Now open up that attached text file. I copy/paste the contents by using:-
(a) Ctrl+A to select all the text in the file. Guaranteed every time!
(b) Ctrl+C to copy the selected text to the clipboard
(c) Alt+Tab to return to the Visual Basic Editor
(d) Ctrl+V to paste the clipboard contents into the module1.
BKnight_02.png
This is what I see now in the VBE. Except for that large arrow, which I painted on the screen snapshot to indicate that there is more code below; I can’t show all the code on my laptop screen.
(3) Save your work at this time with Alt+F then S
(4) You can drag the three (green) commented lines from the end of the function “dblApostrophe” until they are immediately below that functions END statement, then de-comment them using the de-comment tool in the toolbar
BKnight_03.png
In this screen shot I have dragged the TEST subroutine outside its function and I am about to click on the yellow-circled toolbar button.
(5) Once that is done, your three line TEST subroutine will still be selected.
(6) So tap the F5 function key to run that TEST subroutine.
(7) It should run quietly without any objection. That means that the TEST subroutine called the function “dblApostrophe”, which executed and returned the correct result.
(8) Try running that TEST subroutine again, but first change the
Code: Select all
Debug.Assert 113.859375 = dblApostrophe("113'27.5")
To read
Code: Select all
Debug.Assert 513.859375 = dblApostrophe("113'27.5")
(9) Now when you run the TEST subroutine, you should find that the subroutine halts with that Debug.Assert line highlit in yellow. That indicates that there is a problem. (Of Course! We supplied the wrong answer this time around!!!)
If you get this far, then collect some more sample data.
Duplicate that Debug.Assert line using your collected data.
Now this is important: Do NOT run the function with the new data to see what results pop out and then paste those results into your Debug statement.
Collect the data, calculate
by yourself what you expect to get as a result, and use THOSE values to the left of the equals sign.
You want to know that the function returns what you expect, not what it returns.
Cheers, Chris
You do not have the required permissions to view the files attached to this post.