Why are my method Returns being truncated? [modified]
-
This was, as I suspected, just bad code, and that was recognized by another pair of eyes. The problem in finding it, is that at run time it is legitimate code, just not what I intended. The call to 'GetDefaultFileExtensions' should not have had an argument. tg '**************************************** 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 sR
-
This was, as I suspected, just bad code, and that was recognized by another pair of eyes. The problem in finding it, is that at run time it is legitimate code, just not what I intended. The call to 'GetDefaultFileExtensions' should not have had an argument. tg '**************************************** 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 sR
I have no idea why this is happening. The code doesn't show anything that would cause it. I'd remove the MsgBox lines and just step through the code, line-by-line, using the debugger and watch the variables involved.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I have no idea why this is happening. The code doesn't show anything that would cause it. I'd remove the MsgBox lines and just step through the code, line-by-line, using the debugger and watch the variables involved.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hi Dave, I had already used the debugger while working line by line. I added the message boxes to make it easier to try different variations. The only thing the code shows is that I stupidly added the FileType Enum as an argument to a call that didn't ask for an argument. The result was explained to me by in a very elegant answer from Armin Zingler at: http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.dotnet.languages.vb&mid=03cf9ea6-b81a-48fe-ad43-f1f48517dbdc[^] I've copied his explanation here: ************************************************************ 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 ************************************************************ Cool huh?
Tom Garth Developer R. L. Nelson and Associates, Inc., Virginia
-
Hi Dave, I had already used the debugger while working line by line. I added the message boxes to make it easier to try different variations. The only thing the code shows is that I stupidly added the FileType Enum as an argument to a call that didn't ask for an argument. The result was explained to me by in a very elegant answer from Armin Zingler at: http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.dotnet.languages.vb&mid=03cf9ea6-b81a-48fe-ad43-f1f48517dbdc[^] I've copied his explanation here: ************************************************************ 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 ************************************************************ Cool huh?
Tom Garth Developer R. L. Nelson and Associates, Inc., Virginia
Oh my God! I was poking through that code for an hour and didn't see it! :->
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007