converting a String to a value that could be manipulated
converting a String to a value that could be manipulated
(OP)
I need to find a way to take, $4,500.00(String) and convert it to 4500. MyValue=MyTerminal.GetString 14, 18.
Is there an easy way to do this? I have already created the hard, long way. My code can sometimes be long-winded like my brother-in-law. I have tried to wrap my head around it, but my code consists of determining the size of the amount, then taking it apart piece by piece, then putting it back together.
Is there an easy way to do this? I have already created the hard, long way. My code can sometimes be long-winded like my brother-in-law. I have tried to wrap my head around it, but my code consists of determining the size of the amount, then taking it apart piece by piece, then putting it back together.
RE: converting a String to a value that could be manipulated
hi,
I don't know if Extra VB has the CCur() function to convert to currency. Even CDbl() would work.
[code]
Dim s As String, c As Currency
s = "$45,000.24"
c = CCur(s)
[code]
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: converting a String to a value that could be manipulated
I believe I had tried something similar in the past. I have not tried the currency call though, and I will try on monday or tuesday and get back to you. I gave up when it kept coming back with 0.
RE: converting a String to a value that could be manipulated
I tried it, this is what I ran.
CODE
dim c As Currency, S As String, d As Double
s="$45,000.00"
c=CCur(s)
d=CDbl(c)
msgbox c & " " & d
End Sub
bot c and d returned 45
so I tried s="$45,454.00"
same result.
ccur does not like the ","(comma)or the"."(period)
removing the comma gave, 45454
any other thoughts you might have?
RE: converting a String to a value that could be manipulated
That must be a limitation of Extra BASIC.
I have no such issues in Microsoft applications VBA.
So try this...
CODE
dim c As Currency, S As String, d As Double
s="$45,000.00"
s = left(s, instr(s,",")-1) & right(s, len(s)-instr(s,","))
c=CCur(s)
d=CDbl(c)
msgbox c & " " & d
End Sub
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: converting a String to a value that could be manipulated
Your suggestion did the trick. Your code is a lot clearer, in just one line the I could do in 5 or 6. I think I am am finally learning here. The help files are great, but its nice to know there's a place I could go that makes things seem that much clearer. Eurika!
Thanks again, Skip:0)
Ted,