Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Modules not initializing

Modules not initializing

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treddie
    wrote on last edited by
    #1

    Hi. I have encountered a peculiar problem with modules that I have never seen before. Here is a very simple example to demonstrate my point:

    Module Module1
    Dim x as integer = 1
    End Module

    Module Module2
    Dim y as integer =2
    End Module

    Private Sub Form_Load(bla, bla, bla)
    Me.Text = Str(x+y)
    End Sub

    When the program runs, both modules are automatically initialized so that the result is the value "3" getting sent to the form. Up to now, I have never had a problem with modules not getting initialized. But in a new project I am working on, one gets initialized and the other does not. One of them simply does not get recognized. Adding Public to both/either does not help. Does anyone have an idea as to the kinds of things that can cause this to happen? Many thanks! :)

    L 1 Reply Last reply
    0
    • T treddie

      Hi. I have encountered a peculiar problem with modules that I have never seen before. Here is a very simple example to demonstrate my point:

      Module Module1
      Dim x as integer = 1
      End Module

      Module Module2
      Dim y as integer =2
      End Module

      Private Sub Form_Load(bla, bla, bla)
      Me.Text = Str(x+y)
      End Sub

      When the program runs, both modules are automatically initialized so that the result is the value "3" getting sent to the form. Up to now, I have never had a problem with modules not getting initialized. But in a new project I am working on, one gets initialized and the other does not. One of them simply does not get recognized. Adding Public to both/either does not help. Does anyone have an idea as to the kinds of things that can cause this to happen? Many thanks! :)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      treddie wrote:

      But in a new project I am working on, one gets initialized and the other does not.

      Modules are initialized on first use, and the compiler has no incentive to change that behaviour. It should act as a static class does in C#.

      treddie wrote:

      Does anyone have an idea as to the kinds of things that can cause this to happen?

      Check your usings; is there any "Module2" in the other namespaces? If there is, then it might be calling the wrong module. Further, those x and y values should be prefixed with their module-name, to ensure that they're taken from that module (and not some other "global" function called "x").

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      T 1 Reply Last reply
      0
      • L Lost User

        treddie wrote:

        But in a new project I am working on, one gets initialized and the other does not.

        Modules are initialized on first use, and the compiler has no incentive to change that behaviour. It should act as a static class does in C#.

        treddie wrote:

        Does anyone have an idea as to the kinds of things that can cause this to happen?

        Check your usings; is there any "Module2" in the other namespaces? If there is, then it might be calling the wrong module. Further, those x and y values should be prefixed with their module-name, to ensure that they're taken from that module (and not some other "global" function called "x").

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        T Offline
        T Offline
        treddie
        wrote on last edited by
        #3

        Eddy Vluggen wrote:

        Check your usings; is there any "Module2" in the other namespaces?

        No, no others.

        Eddy Vluggen wrote:

        Modules are initialized on first use, and the compiler has no incentive to change that behaviour.

        OK, I think I see what you mean. The form_load procedure is referencing two variables with each declared in each module. Since they are both referenced in the form_load procedure, both modules initialize. But when I change the variable in module2 to "z" instead of "y", there is no reference for it in the form_load, so the compiler deems module2 uneccessary at the present time. At least a test of this confirms it in principle.

        Eddy Vluggen wrote:

        those x and y values should be prefixed with their module-name

        That part I knew about...I was just making a very simple demo which was not "safe".

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups