Calling a public procedure (1 Viewer)

Ryobi

Registered User.
Local time
Today, 12:02
Joined
Mar 5, 2012
Messages
49
Hello,


I hope somebody can help me with this simple problem. I created a public procedure in a Class module, but for some reason I can not call the procedure from a form. The code on the Class module is as follows:


Public Class Module1
Public FileInuse As String
Public Sub GetDataFile()

Dim file_path As String = Application.StartupPath
file_path = file_path.Substring(0,
file_path.LastIndexOf(""))
FileInuse = file_path & "\DataFile.txt"

End Sub

End Class



The code on the form is as follows:


Dim Datafile As String
GetDataFile()
Datafile = FileInuse


I am trying to get the value of the of the public string FileInuse, but for some reason it does not want to work. I have tried Call GetDatafile(), Datafile() and Datafile but not luck. Ideally, I just want want the value of the FileInuse without calling the procedure such:


Dim Datafile As String Datafile = FileInuse


But the Fileinuse does not have a value because the produrec needs to be called.


Any ideas or suggestions are well come.



Thanks
 
but you cannot call them from a class module
You also appear to be very confused. In VB.NET you most certainly can call a procedure in a class module without instantiating an object as long as that procedure is shared. However, I agree this is a poorly written class. Class variables should be private and accessible through properties.
 
Thank you for replying. You are correct in regarding to the confusion between a class and module. I revised the code and used a module to create a global variable that will hold the file name. It regard to MsAccess question, it not not MsAccess question it is a Vb.net question. What I want to do is create a windows form program in VB.net and connect to the the data which is in a Msaccess file.
 
put the OP's code in both a module and a class and you will be confused too!
Not really, I am proficient in .NET so I understand how to call a shared procedure from a class module without instantiation.
 
MajP,


I am sorry for any misunderstanding. I was referring to Uncle Gizmo who posted that the question was for MsAccess not Vb.net forum.
 
Thank you for the suggestion, but I am somewhat familiar with .net. I think you did point the the problem I that was be confused between a class and module. I know what I need, but it is hard figure out where to put the information. In Msaccess it very easy, that's where the confusion part came plus the fact that I just learning visual studio 2017.
 

Users who are viewing this thread

Back
Top Bottom