Results 1 to 6 of 6

Thread: How to declare this variable

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    How to declare this variable

    Im working with the infragistics ultra tab control. It is very neat way of creating tabs. The easiest way to add info the the tabs is to place all your controls etc in a user control and then add that UC to the tab you want it.

    But you can't access the controls like mytab.tab(0).findcontrol("textbox1")

    I have therefor written a shared helper class (which infragistics suggested) where you pass a reference to the tab, the ID of the usercontrol and the ID of the control, then it loops through the control collections and return a reference you can work with

    like

    VB Code:
    1. Dim lbansvarig As ListBox = CType(WebTabHelper.GetChildControlFromUserControl(Me.uwtDriftStopp, "URegistrera1", "lbansvarig"), ListBox)
    2.         'btnNewDelete.Enabled = False
    3.  
    4.        dim item as string =  lbAnsvarig.Items.Count.tostring


    NOW here is my issue... Say I wan to manipulate textbox3 on four different places in a class like reading value, reset value and writing value, in different methods..

    Where in my class structure is most appropriate to create the reference? Like I do it now I create all references to all textboxes on page_load... What I really need is only ONE reference that can work with all the textboxes, one for labels etc...

    but where in the code is most appropriate to write

    dim myTextBox as TextBox ?

    Should it infact be a class property???????????????????????????

    Or should I write it as public class variables? It feels like this is a common architectural problem,a dn there should be a good way to do it? A pettern perhaps?

    I hope you understand my concern?

    kind regards
    Henrik

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Couldn't you use

    Public myObject as object

    and then


    myObject=TextBox1 etc?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Yeah of course I could do that....

    I was more concerned how I would declare the variable itself, not the type it has...

    Const

    Property

    dim


    etc...


    kind regards
    Henrik

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Sorry, I don't follow you. I thought you were saying that you wanted to reduce the number of variables you had to declare.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Hmm yes.. I was afraid it sounded stupid...

    Using one ref variable is a good way and declaring it as object is also great, but the thing I wanted to know is how I would handle such a variable to maintain encapsulation... Should I declare it a sprivate and put a property around it, or does it look just as nice to have it as a dim in every method where I need to access a particular control?


    kind regards
    Henrik

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I think you have to declare it public or else you might end up with several instances of it. Perhaps you could use the containing object variable in a sub and pass the object you want to reference to that sub by way of a parameter.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width