StrComp

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Online help states that if either string1 or string2 is Null, then StrComp returns a Null value. I tried

Option Compare Database

Dim var1 As Variant

var1 = StrComp("ABC", Null)

and I get -1, NOT Null as the online help suggests.

Can anyone explain how I get a Null value from StrComp. If this is not possible, then why not use

Dim var1 As Integer
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Jus to test, I ran
Code:
Sub temp()
Dim var1 As Variant
var1 = StrComp("ABC", Null)
Debug.Print var1
End Sub
in a module in A97 and it returned Null in the Debug Window.

HTH

Peter
 
Upvote 0
I'm getting Null as well now?? Don't know what I was doing before.

This thing all got started because I was wondering why the return value for StrComp was Variant (Integer). If StrComp can produce Null then why don't we have Variant (String)?
 
Upvote 0
It returns an integer -1,0,1 depending on result. Null is a non answer and has no meaning as such. Null is not a string.

Peter
 
Upvote 0
Thanks Peter. It's all clear now. I've always hated Nulls as I have never really understood them, but I do now from your reply.
 
Upvote 0

Forum statistics

Threads
1,221,561
Messages
6,160,495
Members
451,653
Latest member
agata

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top