• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Simple?? VB.net question"

Collapse

  • xoggoth
    replied
    That works although same problem with my original code. I was thinking that the inaccessibility error was a general problem in not being able to access the form, in fact it was just a specific function of that form that is protected. Don't need to use it anyway (it was just an example I copied off an MS page) so problem sorted. Ta chaps!
    Last edited by xoggoth; 29 May 2007, 08:37.

    Leave a comment:


  • ASB
    replied
    Bored so:-

    as buffdaddy says you should probably be passing it by value unless you are tring to return a different form than the one passed in - which migh be unhelpful

    Anyway this is fine:-

    Module Module1
    Public Sub EnableDoubleBuffering(ByRef frm As System.Windows.Forms.Form)
    frm.Text = "QQQQ"
    End Sub

    End Module

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Module1.EnableDoubleBuffering(Me)
    Dim a As New Form2

    'Has to be a type of Form because it will foul up due to narrowing if not.
    Dim b As Form
    b = a
    a.AA(b)

    End Sub
    End Class

    Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Friend Sub AA(ByRef frm As System.Windows.Forms.Form)
    Module1.EnableDoubleBuffering(Me)
    Module1.EnableDoubleBuffering(frm)
    End Sub
    End Class

    Whether it is sensible or any help is a different matter of course.

    Leave a comment:


  • buffdaddy
    replied
    not sure why you are passing the Form in by ref. It should work without the ref since the Form is a Reference Type
    http://msdn2.microsoft.com/en-us/lib...s2(VS.80).aspx

    i tried this quickly (in c# winforms), and it works

    Leave a comment:


  • xoggoth
    started a topic Simple?? VB.net question

    Simple?? VB.net question

    Got a useful answer last time, so worth a try.

    I just want to stick all the common functions called from different forms in one place rather than duplicate code, and for some I need to pass forms by reference to those functions. But if I have something like:-

    Public Sub EnableDoubleBuffering(ByRef frm As System.Windows.Forms.Form)

    in a public module or class, any reference to frm gives 'not accessible in this context because it is protected'.

    The solutions I have looked at on the net all seem to to be along the lines of declaring a new instance of, or inheriting from, a specific form class, however:-

    a) frm does not necessarily always refer to the same form class
    b) frm could refer to different instances of the same form class

    I can think of a rather messy solution to a) but not sure how to handle b). Ta for any answers.

Working...
X