Home All Groups Group Topic Archive Search About

Problem converting string to number: "Type mismatch" error

Author
10 Dec 2008 9:37 PM
Fred
For example:
Retrieving string from Windows registry and the result is:
lpString = "146636546522"

Now, when I do:
CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)

all is fine in IDE but compiled program shows 'Type mismatch' error.

What is wrong with that?
Thanks

Author
10 Dec 2008 10:28 PM
Richard Mueller [MVP]
Fred wrote;

> For example:
> Retrieving string from Windows registry and the result is:
> lpString = "146636546522"
>
> Now, when I do:
> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)
>
> all is fine in IDE but compiled program shows 'Type mismatch' error.
>
> What is wrong with that?
> Thanks
>

I don't get any errors. Are the variables lpString and CollectData declared
as Strings?

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Author
11 Dec 2008 12:41 AM
Fred
Yes. Both variables are declared as strings.
I posted wrong example, that.s why you cannot reproduce that error.
As I mentioned, the data came from Windows registry, and I tested that that
is the problem.
If I do: lname = "146636546522" there is not error, but if lname contains
the same number but retrieved from registry there is an error, as if it was
a different value. But it is not.
Below is the full code I am dealing with:
==========================
Dim lname As String
Dim CollectData As String
       lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
retrieved data 146636546522
       CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 - 39500)

Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
String, ByVal strDefault As String) As String
    Dim strBuf As String
    Dim lDataBufSize As Long
    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
lDataBufSize)
    If rtn = ERROR_SUCCESS Then
        strBuf = String(lDataBufSize, vbNullChar)
        rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal strBuf,
lDataBufSize)
        If rtn = ERROR_SUCCESS Then
            RegQueryStringValue = StripTerminator(strBuf): Exit Function
        End If
    End If
    RegQueryStringValue = strDefault
End Function
============
Thanks, Fred

Show quoteHide quote
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
> Fred wrote;
>
>> For example:
>> Retrieving string from Windows registry and the result is:
>> lpString = "146636546522"
>>
>> Now, when I do:
>> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)
>>
>> all is fine in IDE but compiled program shows 'Type mismatch' error.
>>
>> What is wrong with that?
>> Thanks
>>
>
> I don't get any errors. Are the variables lpString and CollectData
> declared as Strings?
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
Author
11 Dec 2008 1:37 AM
Randem
Try using Trim on the data from the registry. Perhaps it contains a space.
The next solution would be to break the line down into seperate lines to see
which part of the line is causing the problem.

Show quoteHide quote
"Fred" <anybody@any> wrote in message
news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
> Yes. Both variables are declared as strings.
> I posted wrong example, that.s why you cannot reproduce that error.
> As I mentioned, the data came from Windows registry, and I tested that
> that is the problem.
> If I do: lname = "146636546522" there is not error, but if lname contains
> the same number but retrieved from registry there is an error, as if it
> was a different value. But it is not.
> Below is the full code I am dealing with:
> ==========================
> Dim lname As String
> Dim CollectData As String
>       lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
> retrieved data 146636546522
>       CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 - 39500)
>
> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
> String, ByVal strDefault As String) As String
>    Dim strBuf As String
>    Dim lDataBufSize As Long
>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
> lDataBufSize)
>    If rtn = ERROR_SUCCESS Then
>        strBuf = String(lDataBufSize, vbNullChar)
>        rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal strBuf,
> lDataBufSize)
>        If rtn = ERROR_SUCCESS Then
>            RegQueryStringValue = StripTerminator(strBuf): Exit Function
>        End If
>    End If
>    RegQueryStringValue = strDefault
> End Function
> ============
> Thanks, Fred
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
>> Fred wrote;
>>
>>> For example:
>>> Retrieving string from Windows registry and the result is:
>>> lpString = "146636546522"
>>>
>>> Now, when I do:
>>> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)
>>>
>>> all is fine in IDE but compiled program shows 'Type mismatch' error.
>>>
>>> What is wrong with that?
>>> Thanks
>>>
>>
>> I don't get any errors. Are the variables lpString and CollectData
>> declared as Strings?
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>
>
Author
11 Dec 2008 2:04 AM
Fred
Trim does not help.
Also, the problem appears only in compiled executable.
In IDE there is not a problem.
Here is the content of lname directly copied from immediate window:
=========
?lname
146636546522
=========
Thanks,
Fred

