Rivermen Posted January 20, 2004 Posted January 20, 2004 Hej I need help with sub and how it works´.... I got a module1 and i will put the string in to my class..... Module Module1 Sub Main() Dim text As String = "Send to class" Class1.Getvalue(text) End Sub End Module ........ The class1 will take the string, but it need to be a shared sub to work. ......... Public Class Class1 Shared Sub Getvalue(ByVal texta As String) Console.Write(texta) End Sub ............. And now I can write out the string... but i need the string in a another sub, a Public Sub . ............. Public Sub Console.Write(texta) End Class ............................... But texta i now out of range of the declaration.. how should i do it..... i think i have missed some basic knowledge. Please bring it back to me :-) // Rivermen Quote
jwHerm Posted January 20, 2004 Posted January 20, 2004 Why dont you just call the last sub from the middle one and send it the variable? Also, are these all in the same form/module? If so you could dim a private for the form/module and just set the text to that on the first passing of the variable. Hope that makes sense. Quote
Rivermen Posted January 20, 2004 Author Posted January 20, 2004 It make some sens The modul Is in one file and the class is in another. So you mean I should send the string from the Shared Sub to the Public Sub I forget to name the sub in the previous post but it sholud be, Public Sun Run() for exampel. And to "send" the stringe should like this.. ------- Shared Sub Getvalue(ByVal texta As String) Console.Write(texta) Run(texta) End Sub Public Sub Run(ByVal text2 As String) Console.Write(text2) End Class but it dosent work.... I got this error msg on Run(texta) Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. // Ready for more help :-) Quote
jwHerm Posted January 20, 2004 Posted January 20, 2004 Did you try a dim statement in the shared sub so that you are not passing the actual instance variable? Like: Shared Sub Getvalue(ByVal texta As String) dim newText as string = texta Console.Write(texta) Run(newText) End Sub I think that should work. Quote
Rivermen Posted January 20, 2004 Author Posted January 20, 2004 Maybe It should work, but it dosent. Can you or somebody else try.... just to put in this code.... ----- Public Class Class1 Shared Sub Test() Dim Texts As String = "To public Sub" Console.Write(Texts) Run(Texts) End Sub Public Sub Run(ByVal text2 As String) Console.Write(text2) Console.Write(Texts) End Sub End Class ----- I want to send a string from a shared sub to public or that I can use the variabel in Shared Sub in my Public Sub... Thanksful for all help!!!! //Rivermen Quote
Administrators PlausiblyDamp Posted January 20, 2004 Administrators Posted January 20, 2004 The problem you are having is that GetValue is a shared class member and Run isn't. Shared members of a class work without a specific instance i.e. you could do something like Class1.GetValue("dsafsdafsadf") but non-shared members need a specific instance to be created i.e. dim c as new class1 c.Run("ewrewrwerwerewr") Is there any reason GetValue is shared? It may help if you gave a bit more background on what you are trying to do though. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Rivermen Posted January 21, 2004 Author Posted January 21, 2004 ohhhhh tnx you saved me :-) The Dim C as New class1 made it work. The reason I have the GetValue Shared is that i want to send a string from a seperat modul1 to a class, and the only way i get it to work was with a Shared Sub in the class1. Maybe it will work another way... but i dont know.... maybe you got some answer for that to :-) Thanks again to your both that help me.... // Rivermen Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.