Go Back   Access World Forums > Apps and Windows > VB.NET

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-06-2019, 11:17 PM   #1
Ryobi
Newly Registered User
 
Join Date: Mar 2012
Posts: 33
Thanks: 1
Thanked 1 Time in 1 Post
Ryobi is on a distinguished road
Exclamation Calling a public procedure

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

Ryobi is offline   Reply With Quote
Old 04-07-2019, 04:53 AM   #2
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,365
Thanks: 555
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Calling a public procedure

Quote:
Originally Posted by Ryobi View Post
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.
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 04-07-2019, 08:05 AM   #3
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,888
Thanks: 38
Thanked 571 Times in 538 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: Calling a public procedure

Quote:
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.

MajP is online now   Reply With Quote
Old 04-07-2019, 09:21 AM   #4
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,365
Thanks: 555
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Calling a public procedure

Quote:
Originally Posted by MajP View Post
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
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 04-07-2019, 11:51 AM   #5
Ryobi
Newly Registered User
 
Join Date: Mar 2012
Posts: 33
Thanks: 1
Thanked 1 Time in 1 Post
Ryobi is on a distinguished road
Re: Calling a public procedure

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.
Ryobi is offline   Reply With Quote
Old 04-07-2019, 12:34 PM   #6
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,888
Thanks: 38
Thanked 571 Times in 538 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: Calling a public procedure

Quote:
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 is online now   Reply With Quote
Old 04-07-2019, 02:11 PM   #7
Ryobi
Newly Registered User
 
Join Date: Mar 2012
Posts: 33
Thanks: 1
Thanked 1 Time in 1 Post
Ryobi is on a distinguished road
Re: Calling a public procedure

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.

Ryobi is offline   Reply With Quote
Old 04-07-2019, 02:27 PM   #8
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,365
Thanks: 555
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Calling a public procedure

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

Quote:
Originally Posted by Ryobi View Post
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.
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 04-07-2019, 05:02 PM   #9
Ryobi
Newly Registered User
 
Join Date: Mar 2012
Posts: 33
Thanks: 1
Thanked 1 Time in 1 Post
Ryobi is on a distinguished road
Re: Calling a public procedure

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.

Ryobi is offline   Reply With Quote
The Following User Says Thank You to Ryobi For This Useful Post:
Uncle Gizmo (04-07-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling public sub from another form petko Modules & VBA 20 06-29-2017 12:03 AM
Calling public sub and updating all fields kmanji Forms 2 11-22-2016 05:38 AM
calling a public function from a module jasn_78 Modules & VBA 28 03-03-2014 08:53 PM
Calling a public procedure on a subform SmallTime Modules & VBA 13 05-13-2013 03:19 PM
Calling a Public Sub from its SubForm dbay Forms 3 03-05-2011 03:33 PM




All times are GMT -8. The time now is 01:32 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World