Show quoteHide quote
"Randem" <newsgro***@randem.com> wrote in message
news:%234lt1DzWJHA.5476@TK2MSFTNGP03.phx.gbl...
> Try using Trim on the data from the registry. Perhaps it contains a space.
> The next solution would be to break the line down into seperate lines to
> see which part of the line is causing the problem.
>
> --
> Randem Systems
> Your Installation Specialist
> The Top Inno Setup Script Generator
> http://www.randem.com/innoscript.html
> http://www.rndem.com/installerproblems.html
> http://www.randem.com/vistainstalls.html
> http://www.financialtrainingservices.org
>
>
> "Fred" <anybody@any> wrote in message
> news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>> Yes. Both variables are declared as strings.
>> I posted wrong example, that.s why you cannot reproduce that error.
>> As I mentioned, the data came from Windows registry, and I tested that
>> that is the problem.
>> If I do: lname = "146636546522" there is not error, but if lname contains
>> the same number but retrieved from registry there is an error, as if it
>> was a different value. But it is not.
>> Below is the full code I am dealing with:
>> ==========================
>> Dim lname As String
>> Dim CollectData As String
>>       lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
>> retrieved data 146636546522
>>       CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 - 39500)
>>
>> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
>> String, ByVal strDefault As String) As String
>>    Dim strBuf As String
>>    Dim lDataBufSize As Long
>>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
>> lDataBufSize)
>>    If rtn = ERROR_SUCCESS Then
>>        strBuf = String(lDataBufSize, vbNullChar)
>>        rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal
>> strBuf, lDataBufSize)
>>        If rtn = ERROR_SUCCESS Then
>>            RegQueryStringValue = StripTerminator(strBuf): Exit Function
>>        End If
>>    End If
>>    RegQueryStringValue = strDefault
>> End Function
>> ============
>> Thanks, Fred
>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
>> message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
>>> Fred wrote;
>>>
>>>> For example:
>>>> Retrieving string from Windows registry and the result is:
>>>> lpString = "146636546522"
>>>>
>>>> Now, when I do:
>>>> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)
>>>>
>>>> all is fine in IDE but compiled program shows 'Type mismatch' error.
>>>>
>>>> What is wrong with that?
>>>> Thanks
>>>>
>>>
>>> I don't get any errors. Are the variables lpString and CollectData
>>> declared as Strings?
>>>
>>> --
>>> Richard Mueller
>>> MVP Directory Services
>>> Hilltop Lab - http://www.rlmueller.net
>>> --
>>>
>>>
>>
>>
>
>
Author
11 Dec 2008 2:11 AM
Randem
Did you try breaking the line into several to see exactly where the problem
lies?

Show quoteHide quote
"Fred" <anybody@any> wrote in message
news:uzurOTzWJHA.5612@TK2MSFTNGP04.phx.gbl...
> Trim does not help.
> Also, the problem appears only in compiled executable.
> In IDE there is not a problem.
> Here is the content of lname directly copied from immediate window:
> =========
> ?lname
> 146636546522
> =========
> Thanks,
> Fred
>
> "Randem" <newsgro***@randem.com> wrote in message
> news:%234lt1DzWJHA.5476@TK2MSFTNGP03.phx.gbl...
>> Try using Trim on the data from the registry. Perhaps it contains a
>> space. The next solution would be to break the line down into seperate
>> lines to see which part of the line is causing the problem.
>>
>> --
>> Randem Systems
>> Your Installation Specialist
>> The Top Inno Setup Script Generator
>> http://www.randem.com/innoscript.html
>> http://www.rndem.com/installerproblems.html
>> http://www.randem.com/vistainstalls.html
>> http://www.financialtrainingservices.org
>>
>>
>> "Fred" <anybody@any> wrote in message
>> news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>>> Yes. Both variables are declared as strings.
>>> I posted wrong example, that.s why you cannot reproduce that error.
>>> As I mentioned, the data came from Windows registry, and I tested that
>>> that is the problem.
>>> If I do: lname = "146636546522" there is not error, but if lname
>>> contains the same number but retrieved from registry there is an error,
>>> as if it was a different value. But it is not.
>>> Below is the full code I am dealing with:
>>> ==========================
>>> Dim lname As String
>>> Dim CollectData As String
>>>       lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
>>> retrieved data 146636546522
>>>       CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 -
>>> 39500)
>>>
>>> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
>>> String, ByVal strDefault As String) As String
>>>    Dim strBuf As String
>>>    Dim lDataBufSize As Long
>>>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
>>> lDataBufSize)
>>>    If rtn = ERROR_SUCCESS Then
>>>        strBuf = String(lDataBufSize, vbNullChar)
>>>        rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal
>>> strBuf, lDataBufSize)
>>>        If rtn = ERROR_SUCCESS Then
>>>            RegQueryStringValue = StripTerminator(strBuf): Exit Function
>>>        End If
>>>    End If
>>>    RegQueryStringValue = strDefault
>>> End Function
>>> ============
>>> Thanks, Fred
>>>
>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
>>> message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
>>>> Fred wrote;
>>>>
>>>>> For example:
>>>>> Retrieving string from Windows registry and the result is:
>>>>> lpString = "146636546522"
>>>>>
>>>>> Now, when I do:
>>>>> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)
>>>>>
>>>>> all is fine in IDE but compiled program shows 'Type mismatch' error.
>>>>>
>>>>> What is wrong with that?
>>>>> Thanks
>>>>>
>>>>
>>>> I don't get any errors. Are the variables lpString and CollectData
>>>> declared as Strings?
>>>>
>>>> --
>>>> Richard Mueller
>>>> MVP Directory Services
>>>> Hilltop Lab - http://www.rlmueller.net
>>>> --
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
11 Dec 2008 3:50 AM
Fred
I have tried this:
       For i = 1 To Len(lname)   => "Type mismatch"
       MsgBox "1"
       MsgBox CStr(CDbl(Left(lname, i)))
       MsgBox "2"
       Next
