ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   data type problem XL9 (https://www.excelbanter.com/excel-programming/367003-data-type-problem-xl9.html)

RB Smissaert

data type problem XL9
 
Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS




Tom Ogilvy

data type problem XL9
 
I suspect the customer actually is experiencing this in xl97 (xl8). In xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS





Peter T

data type problem XL9
 
Just to add the example works fine in both my XL97 and XL2000, as does the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In

xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS







RB Smissaert

data type problem XL9
 
Maybe it was XL 8. Will find out tomorrow.
For now I have added Val to the string variables as with that it seems fine,
even on this customer's PC.
So:
l = Val(GiveString())

RBS

"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS






RB Smissaert

data type problem XL9
 
Actually the non-simplified code is:

'error he
If Val(ReadINIValueL(strINIPath, _
"Add-in behaviour", _
"F2 for load add-in")) = 0 Then


Function ReadINIValueL(ByVal strINIPath As String, _
ByVal strHeader As String, _
ByVal strKey As String) As String

Dim buf As String * 256
Dim Length As Long

If Len(Dir(strINIPath)) = 0 Then
ReadINIValueL = "<no file"
Exit Function
End If

Length = GetPrivateProfileString(strHeader, _
strKey, _
"<no value", _
buf, _
Len(buf), _
strINIPath)

ReadINIValueL = Left(buf, Length)

End Function

And the result of the function was "1" and not "<no file" or "<no value"


RBS


"Peter T" <peter_t@discussions wrote in message
...
Just to add the example works fine in both my XL97 and XL2000, as does the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In

xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS








Tom Ogilvy

data type problem XL9
 
This doesn't have any bearing on Bart's non-simplified code, but

I don't have xl97 handy to test, but try it this way. this works in xl2003
but I believe it will raise typemismatch in xl97.

Sub test()

Dim i As Long
i = 1
if i = GiveString() then
msgbox "match"
else
MsgBox i
end if

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

--
Regards,
Tom Ogilvy


"Peter T" wrote:

Just to add the example works fine in both my XL97 and XL2000, as does the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In

xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS








RB Smissaert

data type problem XL9
 
Sorry, the actual code was causing the error was:

If ReadINIValueL(strINIPath, _
"Add-in behaviour", _
"F2 for load add-in") = 0 Then

So, without the Val. I had added the Val as a fix.
So, your example looks very similar and probably this is indeed an XL97
thing.

RBS


"Tom Ogilvy" wrote in message
...
This doesn't have any bearing on Bart's non-simplified code, but

I don't have xl97 handy to test, but try it this way. this works in
xl2003
but I believe it will raise typemismatch in xl97.

Sub test()

Dim i As Long
i = 1
if i = GiveString() then
msgbox "match"
else
MsgBox i
end if

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

--
Regards,
Tom Ogilvy


"Peter T" wrote:

Just to add the example works fine in both my XL97 and XL2000, as does
the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In

xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type
mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS









Peter T

data type problem XL9
 
If I follow, effectively it does this (without the Val)

If "1" = 0 Then

again this works in both my XL97 & XL2k

Any missing references ?

Regards,
Peter T

"RB Smissaert" wrote in message
...
Actually the non-simplified code is:

'error he
If Val(ReadINIValueL(strINIPath, _
"Add-in behaviour", _
"F2 for load add-in")) = 0 Then


Function ReadINIValueL(ByVal strINIPath As String, _
ByVal strHeader As String, _
ByVal strKey As String) As String

Dim buf As String * 256
Dim Length As Long

If Len(Dir(strINIPath)) = 0 Then
ReadINIValueL = "<no file"
Exit Function
End If

Length = GetPrivateProfileString(strHeader, _
strKey, _
"<no value", _
buf, _
Len(buf), _
strINIPath)

ReadINIValueL = Left(buf, Length)

End Function

And the result of the function was "1" and not "<no file" or "<no value"


RBS


"Peter T" <peter_t@discussions wrote in message
...
Just to add the example works fine in both my XL97 and XL2000, as does

the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In

xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS










RB Smissaert

data type problem XL9
 
Hi Peter,

I don't think missing references are the problem as this happens very early
in the code in the wb open event. I add references to the project
dynamically,
but that happens later on.
I can see though that missing references are a suspect if you say that
If "1" = 0
works on 97.
I went through the registry with this customer and
Excel\Options was only under
HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\
So I think it is Excel 9.

RBS


"Peter T" <peter_t@discussions wrote in message
...
If I follow, effectively it does this (without the Val)

If "1" = 0 Then

again this works in both my XL97 & XL2k

Any missing references ?

Regards,
Peter T

"RB Smissaert" wrote in message
...
Actually the non-simplified code is:

'error he
If Val(ReadINIValueL(strINIPath, _
"Add-in behaviour", _
"F2 for load add-in")) = 0 Then


Function ReadINIValueL(ByVal strINIPath As String, _
ByVal strHeader As String, _
ByVal strKey As String) As String

Dim buf As String * 256
Dim Length As Long

If Len(Dir(strINIPath)) = 0 Then
ReadINIValueL = "<no file"
Exit Function
End If

Length = GetPrivateProfileString(strHeader, _
strKey, _
"<no value", _
buf, _
Len(buf), _
strINIPath)

ReadINIValueL = Left(buf, Length)

End Function

And the result of the function was "1" and not "<no file" or "<no
value"


RBS


"Peter T" <peter_t@discussions wrote in message
...
Just to add the example works fine in both my XL97 and XL2000, as does

the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).
In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS











Peter T

data type problem XL9
 
That also works in my XL 97, I got "match". I don't recall this particular
type of coercion not working in XL97.

?"1" = 1&
True

Regards,
Peter T

"Tom Ogilvy" wrote in message
...
This doesn't have any bearing on Bart's non-simplified code, but

I don't have xl97 handy to test, but try it this way. this works in

xl2003
but I believe it will raise typemismatch in xl97.

Sub test()

Dim i As Long
i = 1
if i = GiveString() then
msgbox "match"
else
MsgBox i
end if

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

--
Regards,
Tom Ogilvy


"Peter T" wrote:

Just to add the example works fine in both my XL97 and XL2000, as does

the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).

In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS










Peter T

data type problem XL9
 
A bit of a mystery!

Someone else's missing reference even in some another loaded file
That function definitely returning a single character "1" and no Null's
Perform a simple test to confirm a string to long coercion should work on
that system.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Hi Peter,

I don't think missing references are the problem as this happens very

early
in the code in the wb open event. I add references to the project
dynamically,
but that happens later on.
I can see though that missing references are a suspect if you say that
If "1" = 0
works on 97.
I went through the registry with this customer and
Excel\Options was only under
HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\
So I think it is Excel 9.

RBS


"Peter T" <peter_t@discussions wrote in message
...
If I follow, effectively it does this (without the Val)

If "1" = 0 Then

again this works in both my XL97 & XL2k

Any missing references ?

Regards,
Peter T

"RB Smissaert" wrote in message
...
Actually the non-simplified code is:

'error he
If Val(ReadINIValueL(strINIPath, _
"Add-in behaviour", _
"F2 for load add-in")) = 0 Then


Function ReadINIValueL(ByVal strINIPath As String, _
ByVal strHeader As String, _
ByVal strKey As String) As String

Dim buf As String * 256
Dim Length As Long

If Len(Dir(strINIPath)) = 0 Then
ReadINIValueL = "<no file"
Exit Function
End If

Length = GetPrivateProfileString(strHeader, _
strKey, _
"<no value", _
buf, _
Len(buf), _
strINIPath)

ReadINIValueL = Left(buf, Length)

End Function

And the result of the function was "1" and not "<no file" or "<no
value"


RBS


"Peter T" <peter_t@discussions wrote in message
...
Just to add the example works fine in both my XL97 and XL2000, as

does
the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).
In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the

following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS













RB Smissaert

data type problem XL9
 
Perform a simple test to confirm a string to long
coercion should work on that system


