Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi. I have 2 questions here regarding classes and Subroutines. I am a noob at vb still and pls excuse my stupidity :)

I hope u can help me


I have 2 Subroutines in the same Class:
VB
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
Comments
tm9333 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.

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
 
Share this answer
 
v2
I figured what i was trying to do was too complicated and there was a simple more stright forward method
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900