Fred

Show quoteHide quote
"Randem" <newsgro***@randem.com> wrote in message
news:u7PTDXzWJHA.1328@TK2MSFTNGP02.phx.gbl...
> Did you try breaking the line into several to see exactly where the
> problem lies?
>
> --
> Randem Systems
> Your Installation Specialist
> The Top Inno Setup Script Generator
> http://www.randem.com/innoscript.html
> http://www.rndem.com/installerproblems.html
> http://www.randem.com/vistainstalls.html
> http://www.financialtrainingservices.org
>
>
> "Fred" <anybody@any> wrote in message
> news:uzurOTzWJHA.5612@TK2MSFTNGP04.phx.gbl...
>> Trim does not help.
>> Also, the problem appears only in compiled executable.
>> In IDE there is not a problem.
>> Here is the content of lname directly copied from immediate window:
>> =========
>> ?lname
>> 146636546522
>> =========
>> Thanks,
>> Fred
>>
>> "Randem" <newsgro***@randem.com> wrote in message
>> news:%234lt1DzWJHA.5476@TK2MSFTNGP03.phx.gbl...
>>> Try using Trim on the data from the registry. Perhaps it contains a
>>> space. The next solution would be to break the line down into seperate
>>> lines to see which part of the line is causing the problem.
>>>
>>> --
>>> Randem Systems
>>> Your Installation Specialist
>>> The Top Inno Setup Script Generator
>>> http://www.randem.com/innoscript.html
>>> http://www.rndem.com/installerproblems.html
>>> http://www.randem.com/vistainstalls.html
>>> http://www.financialtrainingservices.org
>>>
>>>
>>> "Fred" <anybody@any> wrote in message
>>> news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>>>> Yes. Both variables are declared as strings.
>>>> I posted wrong example, that.s why you cannot reproduce that error.
>>>> As I mentioned, the data came from Windows registry, and I tested that
>>>> that is the problem.
>>>> If I do: lname = "146636546522" there is not error, but if lname
>>>> contains the same number but retrieved from registry there is an error,
>>>> as if it was a different value. But it is not.
>>>> Below is the full code I am dealing with:
>>>> ==========================
>>>> Dim lname As String
>>>> Dim CollectData As String
>>>>       lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
>>>> retrieved data 146636546522
>>>>       CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 -
>>>> 39500)
>>>>
>>>> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
>>>> String, ByVal strDefault As String) As String
>>>>    Dim strBuf As String
>>>>    Dim lDataBufSize As Long
>>>>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
>>>> lDataBufSize)
>>>>    If rtn = ERROR_SUCCESS Then
>>>>        strBuf = String(lDataBufSize, vbNullChar)
>>>>        rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal
>>>> strBuf, lDataBufSize)
>>>>        If rtn = ERROR_SUCCESS Then
>>>>            RegQueryStringValue = StripTerminator(strBuf): Exit Function
>>>>        End If
>>>>    End If
>>>>    RegQueryStringValue = strDefault
>>>> End Function
>>>> ============
>>>> Thanks, Fred
>>>>
>>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote
>>>> in message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
>>>>> Fred wrote;
>>>>>
>>>>>> For example:
>>>>>> Retrieving string from Windows registry and the result is:
>>>>>> lpString = "146636546522"
>>>>>>
>>>>>> Now, when I do:
>>>>>> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)
>>>>>>
>>>>>> all is fine in IDE but compiled program shows 'Type mismatch' error.
>>>>>>
>>>>>> What is wrong with that?
>>>>>> Thanks
>>>>>>
>>>>>
>>>>> I don't get any errors. Are the variables lpString and CollectData
>>>>> declared as Strings?
>>>>>
>>>>> --
>>>>> Richard Mueller
>>>>> MVP Directory Services
>>>>> Hilltop Lab - http://www.rlmueller.net
>>>>> --
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
11 Dec 2008 6:06 AM
Randem
How is lname defined?

