Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Return Null Nothing for validation purpose

Posted on 2003-12-08
8
Medium Priority
?
271 Views
Last Modified: 2010-05-01
Let say I have the following simple code.
        Dim newStudent

        newStudent = Nothing

        If Not IsNothing(newStudent) Then
            Console.WriteLine("They is something")  <-- This is printed
        Else
            Console.WriteLine("They is nothing")
        End If

I need to do the above so let say when the user enter an invalid data, the fuction will return nothing so that I know the function has detected an error e.g. newStudent = GetStudentDetails() in user input and therefore return nothing so that my calling program will reject the entry.

But the above does not work, even when newStudent is nothing which indicate that they is nothing it still say they is something, help, any alternative method is welcome.
0
Comment
Question by:CplusPlus
  • 4
  • 3
8 Comments
 
LVL 39

Expert Comment

by:appari
ID: 9901890

is this code is in VB.NET?
0
 

Author Comment

by:CplusPlus
ID: 9901898
To appari

Yes. sorry about forgetting,,,
0
 
LVL 39

Expert Comment

by:appari
ID: 9901917
what's the datatype of newStudent?

i have tested with type string, seems to work fine

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As String
        x = Nothing
        If Not IsNothing(x) Then
            MsgBox("Not Nothing")
        Else
            MsgBox("Nothing")
        End If
        x = "qwqw#"
        If Not IsNothing(x) Then
            MsgBox("Not Nothing")
        Else
            MsgBox("Nothing")
        End If
    End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:CplusPlus
ID: 9902066
its actually a struc as in Dim newStudent As Student
 
   Structure Student
        Public Name As String
        Public ID As String
        Public BirthYear As Integer
    End Structure
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 9902078
Try use the isdbnull function?

If IsDBNull(x) Then
       msgbox "is null"
   Else
       msgbox "not is null"
   End If
0
 

Author Comment

by:CplusPlus
ID: 9902192
does not work ryancys, but thanks anyway.
0
 
LVL 39

Accepted Solution

by:
appari earned 150 total points
ID: 9902207
you can try something like this

      Dim x As student
        x = Nothing
        If Not IsNothing(x.id) Then
            MsgBox("Not Nothing")
        Else
            MsgBox("Nothing")
        End If
0
 

Author Comment

by:CplusPlus
ID: 9902325
Thanks appari, but it seem odd you have to do that to make it work...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question