Passing literals to functions - Whats happening 
Author Message
 Passing literals to functions - Whats happening

Playing with DotNet, came across the following :-

When passing a literal to a sub or function ie SayHello("Hello World")

where function has following definition

SayHello(byval themessage as string)

you get nullpointerexception errors, if you try to access 'themessage' ie
themessage.length

Is this because under the covers the SayHello method is expecting a string
object, which a literal isnt?

Thanks



Sun, 27 Jun 2004 17:31:16 GMT  
 Passing literals to functions - Whats happening
This seems to work just fine for me.  It was probably a bug in older
versions, but passing a literal in is not a problem.

Matthew Arnheiter


Quote:
> Playing with DotNet, came across the following :-

> When passing a literal to a sub or function ie SayHello("Hello World")

> where function has following definition

> SayHello(byval themessage as string)

> you get nullpointerexception errors, if you try to access 'themessage' ie
> themessage.length

> Is this because under the covers the SayHello method is expecting a string
> object, which a literal isnt?

> Thanks



Mon, 28 Jun 2004 06:11:16 GMT  
 Passing literals to functions - Whats happening
Richy,
Are you initializing the object that the SayHello method belongs to?

Can you post a snippet of code that completely demostrates where this fails.

The literal will be converted into a string object when VB.NET calls your
method.

Hope this helps
Jay


Quote:
> Playing with DotNet, came across the following :-

> When passing a literal to a sub or function ie SayHello("Hello World")

> where function has following definition

> SayHello(byval themessage as string)

> you get nullpointerexception errors, if you try to access 'themessage' ie
> themessage.length

> Is this because under the covers the SayHello method is expecting a string
> object, which a literal isnt?

> Thanks



Mon, 28 Jun 2004 08:19:45 GMT  
 Passing literals to functions - Whats happening
Below is my code and it worked fine.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

        Dim a As New ClassA()
        MessageBox.Show(a.SayHello("garygu"))

    End Sub
End Class

Public Class ClassA

    Public Function SayHello(ByVal themessage As String) As Long
        Return themessage.Length
    End Function

End Class

I am using RC3. How about yours? If possible, please post here more code.

Regards,

This posting is provided ?AS IS?, with no warranties, and confers no
rights.



Fri, 02 Jul 2004 18:02:22 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. whats happening here???

2. Microsoft doesn't know whats happening??

3. Whats happening to VB

4. Microsoft doesn't know whats happening??

5. DBGrids Whats happening

6. Microsoft doesn't know whats happening??

7. Whats wrong with this... (dealing with ini functions)

8. Whats behind VB functions and procedures

9. What happened to Date() Function in Access

10. What happened to the STR function?

11. What happened to the Format function?

12. What happened to GetFreeSystemResources function?

 

 
Powered by phpBB® Forum Software