Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi. I have 2 questions here regarding classes and Subroutines. I am a noob at vb still and pls excuse my stupidity Smile | :)
 
I hope u can help me
 

I have 2 Subroutines in the same Class:
Public Sub DataCapture(ByVal PAGE As Integer, MOTOR As String)
 
 If PAGE = 1 Then
 
 End If
 .
 .
 .
 .
 .
 .
 .
 
PAGE = 12
 
End Sub
 
Private Sub MotorCheck()
 
 If DataCapture.Motor = 1 Then
 
 End If
 .
 .
 .
 .
 .
 
 DataCapture.Motor = 12
 
End Sub
 

 

 
My First Question :
 
is it correct to access the DataCapture's MOTOR variable by simple calling DataCapture.Motor
 
My Second Question
 
I want to run the Private Sub In every if statement of the public sub. How do i to this since they are both in the same class
 

That Is all. I hope you can help me, it is greatly appreciated!
 
Travis
Posted 18-Nov-12 14:44pm
Comments
doomandgloom at 18-Nov-12 21:12pm
   
Hello try this:
 
Put this into a button:
 
Call DataCapture(1, "string")
 

This will call the sub an give a value to the variables PAGE and STRING
 
You then use these variables in the sub that you have just called:
 
If PAGE = 1 then
If STRING = "This is a string" then
 
Something like that.
 
Keep at it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

From the first question, I can assume that "DataCapture" in DataCapture.Motor the same thing as the method DataCapture. If this is so, the whole idea is wrong. There is no such object (and of course there is no such syntax), and I cannot even explain what's wrong the way you could understand it based on your knowledge. I'll just say a few words, but you need to go back and read on the very basics of the most elementary notions of programming. There is no such object as Motor outside of the context of this method. This is a parameter — something which is passed to a method during the call, and the object is used withing the stack frame of the method only during the run time, when the method is executed. If the type of the parameter is a reference type, the reference is copied on stack, if this is a value type, the whole object is copied on stack; upon exit, the objects are removed from stack, the stack memory physically still exists, but used by other objects outside the method execution. Is that clear? I don't think so — you need to learn all the basics; sorry, but I cannot instantaneously write a whole book starting from so elementary levels. Just read some elementary book to get basics.
 
Same thing about second question. Methods are always called inside other methods. There is nothing to explain. If you require explanations, it means you need to learn what is a type, and type instance, method, class, structure and their members, what is method parameters, parameter passing by value and by reference, passing data in static and non-static (instance) methods.
 
I don't want to ask you what you want to achieve and give you cookbook recipe — it cannot help you.
 
—SA
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I figured what i was trying to do was too complicated and there was a simple more stright forward method
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Nirav Prabtani 268
2 Richard Deeming 215
3 CHill60 170
4 _Amy 145
0 OriginalGriff 8,104
1 Sergey Alexandrovich Kryukov 7,045
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100