the '$' in right$()

B

brzak

this is hopefully really simple

i came across a line in a short sub that i don't quite full
understand. The line in question is:

If Right$(fldr, 1) <> "\" Then fldr = fldr & "\"

why is it 'Right$' instead of simply 'Right' ?

I haven't seen any difference in behaviour for what i've been using it
on..
Is there an instance when it would be different?

Thanks

Brz

Code (http://www.ozgrid.com/forum/showthread.php?t=71409) is below:


Sub testit()
myvar = FileList("C:\")
For i = LBound(myvar) To UBound(myvar)
Debug.Print myvar(i)
Next
End Sub

Function FileList(fldr As String, Optional fltr As String = "*.*") As
Variant
Dim sTemp As String, sHldr As String
If Right$(fldr, 1) <> "\" Then fldr = fldr & "\"
sTemp = Dir(fldr & fltr)
If sTemp = "" Then
FileList = Split("No files found", "|") 'ensures an array is
returned
Exit Function
End If
Do
sHldr = Dir
If sHldr = "" Then Exit Do
sTemp = sTemp & "|" & sHldr
Loop
FileList = Split(sTemp, "|")
End Function
 
N

norie

'Right' returns a Variant/String wheres 'Right$' returns a String.

Apart from that they are used in the same way.

The only circumstance I can think of where the 2nd might be needed is
if you needed to ensure
you returned a String.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top