Show quoteHide quote
"Fred" <anybody@any> wrote in message
news:OV3LTO0WJHA.4284@TK2MSFTNGP02.phx.gbl...
>I have tried this:
>       For i = 1 To Len(lname)   => "Type mismatch"
>       MsgBox "1"
>       MsgBox CStr(CDbl(Left(lname, i)))
>       MsgBox "2"
>       Next
> Fred
>
> "Randem" <newsgro***@randem.com> wrote in message
> news:u7PTDXzWJHA.1328@TK2MSFTNGP02.phx.gbl...
>> Did you try breaking the line into several to see exactly where the
>> problem lies?
>>
>> --
>> Randem Systems
>> Your Installation Specialist
>> The Top Inno Setup Script Generator
>> http://www.randem.com/innoscript.html
>> http://www.rndem.com/installerproblems.html
>> http://www.randem.com/vistainstalls.html
>> http://www.financialtrainingservices.org
>>
>>
>> "Fred" <anybody@any> wrote in message
>> news:uzurOTzWJHA.5612@TK2MSFTNGP04.phx.gbl...
>>> Trim does not help.
>>> Also, the problem appears only in compiled executable.
>>> In IDE there is not a problem.
>>> Here is the content of lname directly copied from immediate window:
>>> =========
>>> ?lname
>>> 146636546522
>>> =========
>>> Thanks,
>>> Fred
>>>
>>> "Randem" <newsgro***@randem.com> wrote in message
>>> news:%234lt1DzWJHA.5476@TK2MSFTNGP03.phx.gbl...
>>>> Try using Trim on the data from the registry. Perhaps it contains a
>>>> space. The next solution would be to break the line down into seperate
>>>> lines to see which part of the line is causing the problem.
>>>>
>>>> --
>>>> Randem Systems
>>>> Your Installation Specialist
>>>> The Top Inno Setup Script Generator
>>>> http://www.randem.com/innoscript.html
>>>> http://www.rndem.com/installerproblems.html
>>>> http://www.randem.com/vistainstalls.html
>>>> http://www.financialtrainingservices.org
>>>>
>>>>
>>>> "Fred" <anybody@any> wrote in message
>>>> news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>>>>> Yes. Both variables are declared as strings.
>>>>> I posted wrong example, that.s why you cannot reproduce that error.
>>>>> As I mentioned, the data came from Windows registry, and I tested that
>>>>> that is the problem.
>>>>> If I do: lname = "146636546522" there is not error, but if lname
>>>>> contains the same number but retrieved from registry there is an
>>>>> error, as if it was a different value. But it is not.
>>>>> Below is the full code I am dealing with:
>>>>> ==========================
>>>>> Dim lname As String
>>>>> Dim CollectData As String
>>>>>       lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
>>>>> retrieved data 146636546522
>>>>>       CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 -
>>>>> 39500)
>>>>>
>>>>> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
>>>>> String, ByVal strDefault As String) As String
>>>>>    Dim strBuf As String
>>>>>    Dim lDataBufSize As Long
>>>>>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
>>>>> lDataBufSize)
>>>>>    If rtn = ERROR_SUCCESS Then
>>>>>        strBuf = String(lDataBufSize, vbNullChar)
>>>>>        rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal
>>>>> strBuf, lDataBufSize)
>>>>>        If rtn = ERROR_SUCCESS Then
>>>>>            RegQueryStringValue = StripTerminator(strBuf): Exit
>>>>> Function
>>>>>        End If
>>>>>    End If
>>>>>    RegQueryStringValue = strDefault
>>>>> End Function
>>>>> ============
>>>>> Thanks, Fred
>>>>>
>>>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote
>>>>> in message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
>>>>>> Fred wrote;
>>>>>>
>>>>>>> For example:
>>>>>>> Retrieving string from Windows registry and the result is:
>>>>>>> lpString = "146636546522"
>>>>>>>
>>>>>>> Now, when I do:
>>>>>>> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 -
>>>>>>> 39500)
>>>>>>>
>>>>>>> all is fine in IDE but compiled program shows 'Type mismatch' error.
>>>>>>>
>>>>>>> What is wrong with that?
>>>>>>> Thanks
>>>>>>>
>>>>>>
>>>>>> I don't get any errors. Are the variables lpString and CollectData
>>>>>> declared as Strings?
>>>>>>
>>>>>> --
>>>>>> Richard Mueller
>>>>>> MVP Directory Services
>>>>>> Hilltop Lab - http://www.rlmueller.net
>>>>>> --
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
11 Dec 2008 6:08 AM
Randem
Ok, try this Msgbox lname after you get the value from the registry.

