Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting a String to a value that could be manipulated 1

Status
Not open for further replies.

tedb13

Technical User
Jan 20, 2011
41
CA
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.
 


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,
[sub]
[glasses]Just traded in my old subtlety...
[b]for a NUANCE![/b][tongue][/sub]
 
Hi Skip,

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.
 
Hi Skip,

I tried it, this is what I ran.

Code:
Sub main

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?
 


That must be a limitation of Extra BASIC.

I have no such issues in Microsoft applications VBA.

So try this...
Code:
Sub main

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,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hey Skip,

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,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top