473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to get rid of warning.

This the waring I get:
Warning 4 Function 'UnmaskSSN' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
Expand|Select|Wrap|Line Numbers
  1. Private Function UnmaskSSN(ByVal SSN As String) As String
  2.  
  3.         ' Yank dashes out of the SSN in the masked textbox
  4.         If SSN = "   -  -    " Then
  5.             SSN = "d"
  6.         Else
  7.             If Len(SSN) = 11 Then
  8.                 Dim UnmaskedSSN As String = Microsoft.VisualBasic.Left(SSN, 3) & Microsoft.VisualBasic.Mid(SSN, 5, 2) & Microsoft.VisualBasic.Right(SSN, 4)
  9.                 Return UnmaskedSSN
  10.             Else
  11.                 SSN = "d"
  12.                 MessageBox.Show("The SSN entered is not complete." & vbCrLf & "Please try again.", _
  13.                  "CT Guide Request Search", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  14.                 Me.txtSSN.Focus()
  15.             End If
  16.  
  17.         End If
  18.  
  19.     End Function
Sep 13 '10 #1

✓ answered by Oralloy

Well, the error code means exactly what it says.

If you follow your code through each of the major code paths, you'll find that when the SSN is empty (your magic string), there is no return value; and when the length of SSN is not 11, there is no return value. Instead, in these paths you set the SSN variable to "d", instead.

You might try something like this, instead:

Expand|Select|Wrap|Line Numbers
  1. Private Function UnmaskSSN(ByVal SSN As String) As String 
  2.   Dim result as string
  3.   result = "d"
  4.  
  5.   If Len(SSN) <> 11 Then 
  6.     MessageBox.Show("The SSN entered is not complete." & _
  7.                     vbCrLf & "Please try again.", _ 
  8.                     "CT Guide Request Search", _
  9.                     MessageBoxButtons.OK, _
  10.                     MessageBoxIcon.Exclamation) 
  11.     Me.txtSSN.Focus()
  12.   Else If SSN = "   -  -    " Then 
  13.     '' noOp - result already has "bad" value
  14.   Else
  15.     '' Yank dashes out of the SSN in the masked textbox 
  16.     result = Microsoft.VisualBasic.Left(SSN, 3) & _
  17.              Microsoft.VisualBasic.Mid(SSN, 5, 2) & _
  18.              Microsoft.VisualBasic.Right(SSN, 4) 
  19.   End If
  20.  
  21.   UnmaskSSN = result
  22. End Function 

1 1055
Oralloy
985 Expert 512MB
Well, the error code means exactly what it says.

If you follow your code through each of the major code paths, you'll find that when the SSN is empty (your magic string), there is no return value; and when the length of SSN is not 11, there is no return value. Instead, in these paths you set the SSN variable to "d", instead.

You might try something like this, instead:

Expand|Select|Wrap|Line Numbers
  1. Private Function UnmaskSSN(ByVal SSN As String) As String 
  2.   Dim result as string
  3.   result = "d"
  4.  
  5.   If Len(SSN) <> 11 Then 
  6.     MessageBox.Show("The SSN entered is not complete." & _
  7.                     vbCrLf & "Please try again.", _ 
  8.                     "CT Guide Request Search", _
  9.                     MessageBoxButtons.OK, _
  10.                     MessageBoxIcon.Exclamation) 
  11.     Me.txtSSN.Focus()
  12.   Else If SSN = "   -  -    " Then 
  13.     '' noOp - result already has "bad" value
  14.   Else
  15.     '' Yank dashes out of the SSN in the masked textbox 
  16.     result = Microsoft.VisualBasic.Left(SSN, 3) & _
  17.              Microsoft.VisualBasic.Mid(SSN, 5, 2) & _
  18.              Microsoft.VisualBasic.Right(SSN, 4) 
  19.   End If
  20.  
  21.   UnmaskSSN = result
  22. End Function 
Sep 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bas Wassink | last post by:
Hello there, I'm having trouble understanding a warning produced by 'splint', a code-checker. The warning produced is: keywords.c: (in function keyw_get_string) keywords.c:60:31: Released...
3
by: Bill Burris | last post by:
How do I find what is causing this warning from the Linker? If I use /NODEFAULTLIB I get hundreds of undefined symbols. LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other...
3
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency...
1
by: spanov | last post by:
i've got problem installing python-2.3.5 from sources on FreeBSD 5.3 root@server# ./configure > conf_log configure: WARNING: curses.h: present but cannot be compiled configure: WARNING:...
5
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message...
1
by: Ian | last post by:
I've just discovered the msclr::lock class in the C++ Support Library online documentation. This seems like a much cleaner way to implement thread protection than using...
5
by: holmescn | last post by:
what is the meaning of warning attributes ignored on template instantiation. i got it when i compiled stlport 5.1.3. anybody can help me ? thx!
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
4
by: cody | last post by:
It is possible to declare and use/instantiate a class with a uninitialized readonly field without even a compiler warning. Why don't I get warnings? public class Stuff { public readonly int a;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.