From: Philosophaie on 15 Apr 2010 09:18 How do you convert a string to a double? This does not work: string1 = Right(Left(data(k), 21), 2) double1 = CDbl(string1) It gives a "Type mismatch" error every time.
From: Mike H on 15 Apr 2010 09:34 Hi, I think you need to tell us what data(k) is holding but in the meantime isn't string1 = Mid(data(k), 20, 2) the same as string1 = Right(Left(data(k), 21), 2) and a bit more simple -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Philosophaie" wrote: > How do you convert a string to a double? This does not work: > > string1 = Right(Left(data(k), 21), 2) > double1 = CDbl(string1) > > It gives a "Type mismatch" error every time.
From: Martin Brown on 15 Apr 2010 09:34 Philosophaie wrote: > How do you convert a string to a double? This does not work: > > string1 = Right(Left(data(k), 21), 2) > double1 = CDbl(string1) > > It gives a "Type mismatch" error every time. What is the literal value of string1 ? string1 = "1.23456789E+123" double1 = CDbl(string1) Works fine every time. But string1 = "1.23456789 E+123" will fail every time. It doesn't tolerate embedded spaces in E format numbers. Regards, Martin Brown
From: Mike H on 15 Apr 2010 09:38 I meant to give an example. Suppose Data(k) is holding the value below then your code works fine. If the 2 character as positions 20 & 21 aren't numeric then 'Type Mismatch' data(k) = "abcdefghilklmnopqrs99vwyz" string1 = Mid(data(k), 20, 2) double1 = CDbl(string1) -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Mike H" wrote: > Hi, > > I think you need to tell us what data(k) is holding but in the meantime isn't > > string1 = Mid(data(k), 20, 2) > > the same as > string1 = Right(Left(data(k), 21), 2) > and a bit more simple > > -- > Mike > > When competing hypotheses are otherwise equal, adopt the hypothesis that > introduces the fewest assumptions while still sufficiently answering the > question. > > > "Philosophaie" wrote: > > > How do you convert a string to a double? This does not work: > > > > string1 = Right(Left(data(k), 21), 2) > > double1 = CDbl(string1) > > > > It gives a "Type mismatch" error every time.
From: JLGWhiz on 15 Apr 2010 12:26 The short answer is to make sure that String1 equates to a number without spaces. You cannot use CDbl with data that VBA sees as text. "Philosophaie" <Philosophaie(a)discussions.microsoft.com> wrote in message news:0630E72A-FEF3-43FA-A1F6-2EA4B407FD04(a)microsoft.com... > How do you convert a string to a double? This does not work: > > string1 = Right(Left(data(k), 21), 2) > double1 = CDbl(string1) > > It gives a "Type mismatch" error every time.
|
Pages: 1 Prev: Literal string in filter, not a date Next: Open and close workbooks |