Results 1 to 14 of 14

Thread: VB.NET and forms problems

Threaded View

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

    I see. It only fails when you assign a value to Pippo AFTER the instantiation of F1. In

    ' ------------ It fails begin ----------------------------
    Public F1 As New Form1

    Sub main()
    Application.Run(F1)
    End Sub

    Public Pippo As String = "0"
    ' ----------- It fails end -----------------------------

    The program flow is exactly as listed, so that when F1 is instanced, Pippo has not been given a value and you get a Null Reference exception in F1 at

    Dim pluto As Byte = Byte.Parse(Pippo)

    However, in

    ' ------------ It works n.2 begin ------------------------------

    'Public Pippo As String = "0"
    'Public F1 As New Form1

    'Sub main()
    ' Application.Run(F1)
    'End Sub

    ' ------------ It works n.2 end ------------------------------

    Pippo is declared with a value BEFORE F1 is processed.


    In


    ' ------------ It works begin ------------------------------
    'Public F1 As Form1

    'Sub main()
    ' F1 = New Form1
    ' Application.Run(F1)
    'End Sub

    'Public Pippo As String = "0"
    ' ------------ It works end ------------------------------

    The program flow is such that the Sub Main is processed AFTER Pippo has been declared and FI instance is only processed AFTER the NEW keyword.

    Conclusions:

    Either do it as you suggest and Declare the variable F1 without creating the instance of Form1 at that time; OR

    Make sure you declare and fill all public variables BEFORE creating instances of forms in which those variables will be used.

    Many thanks for all your effort. It is good to be aware of possible problems.
    Last edited by taxes; Jul 4th, 2004 at 12:34 PM.
    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