rossh1977
asked on
split formField string by carriage return
Hi i'm trying to split a formField string by a carriage return:-
Sub splitString()
Dim Items As Variant
Dim desc As String
desc = ActiveDocument.FormFields( "txt_descr iption").R esult
Items = Split(desc, vbCrLf)
For i = 0 To UBound(Items)
MsgBox Items(i)
Next i
End Sub
the vbCrLf is not working?
Also i want to convert items in the array from string to a currency type?
Thanks
Ross
Sub splitString()
Dim Items As Variant
Dim desc As String
desc = ActiveDocument.FormFields(
Items = Split(desc, vbCrLf)
For i = 0 To UBound(Items)
MsgBox Items(i)
Next i
End Sub
the vbCrLf is not working?
Also i want to convert items in the array from string to a currency type?
Thanks
Ross
Currency type is rarely used in VB.
But you can do it with CCur, though it may not achive your wider objective.
Dim c As Currency
c = CCur("£1234")
But you can do it with CCur, though it may not achive your wider objective.
Dim c As Currency
c = CCur("£1234")
I guessed that you are in UK. In fact he optional leading currency sign must match your local settings, otherwise you will get a Type Mismatch error.
ASKER
Thanks again Graham, I've gotten this far with this method which i'd like to get working but i'm going to look more closley at your other solution
Sub splitString()
Dim vQuantity As Variant
Dim vEach As Variant
Dim txt_item As String
Dim txt_each As String
txt_quantity = ActiveDocument.FormFields( "txt_quant ity").Resu lt
txt_each = ActiveDocument.FormFields( "txt_each" ).Result
vQuantity = Split(txt_quantity, vbCr)
vEach = Split(txt_each, vbCr)
For i = 0 To UBound(vQuantity)
ActiveDocument.FormFields( "txt_total ").Result = CCur(vEach(i)) * CInt(vQuantity(i)) & vbCr
Next i
End Sub
If i print this in a msgBox it works, but using the above only enters the sum of the last each and quantity in the arrays?
Thanks
Ross
Sub splitString()
Dim vQuantity As Variant
Dim vEach As Variant
Dim txt_item As String
Dim txt_each As String
txt_quantity = ActiveDocument.FormFields(
txt_each = ActiveDocument.FormFields(
vQuantity = Split(txt_quantity, vbCr)
vEach = Split(txt_each, vbCr)
For i = 0 To UBound(vQuantity)
ActiveDocument.FormFields(
Next i
End Sub
If i print this in a msgBox it works, but using the above only enters the sum of the last each and quantity in the arrays?
Thanks
Ross
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again Graham works a treat, although the carriage return displays as small box, but i'll play about with it.
Thanks again excellent help!
Ross
Thanks again excellent help!
Ross
I'm not sure why carriage returns display as boxes, they don't for me.
They are interpreted by Word as paragraphs, causing a new line and displayed as ¶ if they are set to be visible.
They are interpreted by Word as paragraphs, causing a new line and displayed as ¶ if they are set to be visible.
Try vbCr.