Thanks, will do that.
I already spent about 90 mins debugging this over the phone.
Hopefully adding the Val (in a lot of places) will sort it.
If not I think she might be better off moving to 2003, which is near enough
free in any case on the NHS.

RBS


"Peter T" <peter_t@discussions wrote in message
...
A bit of a mystery!

Someone else's missing reference even in some another loaded file
That function definitely returning a single character "1" and no Null's
Perform a simple test to confirm a string to long coercion should work on
that system.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Hi Peter,

I don't think missing references are the problem as this happens very

early
in the code in the wb open event. I add references to the project
dynamically,
but that happens later on.
I can see though that missing references are a suspect if you say that
If "1" = 0
works on 97.
I went through the registry with this customer and
Excel\Options was only under
HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\
So I think it is Excel 9.

RBS


"Peter T" <peter_t@discussions wrote in message
...
If I follow, effectively it does this (without the Val)

If "1" = 0 Then

again this works in both my XL97 & XL2k

Any missing references ?

Regards,
Peter T

"RB Smissaert" wrote in message
...
Actually the non-simplified code is:

'error he
If Val(ReadINIValueL(strINIPath, _
"Add-in behaviour", _
"F2 for load add-in")) = 0 Then


Function ReadINIValueL(ByVal strINIPath As String, _
ByVal strHeader As String, _
ByVal strKey As String) As String

Dim buf As String * 256
Dim Length As Long

If Len(Dir(strINIPath)) = 0 Then
ReadINIValueL = "<no file"
Exit Function
End If

Length = GetPrivateProfileString(strHeader, _
strKey, _
"<no value", _
buf, _
Len(buf), _
strINIPath)

ReadINIValueL = Left(buf, Length)

End Function

And the result of the function was "1" and not "<no file" or "<no
value"


RBS


"Peter T" <peter_t@discussions wrote in message
...
Just to add the example works fine in both my XL97 and XL2000, as

does
the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).
In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my
customers.

In a .xla add-in I have in very much simplified code the

following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type
mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS














Tom Ogilvy

data type problem XL9
 
Sub aaa()
ActiveCell.Value = "a"
If ActiveCell.Value = 1 Then
MsgBox "Equals 1"
Else
MsgBox "Doesn't equal 1"
End If

End Sub

Fails in xl97 with a type mismatch, but works in xl2002, xl2000 (at least
for me)

I don't know all the combinations that will cause it to fail in xl97 and not
xl2000/2 but I know xl97 is more sensitive to this.

May have no bearing on Bart's problem, but then again maybe it does.

--
Regards,
Tom Ogilvy


"Peter T" <peter_t@discussions wrote in message
...
That also works in my XL 97, I got "match". I don't recall this particular
type of coercion not working in XL97.

?"1" = 1&
True

Regards,
Peter T

"Tom Ogilvy" wrote in message
...
This doesn't have any bearing on Bart's non-simplified code, but

I don't have xl97 handy to test, but try it this way. this works in

xl2003
but I believe it will raise typemismatch in xl97.

Sub test()

Dim i As Long
i = 1
if i = GiveString() then
msgbox "match"
else
MsgBox i
end if

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

--
Regards,
Tom Ogilvy


"Peter T" wrote:

Just to add the example works fine in both my XL97 and XL2000, as does

the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).

In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS












Peter T

data type problem XL9
 
Yes I also get the mismatch in XL97 comparing cell value = "a" to a number.

Bart said his function returns "1" so that does get coerced in my XL97. I
did suggest he double checks his remote user really is returning "1".

Sub test2()
Dim cel As Range, n&, s$, v
n = 1

On Error GoTo errH

s = "1"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1-"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1,"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1:"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1,"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = " 1 "
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1a"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "a1"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v

Debug.Print "Excel " & Application.Version
Set cel = ActiveCell
cel = "a1"
v = cel = n: Debug.Print Chr(34) & cel & Chr(34), v

Exit Sub
errH:
v = "Error"
Resume Next
End Sub

"1" True
"1-" False
"1." True
"1:" Error
"1," True
" 1 " True
"1a" Error
"a1" Error
Excel 8.0a
"a1" Error

Excel 9.0
"a1" False

