Unexpected assignment statement in modules - module

I want to define inside a module some constants that are shared by several subroutines, but I get many error messages when I try to compile it (with the -c command):
Error: Unexpected assignment statement in MODULE
If I use the same code in a subroutine it works.
Here's the code of the module:
module rkSetup
!High order embedded Runge-Kutta formulae, by P.J.Prince and J.R.Dormand,
!Journal of Computational and Applied Mathematics, vol. 7, 1981, pages 67-75
implicit none
INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15)
integer, parameter :: s = 13 ! number of stages
integer, parameter :: p = 8 !< Order of the method
real(dp), dimension(s) :: a !< Runge-Kutta vector of nodes
real(dp), dimension(s) :: c !< Runge-Kutta vector of weigths
real(dp), dimension(s) :: d !< Runge-Kutta vector of weigths for high order
real(dp), dimension(s,s-1) :: b !< Runge-Kutta matrix
a = (/0.0_dp, 1.0_dp/18.0_dp, 1.0_dp/12.0_dp, 1.0_dp/8.0_dp, &
5.0_dp/16.0_dp,3.0_dp/8.0_dp,59.0_dp/400.0_dp,93.0_dp/200.0_dp, &
5490023248.0_dp/9719169821.0_dp, 13.0_dp/20.0_dp, &
1201146811.0_dp/1299019798.0_dp, 1.0_dp, 1.0_dp/)
c = 0.0_dp
d = 0.0_dp
d(1) = 14005451.0_dp/335480064.0_dp
d(6:) = (/-59238493.0_dp/1068277825.0_dp, &
181606767.0_dp/758867731.0_dp, &
561292985.0_dp/797845732.0_dp, &
-1041891430.0_dp/1371343529.0_dp, &
760417239.0_dp/1151165299.0_dp, &
118820643.0_dp/751138087.0_dp, &
-528747749.0_dp/2220607170.0_dp, 1.0_dp/4.0_dp/)
c(1) = 13451932.0_dp/455176623.0_dp
c(6:12) = (/-808719846.0_dp/976000145.0_dp, &
1757004468.0_dp/5645159321.0_dp, &
656045339.0_dp/265891186.0_dp, &
-3867574721.0_dp/1518517206.0_dp, &
465885868.0_dp/322736535.0_dp, &
53011238.0_dp/667516719.0_dp, 2.0_dp/45.0_dp/)
b = 0.0_dp
b(:,1) = (/0.0_dp, 1.0_dp/18.0_dp, 1.0_dp/48.0_dp, &
1.0_dp/32.0_dp, 5.0_dp/16.0_dp, 3.0_dp/80.0_dp, &
29443841.0_dp/614563906.0_dp, 16016141.0_dp/946692911.0_dp, &
39632708.0_dp/573591083.0_dp, 246121993.0_dp/1340847787.0_dp, &
-1028468189.0_dp/846180014.0_dp, 185892177.0_dp/718116043.0_dp, &
403863854.0_dp/491063109.0_dp/)
b(3,2) = 1.0_dp/16.0_dp
b(4:5,3) = (/3.0_dp/32.0_dp, -75.0_dp/64.0_dp /)
b(5:,4) = (/75.0_dp/64.0_dp,3.0_dp/16.0_dp, &
77736538.0_dp/692538347.0_dp, 61564180.0_dp/158732637.0_dp, &
-433636366.0_dp/683701615.0_dp, -37695042795.0_dp/15268766246.0_dp, &
8478235783.0_dp/508512852.0_dp, -3185094517.0_dp/667107341.0_dp, &
-5068492393.0_dp/434740067.0_dp/)
b(6:,5) = (/3.0_dp/20.0_dp, -28693883.0_dp/1125000000.0_dp, &
22789713.0_dp/633445777.0_dp, -421739975.0_dp/2616292301.0_dp, &
-309121744.0_dp/1061227803.0_dp, 1311729495.0_dp/1432422823.0_dp, &
-477755414.0_dp/1098053517.0_dp, -411421997.0_dp/543043805.0_dp/)
b(7:,6) = (/23124283.0_dp/1800000000.0_dp, &
545815736.0_dp/2771057229.0_dp,100302831.0_dp/723423059.0_dp, &
-12992083.0_dp/490766935.0_dp,-10304129995.0_dp/1701304382.0_dp, &
-703635378.0_dp/230739211.0_dp,652783627.0_dp/914296604.0_dp/)
b(8:,7) = (/-180193667.0_dp/1043307555.0_dp, &
790204164.0_dp/839813087.0_dp, 6005943493.0_dp/2108947869.0_dp, &
-48777925059.0_dp/3047939560.0_dp, 5731566787.0_dp/1027545527.0_dp, &
11173962825.0_dp/925320556.0_dp/)
b(9:,8) = (/800635310.0_dp/3783071287.0_dp, &
393006217.0_dp/1396673457.0_dp, 15336726248.0_dp/1032824649.0_dp, &
5232866602.0_dp/850066563.0_dp, -13158990841.0_dp/6184727034.0_dp /)
b(10:,9) = (/123872331.0_dp/1001029789.0_dp, &
-45442868181.0_dp/3398467696.0_dp,-4093664535.0_dp/808688257.0_dp, &
3936647629.0_dp/1978049680.0_dp/)
b(11:,10) = (/3065993473.0_dp/597172653.0_dp, &
3962137247.0_dp/1805957418.0_dp, -160528059.0_dp/685178525.0_dp/)
b(12:,11) = (/65686358.0_dp/487910083.0_dp, &
248638103.0_dp/1413531060.0_dp/)
end module rkSetup
How can I solve this?

