Click here to Skip to main content
15,897,371 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Opinions needed on "shared" keyword Pin
Luc Pattyn12-Jan-12 8:16
sitebuilderLuc Pattyn12-Jan-12 8:16 
GeneralRe: Opinions needed on "shared" keyword Pin
nlarson1112-Jan-12 8:21
nlarson1112-Jan-12 8:21 
GeneralRe: Opinions needed on "shared" keyword Pin
Dave Kreskowiak12-Jan-12 8:32
mveDave Kreskowiak12-Jan-12 8:32 
GeneralRe: Opinions needed on "shared" keyword Pin
nlarson1112-Jan-12 8:38
nlarson1112-Jan-12 8:38 
GeneralRe: Opinions needed on "shared" keyword Pin
Dave Kreskowiak12-Jan-12 9:38
mveDave Kreskowiak12-Jan-12 9:38 
GeneralRe: Opinions needed on "shared" keyword Pin
Luc Pattyn12-Jan-12 8:34
sitebuilderLuc Pattyn12-Jan-12 8:34 
GeneralRe: Opinions needed on "shared" keyword Pin
nlarson1112-Jan-12 8:51
nlarson1112-Jan-12 8:51 
AnswerRe: Opinions needed on "shared" keyword Pin
Eddy Vluggen12-Jan-12 10:40
professionalEddy Vluggen12-Jan-12 10:40 
A Shared (static) method does not interact with the class it's defined in. Anything in your class that doesn't touch instance-members can be made shared.

Sometimes a procedural programmer will have trouble thinking in OO, generating lots of static methods that take lot's of parameters.

The OO-way makes it's handy to have all the parameters and other variables embedded in an object, and interact with those, each "group" of procedures becoming objects;
VB.NET
' If you got groups like these
shared Sub MySBSOpener(sbs as Object, HowMany as integer, ByRef TestCount as Integer)
shared Sub MySBSTester(sbs As Object, HowOften as integer, Verbose as Boolean)
shared Sub MySBSCloser(sbs as Object, Title as String, ByRef TestCount as Integer, Verbose as Boolean)

' consider these
Class SBS
  private _howMany as int
  private _howOften as int

  Public Sub New(HowMany as Integer, HowOften as Integer)
    _howMany = HowMany
    _howOften = HowOften 
  End Sub

  public Sub MyOpener() ' this sub now uses "Me" as the Object,
                        ' _howMany as a field
                        ' and puts the result in the TestCount property
  public Sub MyTester() ' other example sub use their parameters in their body
  public Sub MyCloser(Title As String) ' except title, which is still passed

  public property Verbose as Boolean
  public readonly property TestCount
    get
      return _testCount
    end get
  end property

End Class

This has the advantage that you can populate a list with these things, something that's a bit harder to do if all methods are static.
Bastard Programmer from Hell Suspicious | :suss:

GeneralRe: Opinions needed on "shared" keyword Pin
nlarson1113-Jan-12 2:44
nlarson1113-Jan-12 2:44 
GeneralRe: Opinions needed on "shared" keyword Pin
Eddy Vluggen13-Jan-12 6:34
professionalEddy Vluggen13-Jan-12 6:34 
QuestionDynamic dropdowns enable without post back Pin
byka12-Jan-12 6:31
byka12-Jan-12 6:31 
AnswerRe: Dynamic dropdowns enable without post back Pin
DannyStaten12-Jan-12 10:39
DannyStaten12-Jan-12 10:39 
QuestionChanging default value of a property of a control (DataGridView). Pin
priyamtheone12-Jan-12 3:16
priyamtheone12-Jan-12 3:16 
Answere: Changing default value of a property of a control (DataGridView). Pin
Simon_Whale12-Jan-12 3:41
Simon_Whale12-Jan-12 3:41 
QuestionRe: e: Changing default value of a property of a control (DataGridView). Pin
priyamtheone14-Jan-12 3:27
priyamtheone14-Jan-12 3:27 
AnswerRe: Changing default value of a property of a control (DataGridView). Pin
Wayne Gaylard12-Jan-12 3:47
professionalWayne Gaylard12-Jan-12 3:47 
QuestionDirectShowLib Adjust Camera Brightness Pin
ggoutam711-Jan-12 17:31
ggoutam711-Jan-12 17:31 
QuestionVB2010 Serial Port Tutorial? Pin
JDBravo11-Jan-12 9:19
JDBravo11-Jan-12 9:19 
Answercheck this article out Pin
David Mujica11-Jan-12 10:02
David Mujica11-Jan-12 10:02 
GeneralRe: check this article out Pin
JDBravo11-Jan-12 10:11
JDBravo11-Jan-12 10:11 
AnswerRe: VB2010 Serial Port Tutorial? Pin
Luc Pattyn11-Jan-12 11:02
sitebuilderLuc Pattyn11-Jan-12 11:02 
GeneralRe: VB2010 Serial Port Tutorial? Pin
JDBravo11-Jan-12 11:48
JDBravo11-Jan-12 11:48 
AnswerRe: VB2010 Serial Port Tutorial? Pin
Luc Pattyn11-Jan-12 12:09
sitebuilderLuc Pattyn11-Jan-12 12:09 
GeneralRe: VB2010 Serial Port Tutorial? Pin
JDBravo12-Jan-12 4:15
JDBravo12-Jan-12 4:15 
GeneralRe: VB2010 Serial Port Tutorial? Pin
JDBravo12-Jan-12 6:19
JDBravo12-Jan-12 6:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.