Why are my method Returns being truncated?

G

Guest

I know that I get pretty dumb late in the day, so I hope someone can just
point out the source my stupidity.

Below is partial code from a class. I'm accessing the 2 properties and
getting truncated results for both. For discussion's sake I'll just describe
1 of them - 'DefaultFileExtension'. This property's ReadOnly method calls the
'GetDefaultFileExtensions' function which should return the value of a
constant, which in this case is "*.pdf". Look at the 2 'MsgBox' items in the
code. I put them there for debugging. The message box inside of the
'GetDefaultFileExtensions' function displays "*.pdf". The message box in the
'DefaultFileExtension. property get displays "*" as the returned value from
'GetDefaultFileExtensions'.

I've tried replacing the sReturn variable with the literal "*.pdf" and still
get the same result. Also recompiled, and even rebooted.

I'm stumped and open to suggestions.

Thanks, Tom
'******************************************
Friend Class clsFileDefinitionStructure
Friend Enum fdFileType
PDF_ft
Image_ft
End Enum

Private Const mc_DefaultFiletypeDescription_PDF As String = "PDF files"
Private Const mc_DefaultFiletypeDescription_Image As String = "Image
files"
Private Const mc_DefaultFileExtension_PDF As String = "*.pdf"
Private Const mc_DefaultFileExtension_Image As String =
"*.gif;*.bmp;*.jpg;*.jpeg;*.tif;*.png;*.pcd;*.pcx"

Private m_FileType As fdFileType = fdFileType.PDF_ft

Friend ReadOnly Property DefaultFileExtension() As String
Get
MsgBox(GetDefaultFileExtensions(m_FileType))
Return GetDefaultFileExtensions(m_FileType)
End Get
End Property

Friend ReadOnly Property DefaultFileTypeDescription() As String
Get
Return GetDefaultFileTypeDescription(m_FileType)
End Get
End Property

Private Function GetDefaultFileExtensions() As String
Dim sReturn As String
Select Case m_FileType
Case fdFileType.Image_ft
sReturn = mc_DefaultFileExtension_Image
Case fdFileType.PDF_ft
sReturn = mc_DefaultFileExtension_PDF
Case Else
sReturn = "*.*"
End Select
MsgBox(sReturn)
Return sReturn
End Function

Private Function GetDefaultFileTypeDescription() As String
Dim sReturn As String
Select Case m_FileType
Case fdFileType.Image_ft
sReturn = mc_DefaultFiletypeDescription_Image
Case fdFileType.PDF_ft
sReturn = mc_DefaultFiletypeDescription_PDF
Case Else
sReturn = "All Files"
End Select
Return sReturn
End Function
End Class
 
A

Armin Zingler

Tom Garth said:
I know that I get pretty dumb late in the day, so I hope someone can
just point out the source my stupidity.

Below is partial code from a class. I'm accessing the 2 properties
and getting truncated results for both. For discussion's sake I'll
just describe 1 of them - 'DefaultFileExtension'. This property's
ReadOnly method calls the 'GetDefaultFileExtensions' function which
should return the value of a constant, which in this case is
"*.pdf". Look at the 2 'MsgBox' items in the code. I put them there
for debugging. The message box inside of the
'GetDefaultFileExtensions' function displays "*.pdf". The message
box in the 'DefaultFileExtension. property get displays "*" as the
returned value from 'GetDefaultFileExtensions'.

I've tried replacing the sReturn variable with the literal "*.pdf"
and still get the same result. Also recompiled, and even rebooted.

I'm stumped and open to suggestions.

Thanks, Tom
'******************************************
Friend Class clsFileDefinitionStructure
Friend Enum fdFileType
PDF_ft
Image_ft
End Enum

Private Const mc_DefaultFiletypeDescription_PDF As String = "PDF
files" Private Const mc_DefaultFiletypeDescription_Image As
String = "Image files"
Private Const mc_DefaultFileExtension_PDF As String = "*.pdf"
Private Const mc_DefaultFileExtension_Image As String =
"*.gif;*.bmp;*.jpg;*.jpeg;*.tif;*.png;*.pcd;*.pcx"

Private m_FileType As fdFileType = fdFileType.PDF_ft

Friend ReadOnly Property DefaultFileExtension() As String
Get
MsgBox(GetDefaultFileExtensions(m_FileType))
Return GetDefaultFileExtensions(m_FileType)
End Get
End Property

Friend ReadOnly Property DefaultFileTypeDescription() As String
Get
Return GetDefaultFileTypeDescription(m_FileType)
End Get
End Property

Private Function GetDefaultFileExtensions() As String
Dim sReturn As String
Select Case m_FileType
Case fdFileType.Image_ft
sReturn = mc_DefaultFileExtension_Image
Case fdFileType.PDF_ft
sReturn = mc_DefaultFileExtension_PDF
Case Else
sReturn = "*.*"
End Select
MsgBox(sReturn)
Return sReturn
End Function

Private Function GetDefaultFileTypeDescription() As String
Dim sReturn As String
Select Case m_FileType
Case fdFileType.Image_ft
sReturn = mc_DefaultFiletypeDescription_Image
Case fdFileType.PDF_ft
sReturn = mc_DefaultFiletypeDescription_PDF
Case Else
sReturn = "All Files"
End Select
Return sReturn
End Function
End Class


This is awesome... The thing is that

GetDefaultFileExtensions(m_FileType)

is short for

GetDefaultFileExtensions.Chars(m_FileType)

because Chars is the default property of a String, and because
GetDefaultFileExtensions does /not/ have arguments. As m_FileType is 0, this
is actually

GetDefaultFileExtensions.Chars(0)

So, you get the first char of the string, which is "*" only.


Armin
 
G

Guest

Awesome answer as well! That's really cool. Thanks very much for "decoding"
that one.
 

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