As per Table 2.2 in the Fortran 2008 Standard, you may not place executable statements into a module directly.
If you want to initialize this data, either (a) do it during declaration, or (b) add a dedicated subroutine that you can call to do the initialization.
(a)
real(dp), dimension(s),parameter :: a = &
(/0.0_dp, 1.0_dp/18.0_dp, 1.0_dp/12.0_dp, 1.0_dp/8.0_dp, &
5.0_dp/16.0_dp,3.0_dp/8.0_dp,59.0_dp/400.0_dp,93.0_dp/200.0_dp, &
5490023248.0_dp/9719169821.0_dp, 13.0_dp/20.0_dp, &
1201146811.0_dp/1299019798.0_dp, 1.0_dp, 1.0_dp/)
(b)
module rkSetup
!High order embedded Runge-Kutta formulae, by P.J.Prince and J.R.Dormand,
!Journal of Computational and Applied Mathematics, vol. 7, 1981, pages 67-75
implicit none
INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15)
!...
contains
subroutine init()
a = (/0.0_dp, 1.0_dp/18.0_dp, 1.0_dp/12.0_dp, 1.0_dp/8.0_dp, &
5.0_dp/16.0_dp,3.0_dp/8.0_dp,59.0_dp/400.0_dp,93.0_dp/200.0_dp, &
5490023248.0_dp/9719169821.0_dp, 13.0_dp/20.0_dp, &
1201146811.0_dp/1299019798.0_dp, 1.0_dp, 1.0_dp/)
!....
end subroutine
end module

Alexander Vogt is correct that you can define them in an initialization routine. However, if a,b,c,d are constants, the most efficient thing to do is define them as parameters. Here is an example of two ways to do this:
module params
implicit none
integer, parameter :: s = 5
! -- Initialization method 1
real, parameter :: a(s) = (/ 1.2, 3.4, &
5.6, 7.8, 9.0 /)
! -- Initialization method 2
real :: b(s)
parameter( b = (/ 1.2, 3.4, &
5.6, 7.8, 9.0 /) )
end module params
program main
use params
write(*,'(a,5f6.2)') 'a is: ', a
write(*,'(a,5f6.2)') 'b is: ', b
end program main
If you wish to set a large parameter array with more than one dimension, consider using reshape.

Related

Why is (L \ 12) calculating to 0?