Show quoteHide quote
"Fred" <anybody@any> wrote in message
news:OV3LTO0WJHA.4284@TK2MSFTNGP02.phx.gbl...
>I have tried this:
>       For i = 1 To Len(lname)   => "Type mismatch"
>       MsgBox "1"
>       MsgBox CStr(CDbl(Left(lname, i)))
>       MsgBox "2"
>       Next
> Fred
>
> "Randem" <newsgro***@randem.com> wrote in message
> news:u7PTDXzWJHA.1328@TK2MSFTNGP02.phx.gbl...
>> Did you try breaking the line into several to see exactly where the
>> problem lies?
>>
>> --
>> Randem Systems
>> Your Installation Specialist
>> The Top Inno Setup Script Generator
>> http://www.randem.com/innoscript.html
>> http://www.rndem.com/installerproblems.html
>> http://www.randem.com/vistainstalls.html
>> http://www.financialtrainingservices.org
>>
>>
>> "Fred" <anybody@any> wrote in message
>> news:uzurOTzWJHA.5612@TK2MSFTNGP04.phx.gbl...
>>> Trim does not help.
>>> Also, the problem appears only in compiled executable.
>>> In IDE there is not a problem.
>>> Here is the content of lname directly copied from immediate window:
>>> =========
>>> ?lname
>>> 146636546522
>>> =========
>>> Thanks,
>>> Fred
>>>
>>> "Randem" <newsgro***@randem.com> wrote in message
>>> news:%234lt1DzWJHA.5476@TK2MSFTNGP03.phx.gbl...
>>>> Try using Trim on the data from the registry. Perhaps it contains a
>>>> space. The next solution would be to break the line down into seperate
>>>> lines to see which part of the line is causing the problem.
>>>>
>>>> --
>>>> Randem Systems
>>>> Your Installation Specialist
>>>> The Top Inno Setup Script Generator
>>>> http://www.randem.com/innoscript.html
>>>> http://www.rndem.com/installerproblems.html
>>>> http://www.randem.com/vistainstalls.html
>>>> http://www.financialtrainingservices.org
>>>>
>>>>
>>>> "Fred" <anybody@any> wrote in message
>>>> news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>>>>> Yes. Both variables are declared as strings.
>>>>> I posted wrong example, that.s why you cannot reproduce that error.
>>>>> As I mentioned, the data came from Windows registry, and I tested that
>>>>> that is the problem.
>>>>> If I do: lname = "146636546522" there is not error, but if lname
>>>>> contains the same number but retrieved from registry there is an
>>>>> error, as if it was a different value. But it is not.
>>>>> Below is the full code I am dealing with:
>>>>> ==========================
>>>>> Dim lname As String
>>>>> Dim CollectData As String
>>>>>       lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
>>>>> retrieved data 146636546522
>>>>>       CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 -
>>>>> 39500)
>>>>>
>>>>> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
>>>>> String, ByVal strDefault As String) As String
>>>>>    Dim strBuf As String
>>>>>    Dim lDataBufSize As Long
>>>>>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
>>>>> lDataBufSize)
>>>>>    If rtn = ERROR_SUCCESS Then
>>>>>        strBuf = String(lDataBufSize, vbNullChar)
>>>>>        rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal
>>>>> strBuf, lDataBufSize)
>>>>>        If rtn = ERROR_SUCCESS Then
>>>>>            RegQueryStringValue = StripTerminator(strBuf): Exit
>>>>> Function
>>>>>        End If
>>>>>    End If
>>>>>    RegQueryStringValue = strDefault
>>>>> End Function
>>>>> ============
>>>>> Thanks, Fred
>>>>>
>>>>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote
>>>>> in message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
>>>>>> Fred wrote;
>>>>>>
>>>>>>> For example:
>>>>>>> Retrieving string from Windows registry and the result is:
>>>>>>> lpString = "146636546522"
>>>>>>>
>>>>>>> Now, when I do:
>>>>>>> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 -
>>>>>>> 39500)
>>>>>>>
>>>>>>> all is fine in IDE but compiled program shows 'Type mismatch' error.
>>>>>>>
>>>>>>> What is wrong with that?
>>>>>>> Thanks
>>>>>>>
>>>>>>
>>>>>> I don't get any errors. Are the variables lpString and CollectData
>>>>>> declared as Strings?
>>>>>>
>>>>>> --
>>>>>> Richard Mueller
>>>>>> MVP Directory Services
>>>>>> Hilltop Lab - http://www.rlmueller.net
>>>>>> --
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
11 Dec 2008 2:17 AM
Larry Serflaten
"Fred" <anybody@any> wrote
> Trim does not help.
> Also, the problem appears only in compiled executable.
> In IDE there is not a problem.
> Here is the content of lname directly copied from immediate window:

Did you try using Val() instead of CDbl()?

LFS
Author
11 Dec 2008 3:28 AM
Fred
Val returns 0 in compiled code.
In IDE displays the correct value.
       lname = Trim(lname)
       MsgBox CStr(Val(lname))  --->displays 0
       MsgBox CStr(CDbl(lname)) ----> "Type mismatch"
thanks,
F

