|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem converting string to number: "Type mismatch" errorFor 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 Fred wrote;
> For example: I don't get any errors. Are the variables lpString and CollectData declared > 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 > as Strings? 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 > -- > > 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 quoteRandem 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 >> -- >> >> > > 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 >>> -- >>> >>> >> >> > > Did you try breaking the line into several to see exactly where the problem
lies? -- Show quoteHide quoteRandem 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 >>>> -- >>>> >>>> >>> >>> >> >> > > 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 >>>>> -- >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > How is lname defined?
-- Show quoteHide quoteRandem 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: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 >>>>>> -- >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > Ok, try this Msgbox lname after you get the value from the registry.
-- Show quoteHide quoteRandem 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: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 >>>>>> -- >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > "Fred" <anybody@any> wrote Did you try using Val() instead of CDbl()?> 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: LFS 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 > > "Fred" <anybody@any> wrote in message A couple of things to trynews: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" 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 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 > "Fred" <anybody@any> wrote in message One more thing to try before losing hair...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" 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 "Fred" <anybody@any> wrote in message Forgot to add... to eliminate any registry I/O problems (as well as Unicode news:O00T8S0WJHA.1532@TK2MSFTNGP03.phx.gbl... > MsgBox TypeName(lname) & vbCrLf & VarType(lname) > returns: > String > 8 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. 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 >> >> > > 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 >>> >>> >> >> > 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 >>>> >>>> >>> >>> >> > >
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 > > -- > > > > > > "Fred" <anybody@any> wrote in message What's the data type of the value using Registry Editor? Is it shown as news:eALlClyWJHA.4412@TK2MSFTNGP03.phx.gbl... > rtn = RegQueryValueEx(hKey, strValueName, 0&, REG_SZ, ByVal 0&, > lDataBufSize) 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). 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). > > 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). >> >> > > "Fred" <anybody@any> wrote in message It seems that the variable area in memory is corrupted. Post the function news:%23gibDX0WJHA.1444@TK2MSFTNGP02.phx.gbl... > BTW, it was my code which created that value in the first place. 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. "Fred" <anybody@any> wrote... Where did you get that declare? Below is a declare found on microsoft. I did > ========================== > Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As > String, ByVal strDefault As String) As String 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 "David Youngblood" <d**@flash.net> wrote... Disregard my post, I somehow saw that as an API function. Wrong again...> "Fred" <anybody@any> wrote... >> ========================== >> Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As >> String, ByVal strDefault As String) As String
VB6: How to initialize a variable as a array structure / structure (type) array (see example)
Screen resolution and Image Anchors and Objects How many characters wide should posts be? Shelling to EXE not named EXE A query loosing its value? Commenting out a block of code with one click (OT) Anyone remember the formula? Runtime Error 91 Status Bar Question |
|||||||||||||||||||||||