I am trying to do calculations through VBA.
I am doing it through the form itself because when Production creates one of these Job Tickets a number of fields can change on the fly. Which Unit of Measure we are running in, which type of Wood, how we Wrap it, etc.
All of these changes affect the total footage or amount of pieces we have to run, which is why I have If-Then-Else statements for them.
It works until I get to Wrap SQ Footage. I get a zero inserted into my field, but when I do the calculations on my own I never get 0.
I created this expression in the control source of one of the Wrap SQ Footages, and it comes out correctly.
=Abs(Int( (([Wrap_Slit1]/12) * [Quantity_Ordered] ) * ( [RIP_Scrap_Rate] + 1))))
Private Sub FTG_Calculations()
'Declare Variable
Dim L As Double
Dim Length As Double
Dim OrderFTG As Double
Dim UoM As String
Dim W As Double
Dim frm As Access.Form
Set frm = Forms!Frm_JobTicket
'Set L equal to Length from Tbl_JobTicketMould
L = DLookup("Length", "Tbl_JobTicketMould", "Access_ID =" & Forms!Frm_JobTicket!Part_Number)
'Convert Length to Feet
Length = (L \ 12)
'Find Unit of Measure for this part
UoM = DLookup("Unit_of_Measure", "Tbl_JobTicketUoM", "Access_ID =" & Forms!Frm_JobTicket!Part_Number)
'Mupltiply Length times Quantity to get Order Footage
OrderFTG = Int((Length * Me.Txt_Pcs_JobTicket))
'If UoM is PCS then insert that number. Otherwise set equal to Quantity Ordered divided by Length of piece(in FT)
If UoM = "PCS" Then Me.Txt_Pcs_JobTicket = Me.Quantity_Ordered Else: Me.Txt_Pcs_JobTicket = Abs(Int(Me.Quantity_Ordered \ Length))
'Define limits of the loop. Then runs through all Wrap SQ FTG fields and inputs calculation
For W = 1 To 3
'If UoM is PCS then calculate Order Footage to find Wrap Sqaure Footage. Otherwise take slit size in FT and multiply by Order Quantity and Scrap Rate
If UoM = "PCS" Then
frm("Txt_Wrap" & W & "SQFTG_JobTicket") = (((frm("Wrap_Slit" & W) \ 12) * OrderFTG) * (Round((frm("RIP_Scrap_Rate")), 3) + 1))
Else: frm("Txt_Wrap" & W & "SQFTG_JobTicket") = (((frm("Wrap_Slit" & W) \ 12) * frm(Quantity_Ordered)) * (frm(RIP_Scrap_Rate + 1)))
End If
Next W
I figured out the issue is in the (frm("Wrap_Slit" & W) \ 12) area. Wrap_Slit1 shows a value of 2 in the data tips, but when I divide by 12 it comes out to 0.
All of my data points are set to double, and the variables are declared as double. It is rounding down when it should come out to .16667.
Place the following code before the:
If UoM = "PCS" Then
Msgbox code:
MsgBox("Current State:" & vbCrLf & _
"UoM:" & vbTab & UoM & vbCrlf & _
"OrderFTGL" & vbTab & OrderFTG & _
"Wrap_Slit1:" & vbTab & Me.Wrap_Slit1 & _
... continue pattern for other desired values in calculation...
"Continue...", vbOK)

MS Access VBA concatenation

