Author Topic: Probably a daft question ....  (Read 1914 times)

Offline roadhouse

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Probably a daft question ....
« on: February 15, 2010, 09:04:10 PM »
Sorry if this is a stupid question but I'm returning to programming after many many years and still gettin to grips with OOP.

In VB2008, I can get the demo files to run no problem. But if i try to write my own code based on the demos I get constant erros about 'reference to a non-shared member requires an object reference'  and messages about 'handles' not being defined in a variable first when using event handlers. I can get round this by declaring a variable first then using that but I would realy like to know if i am doing something fundamentally wrong here. For example,

In the proximitydemo the library is refreneced like this...

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

but in my programs I have to use...

Private Sub fmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim x As wcl.wclAPI = New wcl.wclAPI
        x.Load()
    End Sub

Which then works.

Dont worry, I'm not looking for a VB primer, i appreciate thats not what you are here for. But I am so confused about why it works one way with the demo code and not when I try to write the same code in my own programs ? As a beginner, its causing me some considerable confusion when having to dimension variables all over the place. Your demo code looks much easier to follow.

Is there something else I have to do to my VB environment to get it to work like the demo ? a reference or a system setting or something else ?

Cheers



Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: Probably a daft question ....
« Reply #1 on: February 15, 2010, 09:52:20 PM »
Hi,

Because X is local variable. When routine is done (exited) variable is destroyed. Declare it as global or drop component on the form.

Offline roadhouse

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Probably a daft question ....
« Reply #2 on: February 15, 2010, 11:30:00 PM »
Thanks Mike,

So I can drop the 'WCL' component directly onto the form ? thats pretty cool.

If i can be cheeky and ask one more question, how do I do that ? I can load the WCL library as a reference but it doesnt appear in the component toolbox.

Sorry for the newbie questions, but I'm desperatley trying to find my way round this stuff and the internet resources for people like me are so thin on the ground. Most assume you know all this stuff and go directly into talking technical.

In my job i'm a Cisco Design Architect (CCNA,CCDA,CCDP) I'm not techically inept, just not a programmer.

Be gentle and Thanks for your help.
Cheers

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: Probably a daft question ....
« Reply #3 on: February 15, 2010, 11:32:30 PM »
Hi,

Right click on toolbox -> Add toolbox item->Select wcl.dll and its components.

All those things are very good described in Visual Studio Help system

Offline roadhouse

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Probably a daft question ....
« Reply #4 on: February 21, 2010, 06:13:56 PM »
Hi Mike,

Thanks for the advice. I have it working now. Although it would not let me drag and drop the wclAPI component onto the form directly, I was able to get round it using Me. declarations instead.

Thaks again.

Cheers

 

Sitemap 1 2 3 4 5 6 7 8 9