Show quoteHide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:OijNWazWJHA.5364@TK2MSFTNGP05.phx.gbl...
>
> "Fred" <anybody@any> wrote
>> Trim does not help.
>> Also, the problem appears only in compiled executable.
>> In IDE there is not a problem.
>> Here is the content of lname directly copied from immediate window:
>
> Did you try using Val() instead of CDbl()?
>
> LFS
>
>
Author
11 Dec 2008 3:36 AM
Bob Butler
"Fred" <anybody@any> wrote in message
news:epz5QC0WJHA.5064@TK2MSFTNGP02.phx.gbl...
> Val returns 0 in compiled code.
> In IDE displays the correct value.
>       lname = Trim(lname)
>       MsgBox CStr(Val(lname))  --->displays 0
>       MsgBox CStr(CDbl(lname)) ----> "Type mismatch"

A couple of things to try

msgbox typename(lname) & vbcrlf & vartype(lname)
msgbox val("" & lname)
msgbox cdbl("" & lname)

for x=1 to len(lname)
  t=t & x & ":" & asc(mid$(lname,x,1)) & vbcrlf
next
msgbox t
Author
11 Dec 2008 3:58 AM
Fred
MsgBox TypeName(lname) & vbCrLf & VarType(lname)
returns:
String
8
MsgBox Val("" & lname)--->returns: 0
MsgBox CDbl("" & lname) ---> "Type mismatch"
For i = 1 To Len(lname) ---> "Type mismatch"
......

Thanks, F

Show quoteHide quote
"Bob Butler" <noway@nospam.ever> wrote in message
news:O5$GfI0WJHA.5364@TK2MSFTNGP05.phx.gbl...
>
> "Fred" <anybody@any> wrote in message
> news:epz5QC0WJHA.5064@TK2MSFTNGP02.phx.gbl...
>> Val returns 0 in compiled code.
>> In IDE displays the correct value.
>>       lname = Trim(lname)
>>       MsgBox CStr(Val(lname))  --->displays 0
>>       MsgBox CStr(CDbl(lname)) ----> "Type mismatch"
>
> A couple of things to try
>
> msgbox typename(lname) & vbcrlf & vartype(lname)
> msgbox val("" & lname)
> msgbox cdbl("" & lname)
>
> for x=1 to len(lname)
>  t=t & x & ":" & asc(mid$(lname,x,1)) & vbcrlf
> next
> msgbox t
>
Author
11 Dec 2008 9:13 PM
Ken Halter
"Fred" <anybody@any> wrote in message
news:O00T8S0WJHA.1532@TK2MSFTNGP03.phx.gbl...
> MsgBox TypeName(lname) & vbCrLf & VarType(lname)
> returns:
> String
> 8
> MsgBox Val("" & lname)--->returns: 0
> MsgBox CDbl("" & lname) ---> "Type mismatch"
> For i = 1 To Len(lname) ---> "Type mismatch"

One more thing to try before losing hair...

lname = lname & ".0" 'Add a decimal plus a zero, to make sure there's no
possibility of data type confusion.

Len(lname) should work, if lname is actually a string. Have you tried
LenB(lname)?

Hopefully, Option Explicit is at the top of each module, so we're not
dealing with undeclared variables and scope issues
Author
11 Dec 2008 9:15 PM
Ken Halter
"Fred" <anybody@any> wrote in message
news:O00T8S0WJHA.1532@TK2MSFTNGP03.phx.gbl...
> MsgBox TypeName(lname) & vbCrLf & VarType(lname)
> returns:
> String
> 8

Forgot to add... to eliminate any registry I/O problems (as well as Unicode
vs Ansi), here's a drop-in class module that gives you....

Complete Registry control
http://www.vbaccelerator.com/home/VB/Code/Libraries/Registry_and_Ini_Files/Complete_Registry_Control/article.asp


....and usage wise, it couldn't get much easier.
Author
11 Dec 2008 3:38 AM
Bill McCarthy
What OS ?  Is this Vista and perhaps you are seeing different values due to
different permissions?

Show quoteHide quote
"Fred" <anybody@any> wrote in message
news:epz5QC0WJHA.5064@TK2MSFTNGP02.phx.gbl...
> Val returns 0 in compiled code.
> In IDE displays the correct value.
>       lname = Trim(lname)
>       MsgBox CStr(Val(lname))  --->displays 0
>       MsgBox CStr(CDbl(lname)) ----> "Type mismatch"
> thanks,
> F
>
> "Larry Serflaten" <serfla***@usinternet.com> wrote in message
> news:OijNWazWJHA.5364@TK2MSFTNGP05.phx.gbl...
>>
>> "Fred" <anybody@any> wrote
>>> Trim does not help.
>>> Also, the problem appears only in compiled executable.
>>> In IDE there is not a problem.
>>> Here is the content of lname directly copied from immediate window:
>>
>> Did you try using Val() instead of CDbl()?
>>
>> LFS
>>
>>
>
>
Author
11 Dec 2008 3:52 AM
Fred
Win XP