All the s = n comparisons return identically for me in XL97 & XL2000
However the last cell = n comparison is notably different, error in '97,
false in 2K, and replicates the difference you suggested.

Regards,
Peter T

"Tom Ogilvy" wrote in message
...
Sub aaa()
ActiveCell.Value = "a"
If ActiveCell.Value = 1 Then
MsgBox "Equals 1"
Else
MsgBox "Doesn't equal 1"
End If

End Sub

Fails in xl97 with a type mismatch, but works in xl2002, xl2000 (at least
for me)

I don't know all the combinations that will cause it to fail in xl97 and

not
xl2000/2 but I know xl97 is more sensitive to this.

May have no bearing on Bart's problem, but then again maybe it does.

--
Regards,
Tom Ogilvy


"Peter T" <peter_t@discussions wrote in message
...
That also works in my XL 97, I got "match". I don't recall this

particular
type of coercion not working in XL97.

?"1" = 1&
True

Regards,
Peter T

"Tom Ogilvy" wrote in message
...
This doesn't have any bearing on Bart's non-simplified code, but

I don't have xl97 handy to test, but try it this way. this works in

xl2003
but I believe it will raise typemismatch in xl97.

Sub test()

Dim i As Long
i = 1
if i = GiveString() then
msgbox "match"
else
MsgBox i
end if

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

--
Regards,
Tom Ogilvy


"Peter T" wrote:

Just to add the example works fine in both my XL97 and XL2000, as

does
the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).

In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my

customers.

In a .xla add-in I have in very much simplified code the

following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS














[email protected]

data type problem XL9
 
Can comfirm now that this was on Excel 9 (2000), so maybe the trouble
is somehow caused by a missing reference.
Strange though that when I was debugging over the phone adding Val
fixed at least the error on that line.

RBS


RB Smissaert wrote:
Maybe it was XL 8. Will find out tomorrow.
For now I have added Val to the string variables as with that it seems fine,
even on this customer's PC.
So:
l = Val(GiveString())

RBS

"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS






Peter T

data type problem XL9
 
I was a bit puzzled in the test I posted as to the difference in XL2000
between

s = "a1"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v ' Error
and

cel = "a1"
v = cel = n: Debug.Print Chr(34) & cel & Chr(34), v ' False

I think this explains

Sub Test3()
Dim s As String
Dim vs As Variant

s = "a1" ' String
vs = s ' Variant/String
MsgBox vs = 1 ' False
MsgBox s = 1 ' Error
End Sub

In XL97 MsgBox vs = 1 also fails

Regards,
Peter T

"Peter T" <peter_t@discussions wrote in message
...
Yes I also get the mismatch in XL97 comparing cell value = "a" to a

number.

Bart said his function returns "1" so that does get coerced in my XL97. I
did suggest he double checks his remote user really is returning "1".

Sub test2()
Dim cel As Range, n&, s$, v
n = 1

On Error GoTo errH

s = "1"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1-"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1,"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1:"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1,"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = " 1 "
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "1a"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v
s = "a1"
v = s = n: Debug.Print Chr(34) & s & Chr(34), v

Debug.Print "Excel " & Application.Version
Set cel = ActiveCell
cel = "a1"
v = cel = n: Debug.Print Chr(34) & cel & Chr(34), v

Exit Sub
errH:
v = "Error"
Resume Next
End Sub

"1" True
"1-" False
"1." True
"1:" Error
"1," True
" 1 " True
"1a" Error
"a1" Error
Excel 8.0a
"a1" Error

Excel 9.0
"a1" False

All the s = n comparisons return identically for me in XL97 & XL2000
However the last cell = n comparison is notably different, error in '97,
false in 2K, and replicates the difference you suggested.

Regards,
Peter T

"Tom Ogilvy" wrote in message
...
Sub aaa()
ActiveCell.Value = "a"
If ActiveCell.Value = 1 Then
MsgBox "Equals 1"
Else
MsgBox "Doesn't equal 1"
End If

End Sub

Fails in xl97 with a type mismatch, but works in xl2002, xl2000 (at

least
for me)