this is my first time posting! So I created a database on ms access that helps in invoicing and helps to create and analyse data. I wanted to simplify it and add code to it. One of the modules that I created is the following one, it takes four numbers as input, three of them have a default value of 0, if they are anything other than zero then it is supposed to concatenate them. I believe( atleast hope) the module is correct, but when I add it to the form, it displays an error "?Name".
Thanks in advance! :-)
This is the code:
Function MultiApart(ApOne As Single, ApTwo As Single, ApThree As Single, ApFour As Single) As String
Dim a As String
Dim b As String
Dim c As String
Dim d As String
a = CStr(ApOne)
b = CStr(ApTwo)
c = CStr(ApThree)
d = CStr(ApFour)
MultiApart = a
If (ApTwo > 0#) Then MultiApart = MultiApart & ", " & b
If (ApThree > 0#) Then MultiApart = MultiApart & ", " & c
If (ApFour > 0#) Then MultiApart = MultiApart & ", " & d
End Function

Creating DLL from a Fortran subroutine to be used in Excel VBA

My goal is to find a way to call Fortran subroutine in Excel VBA (can be found on Prof Alan Genz. The program is MVNPACK) to compute the CDF of multivariate normal distribution. Ideally, I would like to be able to use a version of DLL compiled from that source code in a C# project as well in the future. However, I am not sure how to troubleshoot and proceed further. I typically code in Python, have some exposure in C, Java, etc., but never use Fortran and not too familiar with what's going on when one calls a function in a DLL. To the best of my knowledge, this computation is not that widely available, and compiling the Fortran source code is my best bet.
I have been closely following the example here about creating the DLL, and here about using that in Excel VBA, and been trying to mimic the result. Starting from the MVNPACK source code mentioned above, I figured that what I need is to pass the inputs to the subroutine MVNDST, and get the result back by passing the pointers as arguments to the subroutine. So the first thing I did was trying to modify the code based on what the examples did. My modified version MVNDSTC looks like this.
SUBROUTINE MVNDSTC( N, LOWERC, UPPERC, INFINC, CORRELC, MAXPTS,
& ABSEPS, RELEPS, ERRORC, VALUEC, INFORMC)
& bind(c)
use ISO_C_BINDING
implicit none
cGCC$ ATTRIBUTES STDCALL, DLLEXPORT :: MVNDSTC
EXTERNAL MVNDFN
integer(kind=c_long), value:: N, MAXPTS
real(kind=c_double), value:: ABSEPS, RELEPS
type(c_ptr), value:: LOWERC, UPPERC, INFINC, CORRELC
type(c_ptr), value:: ERRORC, VALUEC, INFORMC
real(kind=c_double), dimension(:), pointer:: LOWER, UPPER, CORREL
integer(kind=c_long), dimension(:), pointer:: INFIN
real(kind=c_double), dimension(:), pointer:: ERROR_OUT, VALUE_OUT
integer(kind=c_int), dimension(:), pointer:: INFORM_OUT
INTEGER NN
INTEGER INFORM, INFIS, IVLS
DOUBLE PRECISION ERROR, VALUE, E, D, MVNDNT, MVNDFN
COMMON /DKBLCK/IVLS
NN = (N - 1) * N / 2
call C_F_POINTER(LOWERC, LOWER, [N])
call C_F_POINTER(UPPERC, UPPER, [N])
call C_F_POINTER(INFINC, INFIN, [N])
call C_F_POINTER(CORRELC, CORREL, [NN])
call C_F_POINTER(ERRORC, ERROR_OUT, [1])
call C_F_POINTER(VALUEC, VALUE_OUT, [1])
call C_F_POINTER(INFORMC, INFORM_OUT, [1])
IF ( N .GT. 500 .OR. N .LT. 1 ) THEN
INFORM = 2
VALUE = 0
ERROR = 1
ELSE
INFORM = MVNDNT(N, CORREL, LOWER, UPPER, INFIN, INFIS, D, E)
IF ( N-INFIS .EQ. 0 ) THEN
VALUE = 1
ERROR = 0
ELSE IF ( N-INFIS .EQ. 1 ) THEN
VALUE = E - D
ERROR = 2D-16
ELSE
*
* Call the lattice rule integration subroutine
*
IVLS = 0
CALL DKBVRC( N-INFIS-1, IVLS, MAXPTS, MVNDFN,
& ABSEPS, RELEPS, ERROR, VALUE, INFORM )
ENDIF
ENDIF
VALUE_OUT(0) = VALUE
ERROR_OUT(0) = ERROR
INFORM_OUT(0) = INFORM
END
Then I created a small subroutine with the mvndstc declaration on top. The VBA code is as follows.
Private Declare PtrSafe Sub mvndstc Lib "C:\Users\poopa\Desktop\mvn\mvn_project\fortran-library.dll" _
(ByVal N As Integer, _
ByRef LOWER As Single, _
ByRef UPPER As Single, _
ByRef INFIN As Single, _
ByRef CORREL As Single, _
ByVal MAXPTS As Integer, _
ByVal ABSEPS As Double, _
ByVal RELEPS As Double, _
ByRef ERROR As Single, _
ByRef VALUE As Single, _
ByRef INFORM As Single)
Sub mvn_test()
Dim value_1(1 To 1) As Single ' Result of the function
Dim inform_1(1 To 1) As Single ' Information
Dim error_1(1 To 1) As Single ' Error estimate
Dim upper_1() As Single
Dim lower_1() As Single
Dim infin_1() As Single
Dim correl_1() As Single
Dim n_1 As Long, n_1_2 As Long, max_pts_1 As Long
n_1 = 5
ReDim lower_1(1 To n_1)
ReDim upper_1(1 To n_1)
ReDim infin_1(1 To n_1)
lower_1(1) = 0#
lower_1(2) = 0#
lower_1(3) = 1.7817
lower_1(4) = 0.14755
lower_1(5) = 0#
upper_1(1) = 0#
upper_1(2) = 1.5198
upper_1(3) = 0#
upper_1(4) = 0#
upper_1(5) = 1.5949
infin_1(1) = 1
infin_1(2) = 2
infin_1(3) = 1
infin_1(4) = 1
infin_1(5) = 0
n_1_2 = Int(n_1 / 2 * (n_1 - 1))
ReDim correl_1(1 To n_1_2)
correl_1(1) = -0.707107 ' 12
correl_1(2) = 0# ' 13
correl_1(3) = 0.5 ' 14
correl_1(4) = 0# ' 15
correl_1(5) = 0.5 ' 23
correl_1(6) = 0.5 ' 24
correl_1(7) = 0# ' 25
correl_1(8) = 0.5 ' 34
correl_1(9) = 0.5 ' 35
correl_1(10) = 0.5 ' 45
max_pts_1 = 625000
mvndstc n_1, lower_1(1), upper_1(1), infin_1(1), correl_1(1), max_pts_1, 0.00005, 0, error_1(1), value_1(1), inform_1(1)
Debug.Print "Value = " & (value_1(1))
Debug.Print "Error Est = " & (error_1(1))
Debug.Print "Inform = " & inform_1(1)
End Sub
Now my first attempt I did not modify ERROR, VALUE, INFORM parameters at all and simply declare then in Fortran as theirs respective primitive types. I can actually run the VBA subroutine, but I got all zeros for the results. So I was speculating that the program runs but perhaps I didn't get the result back properly and I should treat these three outputs as pointers with size of 1. That way I just keep whatever procedure exactly the same in Fortran and then if I put VALUE_OUT(0) = VALUE and so on, before the function ends I should be get the results just fine. Right now using the code I posted here, I can actually see the results printed out in VBA, still all zeros, but right after that Excel would immediately crash.
So I want to ask how do I proceed from here? What did I got wrong here? Is there any resource worth looking into?
Thanks in advance.
I fixed this yesterday, the problem is indeed about the data types. When I read the tutorial I was assuming Single is some kind of object type in VBA. Little did I know that Single is actually the single precision of Double! I tried debugging all this by letting the DLL print out all the values inside the function to a file.

VBS script return expected result, how to compare float value?

I am getting an interesting result when executing the following VB script.
Set StdOut = WScript.StdOut
Set wbemSvc = GetObject("winmgmts://" & "." & "/root/cimv2")
Set biosSet = wbemSvc.ExecQuery("Select * from Win32_BIOS")
For Each biosObj In biosSet
StdOut.WriteLine "SMBIOSMajorVersion=" & biosObj.SMBIOSMajorVersion
StdOut.WriteLine "SMBIOSMinorVersion=" & biosObj.SMBIOSMinorVersion
Next
StdOut.WriteLine "Return value is: " & IsNewBiosVersion
Function IsNewBiosVersion()
On Error Resume Next
Set biosSet = wbemSvc.ExecQuery("Select * from Win32_BIOS")
newBios = 0
For Each bios In biosSet
minorFloat = "." & bios.SMBIOSMinorVersion
If bios.SMBIOSMajorVersion > 2 OR (bios.SMBIOSMajorVersion = 2 AND minorFloat >= .6) Then
newBios = 1
End If
Next
IsNewBiosVersion = newBios
End Function
The result is as follow. This looks contradictory since the SMBIOSMinorVersion=4, according to the code logic in the script, the return value should be 0!!!
SMBIOSMajorVersion=2
SMBIOSMinorVersion=4
Return value is: 1
I ran this same script on another system and got the expected correct result.
SMBIOSMajorVersion=2
SMBIOSMinorVersion=4
Return value is: 0
So what is the problem here?
New update:
We execute the following script again on the system, and found that the CDbl() function does not convert the string "2.4" to double value correctly, instead it converts it to 24! Looks like the dot "." was lost when converting, what is wrong with this? An bug in CDbl or a violation when use it?
here is the script
Set StdOut = WScript.StdOut
StdOut.WriteLine ""
StdOut.WriteLine "Simple Function to Test BIOS Version"
StdOut.WriteLine ""
Set wbemSvc = GetObject("winmgmts://" & "." & "/root/cimv2")
Set biosSet = wbemSvc.ExecQuery("Select * from Win32_BIOS")
For Each bios In biosSet
newBios = 0
StdOut.WriteLine "SMBIOSMajorVersion=" & bios.SMBIOSMajorVersion
StdOut.WriteLine "SMBIOSMinorVersion=" & bios.SMBIOSMinorVersion
temp = bios.SMBIOSMajorVersion & "." & bios.SMBIOSMinorVersion
StdOut.WriteLine "major dot minor=" & temp
currentBios = CDbl(bios.SMBIOSMajorVersion & "." & bios.SMBIOSMinorVersion)
StdOut.WriteLine ""
StdOut.WriteLine "currentBios=" & currentBios
If currentBios >= 2.6 Then newBios = 1
StdOut.WriteLine "return value is: " & newBios
Next
here is the output
Simple Function to Test BIOS Version
SMBIOSMajorVersion=2
SMBIOSMinorVersion=4
major dot minor=2.4
currentBios=24
return value is: 1
Remove your error handling - it s probably suppressing an issue.
On Error Resume Next ' Not a good idea
For one thing you are comparing a string to a double in these lines:
minorFloat = "." & bios.SMBIOSMinorVersion
If bios.SMBIOSMajorVersion > 2 OR (bios.SMBIOSMajorVersion = 2 AND minorFloat >= .6) Then
Why not just convert the major.minor values to floating-point for your test? You're currently doing two separate tests, with one being a string vs float comparison, which is unusual.
Maybe try this instead?
currentBios = CDbl(bios.SMBIOSMajorVersion & "." & bios.SMBIOSMinorVersion)
If currentBios >= 2.6 Then newBios = 1
You have to be careful comparing floating-point values when math operations are involved but for literal values you'll be fine.
And, as already mentioned, remove On Error Resume Next or you may never know why it works on one PC but not another.

Classic ASP - passing a property as byref

In Classic ASP, I have an object, call it bob. This then has a property called name, with let and get methods.
I have a function as follows:
sub append(byref a, b)
a = a & b
end sub
This is simply to make it quicker to add text to a variable. I also have the same for prepend, just it is a = b & a. I know it would be simple to say bob.name = bob.name & "andy", but I tried using the above functions and neither of them work.
The way I am calling it is append bob.name, "andy". Can anyone see what is wrong with this?
Unfortunately this is a feature of VBScript. It is documented in http://msdn.microsoft.com/en-us/library/ee478101(v=vs.84).aspx under "Argument in a class". The alternative is to use a function. Here is an example illustrating the difference. You can run this from the command line using "cscript filename.vbs.
sub append (a, b)
a = a & b
end sub
function Appendix(a, b)
Appendix = a & b
end function
class ClsAA
dim m_b
dim m_a
end class
dim x(20)
a = "alpha"
b = "beta"
wscript.echo "variable works in both cases"
append a, b
wscript.echo "sub " & a
a = appendix(a, b)
wscript.echo "function " & a
x(10) = "delta"
wscript.echo "array works in both cases"
append x(10), b
wscript.echo "sub " & x(10)
x(10) = appendix( x(10), b)
wscript.echo "function " & x(10)
set objAA = new ClsAA
objAA.m_a = "gamma"
wscript.echo "Member only works in a function"
append objAA.m_a, b
wscript.echo "sub " & objAA.m_a
objAA.m_a = appendix(objAA.m_a, b)
wscript.echo "function " & objAA.m_a
Have you tried using with the keyword CALL:
call append (bob.name, "andy")
Classic ASP is fickel about ByRef and ByVal. By default it uses ByRef -- no reason to specify that. If you call a function with parenthesis (without the call), it will pass the variables as ByVal.
Alternatively, you could accomplish the same with:
function append(byref a, b)
append = a & b
end sub
bob.name = append(bob.name, "andy");
Good luck.
As this other answer correctly states, you are facing limitation of the language itself.
The only other option to achieve what you are after as far as I can see it, is to add such sub routine to the class itself:
Public Sub Append(propName, strValue)
Dim curValue, newValue
curValue = Eval("Me." & propName)
newValue = curValue & strValue
Execute("Me." & propName & " = """ & Replace(newValue, """", """""") & """")
End Sub
Then to use it:
bob.Append "name", "andy"
Less elegant, but working.