Show quoteHide quote
"Bill McCarthy" <B***@localhost.com> wrote in message
news:e$BXyI0WJHA.5760@TK2MSFTNGP05.phx.gbl...
> What OS ?  Is this Vista and perhaps you are seeing different values due
> to different permissions?
>
> "Fred" <anybody@any> wrote in message
> news:epz5QC0WJHA.5064@TK2MSFTNGP02.phx.gbl...
>> Val returns 0 in compiled code.
>> In IDE displays the correct value.
>>       lname = Trim(lname)
>>       MsgBox CStr(Val(lname))  --->displays 0
>>       MsgBox CStr(CDbl(lname)) ----> "Type mismatch"
>> thanks,
>> F
>>
>> "Larry Serflaten" <serfla***@usinternet.com> wrote in message
>> news:OijNWazWJHA.5364@TK2MSFTNGP05.phx.gbl...
>>>
>>> "Fred" <anybody@any> wrote
>>>> Trim does not help.
>>>> Also, the problem appears only in compiled executable.
>>>> In IDE there is not a problem.
>>>> Here is the content of lname directly copied from immediate window:
>>>
>>> Did you try using Val() instead of CDbl()?
>>>
>>> LFS
>>>
>>>
>>
>>
>
Author
11 Dec 2008 3:59 AM
Bill McCarthy
Hi Fred,

Well everything points to a problem with the value as you are getting it
form the registry. If it isn't different user accounts, different
permissions,  and not a compiler directive, eg #If DEBUG, then it's got to
be something about the values you are using to get the registry key.


Show quoteHide quote
"Fred" <anybody@any> wrote in message
news:e2YwyP0WJHA.1336@TK2MSFTNGP02.phx.gbl...
> Win XP
>
> "Bill McCarthy" <B***@localhost.com> wrote in message
> news:e$BXyI0WJHA.5760@TK2MSFTNGP05.phx.gbl...
>> What OS ?  Is this Vista and perhaps you are seeing different values due
>> to different permissions?
>>
>> "Fred" <anybody@any> wrote in message
>> news:epz5QC0WJHA.5064@TK2MSFTNGP02.phx.gbl...
>>> Val returns 0 in compiled code.
>>> In IDE displays the correct value.
>>>       lname = Trim(lname)
>>>       MsgBox CStr(Val(lname))  --->displays 0
>>>       MsgBox CStr(CDbl(lname)) ----> "Type mismatch"
>>> thanks,
>>> F
>>>
>>> "Larry Serflaten" <serfla***@usinternet.com> wrote in message
>>> news:OijNWazWJHA.5364@TK2MSFTNGP05.phx.gbl...
>>>>
>>>> "Fred" <anybody@any> wrote
>>>>> Trim does not help.
>>>>> Also, the problem appears only in compiled executable.
>>>>> In IDE there is not a problem.
>>>>> Here is the content of lname directly copied from immediate window:
>>>>
>>>> Did you try using Val() instead of CDbl()?
>>>>
>>>> LFS
>>>>
>>>>
>>>
>>>
>>
>
>
Author
11 Dec 2008 2:13 AM
Larry Serflaten
Show quote Hide quote
"Fred" <anybody@any> wrote in message news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
> Yes. Both variables are declared as strings.
> I posted wrong example, that.s why you cannot reproduce that error.
> As I mentioned, the data came from Windows registry, and I tested that that
> is the problem.
> If I do: lname = "146636546522" there is not error, but if lname contains
> the same number but retrieved from registry there is an error, as if it was
> a different value. But it is not.
> Below is the full code I am dealing with:
> ==========================
>  Dim lname As String
>  Dim CollectData As String
>        lname = RegQueryStringValue(phkResult, "Data", vbNullString) '
> retrieved data 146636546522
>        CollectData = CollectData & vbCrLf & CStr(CDbl(lname) / 37 - 39500)
>
> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
> String, ByVal strDefault As String) As String
>     Dim strBuf As String
>     Dim lDataBufSize As Long
>     rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
> lDataBufSize)
>     If rtn = ERROR_SUCCESS Then
>         strBuf = String(lDataBufSize, vbNullChar)
>         rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal strBuf,
> lDataBufSize)
>         If rtn = ERROR_SUCCESS Then
>             RegQueryStringValue = StripTerminator(strBuf): Exit Function
>         End If
>     End If
>     RegQueryStringValue = strDefault
> End Function
> ============
> Thanks, Fred
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:%23BT3kaxWJHA.552@TK2MSFTNGP06.phx.gbl...
> > Fred wrote;
> >
> >> For example:
> >> Retrieving string from Windows registry and the result is:
> >> lpString = "146636546522"
> >>
> >> Now, when I do:
> >> CollectData = CollectData & vbCrLf & CStr(CDbl(lpString)/ 37 - 39500)
> >>
> >> all is fine in IDE but compiled program shows 'Type mismatch' error.
> >>
> >> What is wrong with that?
> >> Thanks
> >>
> >
> > I don't get any errors. Are the variables lpString and CollectData
> > declared as Strings?
> >
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> >
>
>
Author
11 Dec 2008 3:56 AM
expvb
"Fred" <anybody@any> wrote in message
news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
> lDataBufSize)

