someone told me that i should stick with method #2, interested in getting feedback here.

form2 has an id that form1 passes in order to load information from.


method #1
has a public integer that form 1 passes to form 2

class form1

private sub button1_click
form2.id = 1
form2.pull_data
form2.show
end sub

end class

class form2

public id as integer = 0

public sub pull_data
select whatever from whatever where id = id
end sub

end class

method # 2
has a private integer on form 2 that a public function changes..

class form1
private sub button1_click
call form2.writeid(1)
call form2.pull_data
form2.show
end class

class form2
private id as integer = 0

public sub writeid(newid as integer)
me.id = newid
end sub

public sub pull_data
select whatever from whatever where id = id
end sub

end class

Recommended Answers

All 7 Replies

Unless you plan to reuse your "id" Integer from multiple Forms, method #2 is probably the best way to go about it.

it doesnt get reused anywhere

mind if i ask you why it is a better method though? (for my own knowledge)

A Global Declaration should be used for what it is.
There is no reason to add your "id" with the rest of the Global Declarations if only used once.

I would also add my "id" in the "public sub pull_data" if that Sub Procedure ends up having to use the "id" to process code.
If your "public sub pull_data" is needed for other results, not just for when the "id" is needed, Declaring something like "Static id as integer = newid" within that Sub Procedure should keep account for the "id"'s value.

Public Sub pull_data(Optional ByVal newid As Integer = 0)
        Static id As Integer = newid
        ' MsgBox(id)
        'select whatever from whatever where id = id
    End Sub

id gets used throughout the form for different things, pass it to other areas or update something in a db with that id thats why i declare it in the class for whenever i need it again

it doesnt ever change once it is passed to the form though

Under those circumstances, declaring your "id" at a Class Level, seems appropriate.
I just thought I would offer a suggestion about using a Static Declaration within a Sub Procedure.

thanks for the feedback/information

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.