Calling a public procedure (2 Viewers)

Ryobi

Registered User.
Local time
Today, 12:18
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
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:18
Joined
Jul 9, 2003
Messages
16,244
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:

Code:
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:

Code:
      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:

Code:
 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

You appear to be very confused. First of all you have posted in The VB.Net forum, but you appear to be asking a question about a Microsoft Access. It would be helpful if you could clear that up. Secondly it appears you are confusing class modules and standard modules, you can call routines from a standard module but you cannot call them from a class module.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:18
Joined
May 21, 2018
Messages
8,463
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.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:18
Joined
Jul 9, 2003
Messages
16,244
You also appear to be very confused

I am, put the OP's code in both a module and a class and you will be confused too!

Sent from my SM-G925F using Tapatalk
 

Ryobi

Registered User.
Local time
Today, 12:18
Joined
Mar 5, 2012
Messages
49
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:18
Joined
May 21, 2018
Messages
8,463
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.
 

Ryobi

Registered User.
Local time
Today, 12:18
Joined
Mar 5, 2012
Messages
49
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.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:18
Joined
Jul 9, 2003
Messages
16,244
Well I definitely owe you an apology! I was operating under the assumption that you were working in MS Access and had posted in the wrong forum! Which is why I was confused! - please ignore my previous misguided comments.

With regard to:-

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.

I do recall seeing some very good YouTube videos on working in VB.Net, Mind you it was a while ago so I'm not sure I could find them, but if you wanted to go the route I could have a look see.
 

Ryobi

Registered User.
Local time
Today, 12:18
Joined
Mar 5, 2012
Messages
49
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

Top Bottom