What's the data type of the value using Registry Editor? Is it shown as
REG_SZ, or something else?

Note that RegQueryValueEx() doesn't convert the value for you. You don't
specify REG_SZ to it. lpType is an [out] parameter, meaning that it's a
ByRef parameter that you provide it with a variable(or null), and it returns
the type in that variable, but it doesn't convert it. In your case, with the
way it's written, VB6 creates a temporary location in memory, and pass the
reference to that location to the function. The function changes the value,
but it's discarded. So essentially specifying REG_SZ in that parameter is
ignored. Use ByVal 0& instead, or pass a Long var to see what the type is
actually is(Same as RegEdit).
Author
11 Dec 2008 4:00 AM
Fred
It shows REG_SZ
Fred

Show quoteHide quote
"expvb" <nob***@cox.net> wrote in message
news:%23%23xhwR0WJHA.5108@TK2MSFTNGP04.phx.gbl...
> "Fred" <anybody@any> wrote in message
> news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
>> lDataBufSize)
>
> What's the data type of the value using Registry Editor? Is it shown as
> REG_SZ, or something else?
>
> Note that RegQueryValueEx() doesn't convert the value for you. You don't
> specify REG_SZ to it. lpType is an [out] parameter, meaning that it's a
> ByRef parameter that you provide it with a variable(or null), and it
> returns the type in that variable, but it doesn't convert it. In your
> case, with the way it's written, VB6 creates a temporary location in
> memory, and pass the reference to that location to the function. The
> function changes the value, but it's discarded. So essentially specifying
> REG_SZ in that parameter is ignored. Use ByVal 0& instead, or pass a Long
> var to see what the type is actually is(Same as RegEdit).
>
>
Author
11 Dec 2008 4:05 AM
Fred
BTW, it was my code which created that value in the first place.
Fred

Show quoteHide quote
"Fred" <anybody@any> wrote in message
news:e8VK3T0WJHA.1184@TK2MSFTNGP05.phx.gbl...
> It shows REG_SZ
> Fred
>
> "expvb" <nob***@cox.net> wrote in message
> news:%23%23xhwR0WJHA.5108@TK2MSFTNGP04.phx.gbl...
>> "Fred" <anybody@any> wrote in message
>> news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl...
>>>    rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&,
>>> lDataBufSize)
>>
>> What's the data type of the value using Registry Editor? Is it shown as
>> REG_SZ, or something else?
>>
>> Note that RegQueryValueEx() doesn't convert the value for you. You don't
>> specify REG_SZ to it. lpType is an [out] parameter, meaning that it's a
>> ByRef parameter that you provide it with a variable(or null), and it
>> returns the type in that variable, but it doesn't convert it. In your
>> case, with the way it's written, VB6 creates a temporary location in
>> memory, and pass the reference to that location to the function. The
>> function changes the value, but it's discarded. So essentially specifying
>> REG_SZ in that parameter is ignored. Use ByVal 0& instead, or pass a Long
>> var to see what the type is actually is(Same as RegEdit).
>>
>>
>
>
Author
11 Dec 2008 4:32 AM
expvb
"Fred" <anybody@any> wrote in message
news:%23gibDX0WJHA.1444@TK2MSFTNGP02.phx.gbl...
> BTW, it was my code which created that value in the first place.

It seems that the variable area in memory is corrupted. Post the function
that sets the value, also, try increasing the buffer size by one character
in the call to String function(inside RegQueryStringValue).

But before trying the above, delete the value from the registry, and
re-create it using RegEdit, and see if the problem persists.
Author
11 Dec 2008 5:23 AM
David Youngblood
"Fred" <anybody@any> wrote...
> ==========================
> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
> String, ByVal strDefault As String) As String

Where did you get that declare? Below is a declare found on microsoft. I did
not try it, but you might. The comments say that the string value is
returned in the strData parameter.

Public Function RegQueryStringValue(ByVal hKey As Long, _
ByVal strValueName As String, strData As String) As Boolean
'-----------------------------------------------------------
' This retrieves the string data for a named
' (strValueName = name) or for an unnamed (Len(strValueName) = 0)
' value in a registry key. If the named value
' exists, but its data is not a string, this function
' fails.
'
' Returns: True on success, else False
'  On success, strData is set to the string data value.

David
Author
11 Dec 2008 5:35 AM
David Youngblood
"David Youngblood" <d**@flash.net> wrote...
> "Fred" <anybody@any> wrote...
>> ==========================
>> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As
>> String, ByVal strDefault As String) As String

Disregard my post, I somehow saw that as an API function. Wrong again...