I don't know all the combinations that will cause it to fail in xl97 and

not
xl2000/2 but I know xl97 is more sensitive to this.

May have no bearing on Bart's problem, but then again maybe it does.

--
Regards,
Tom Ogilvy


"Peter T" <peter_t@discussions wrote in message
...
That also works in my XL 97, I got "match". I don't recall this

particular
type of coercion not working in XL97.

?"1" = 1&
True

Regards,
Peter T

"Tom Ogilvy" wrote in message
...
This doesn't have any bearing on Bart's non-simplified code, but

I don't have xl97 handy to test, but try it this way. this works in
xl2003
but I believe it will raise typemismatch in xl97.

Sub test()

Dim i As Long
i = 1
if i = GiveString() then
msgbox "match"
else
MsgBox i
end if

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

--
Regards,
Tom Ogilvy


"Peter T" wrote:

Just to add the example works fine in both my XL97 and XL2000, as

does
the
following in both versions

Dim n As Long
n = "123"

Regards,
Peter T


"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97

(xl8).
In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my

customers.

In a .xla add-in I have in very much simplified code the

following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type
mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS
















Peter T

data type problem XL9
 
I'm sure you've double checked but if the string returns an extra non
numeric character, perhaps non-printable & not obvious, it would be fixed
with use of Val.

String functions are particularly sensitive to missing references. Although
one is not used directly maybe a string function is used invisibly to
perform the coercion, I don't know.

I'm not sure that upgrading to 2003 will guarantee to fix the problem.

Regards,
Peter T

wrote in message
oups.com...
Can comfirm now that this was on Excel 9 (2000), so maybe the trouble
is somehow caused by a missing reference.
Strange though that when I was debugging over the phone adding Val
fixed at least the error on that line.

RBS


RB Smissaert wrote:
Maybe it was XL 8. Will find out tomorrow.
For now I have added Val to the string variables as with that it seems

fine,
even on this customer's PC.
So:
l = Val(GiveString())

RBS

"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8). In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS








RB Smissaert

data type problem XL9
 
Yes, good point, but the result of that ini function in that particular case
only
can be "1" or "0".
Must admit though I haven't seen the actual return when it runs.
As this customer has XL9 the whole issue of Type mismatch in XL8 versus 9
is now irrelevant and I will have to look somewhere else.
Had a look in my customer database and I have nobody on XL8, so maybe I can
throw all those Val's out again.
My guess is that indeed it somehow has to do with references.
Will have to wait till next week to find out.

RBS


"Peter T" <peter_t@discussions wrote in message
...
I'm sure you've double checked but if the string returns an extra non
numeric character, perhaps non-printable & not obvious, it would be fixed
with use of Val.

String functions are particularly sensitive to missing references.
Although
one is not used directly maybe a string function is used invisibly to
perform the coercion, I don't know.

I'm not sure that upgrading to 2003 will guarantee to fix the problem.

Regards,
Peter T

wrote in message
oups.com...
Can comfirm now that this was on Excel 9 (2000), so maybe the trouble
is somehow caused by a missing reference.
Strange though that when I was debugging over the phone adding Val
fixed at least the error on that line.

RBS


RB Smissaert wrote:
Maybe it was XL 8. Will find out tomorrow.
For now I have added Val to the string variables as with that it seems

fine,
even on this customer's PC.
So:
l = Val(GiveString())

RBS

"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).
In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS









Peter T

data type problem XL9
 
Yes, good point, but the result of that ini function in that particular
case
only can be "1" or "0".


In theory <g

I know it's not relevant but FWIW even in XL97 it should work fine without
Val if the returned string is truly numeric.

My guess by a small margin is the string is not returning as expected!

Regards,
Peter T


"RB Smissaert" wrote in message
...
Yes, good point, but the result of that ini function in that particular

case
only
can be "1" or "0".
Must admit though I haven't seen the actual return when it runs.
As this customer has XL9 the whole issue of Type mismatch in XL8 versus 9
is now irrelevant and I will have to look somewhere else.
Had a look in my customer database and I have nobody on XL8, so maybe I

can
throw all those Val's out again.
My guess is that indeed it somehow has to do with references.
Will have to wait till next week to find out.

RBS


"Peter T" <peter_t@discussions wrote in message
...
I'm sure you've double checked but if the string returns an extra non
numeric character, perhaps non-printable & not obvious, it would be

fixed
with use of Val.

String functions are particularly sensitive to missing references.
Although
one is not used directly maybe a string function is used invisibly to
perform the coercion, I don't know.

I'm not sure that upgrading to 2003 will guarantee to fix the problem.

Regards,
Peter T

wrote in message
oups.com...
Can comfirm now that this was on Excel 9 (2000), so maybe the trouble
is somehow caused by a missing reference.
Strange though that when I was debugging over the phone adding Val
fixed at least the error on that line.

RBS


RB Smissaert wrote:
Maybe it was XL 8. Will find out tomorrow.
For now I have added Val to the string variables as with that it

seems
fine,
even on this customer's PC.
So:
l = Val(GiveString())

RBS

"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).
In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my customers.

In a .xla add-in I have in very much simplified code the

following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type

mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS











RB Smissaert

data type problem XL9
 
My guess by a small margin is the string is not returning as expected!

You might be right but very unlikely:

The function returns the value of an .ini file.
The file is present as a previous call (some lines higher in the code)
worked fine.
The section and key is present as it is a newly installed app and the .ini
file is in the setup:

[Add-in behaviour]
Allow fast searches=True
Select new node=False
F2 for load add-in=1

The value should be there as there has been no write yet to that key.

I suppose at the end of the day my error handling in particular case is just
not up to scratch
otherwise I would have known by now what the trouble is.
Will let you know what the outcome is.

RBS


"Peter T" <peter_t@discussions wrote in message
...
Yes, good point, but the result of that ini function in that particular

case
only can be "1" or "0".


In theory <g

I know it's not relevant but FWIW even in XL97 it should work fine without
Val if the returned string is truly numeric.

My guess by a small margin is the string is not returning as expected!

Regards,
Peter T


"RB Smissaert" wrote in message
...
Yes, good point, but the result of that ini function in that particular

case
only
can be "1" or "0".
Must admit though I haven't seen the actual return when it runs.
As this customer has XL9 the whole issue of Type mismatch in XL8 versus 9
is now irrelevant and I will have to look somewhere else.
Had a look in my customer database and I have nobody on XL8, so maybe I

can
throw all those Val's out again.
My guess is that indeed it somehow has to do with references.
Will have to wait till next week to find out.

RBS


"Peter T" <peter_t@discussions wrote in message
...
I'm sure you've double checked but if the string returns an extra non
numeric character, perhaps non-printable & not obvious, it would be

fixed
with use of Val.

String functions are particularly sensitive to missing references.
Although
one is not used directly maybe a string function is used invisibly to
perform the coercion, I don't know.

I'm not sure that upgrading to 2003 will guarantee to fix the problem.

Regards,
Peter T

wrote in message
oups.com...
Can comfirm now that this was on Excel 9 (2000), so maybe the trouble
is somehow caused by a missing reference.
Strange though that when I was debugging over the phone adding Val
fixed at least the error on that line.

RBS


RB Smissaert wrote:
Maybe it was XL 8. Will find out tomorrow.
For now I have added Val to the string variables as with that it

seems
fine,
even on this customer's PC.
So:
l = Val(GiveString())

RBS

"Tom Ogilvy" wrote in message
...
I suspect the customer actually is experiencing this in xl97 (xl8).
In
xl97,
you would get that error.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Have come across a strange problem today with one of my
customers.

In a .xla add-in I have in very much simplified code the

following:

Sub test()

Dim l As Long
l = GiveString()
MsgBox l

End Sub


Function GiveString() As String

Dim s As String
s = "1"
GiveString = s

End Function

All this works fine on my 2 home PC's with XL11 and XL9.
With this one customer though in XL9 there is the error: Type
mismatch.

Why would this be if it runs fine on the home machine with XL9?


RBS













All times are GMT +1. The time now is 12:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com