3 Replies - 344 Views - Last Post: 30 August 2019 - 02:38 PM Rate Topic: -----

#1 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 04-January 14

Reference to a non-shared member requires an object reference

Posted 27 August 2019 - 10:23 PM

Hi
Getting this error within a Module when referencing my Forms and Form Controls.

This is my 3rd project and never had this issue before.
I created this temporary Module to test the main Module

Refers to 2 forms Main & Rite. pRight is a Panel

Module Module1
	'
	Public TW, TWH, TH, LW, LH, Mw, Mh, RW, RH As Integer
	Public LPH, LPW, RPH, RPW As Integer
	Public Lx, Ly, Mx, My, Rx, Ry, xpos1, ypos1 As Integer
	Public PLx, PLy, PRx, PRy As Integer
	Public DE As Integer = 0
	Public newpoint As System.Drawing.Point
	Public started As Boolean = False
	'
	Sub temp()
		'
		Main.Focus()
		Rite.pRight.location = New Point(Lx, Ly)
		'
	End Sub
	'
End Module




I'm sure it's a simple solution - googling for an answer did not help though

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Reference to a non-shared member requires an object reference

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15260
  • View blog
  • Posts: 61,140
  • Joined: 12-June 08

Re: Reference to a non-shared member requires an object reference

Posted 27 August 2019 - 10:30 PM

You wouldn't be using modules with winforms. A class would be better as modules tend to be for consoles.

Also you should be declaring instances of your forms before you use them.

Example - if your form is called 'form1' in the solution then you would do something like

dim foo as new form1

foo.show

..etc.
Was This Post Helpful? 1
  • +
  • -

#3 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 04-January 14

Re: Reference to a non-shared member requires an object reference

Posted 27 August 2019 - 10:51 PM

Hi

My Form is within a class

Imports System.Data.OleDb, System, System.IO
Imports System.Web
Imports System.Net.Mail
Imports System.Net.Mail.Attachment
Imports System.Runtime

Public Class Main

	Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		'
		'pMain.Visible = False
		Me.Top = 0
		Me.Left = 0
		TH = Screen.PrimaryScreen.WorkingArea.Height
		TW = Screen.PrimaryScreen.WorkingArea.Width
		TWH = CInt(TW / 2)
		'
		If started = False Then startup()
		'
		started = True
		Ctrl.Show(Me)
		'
	End Sub
	'
End Class





I have since discovered that if I remove the declarations from my main Module which are duplicated in the temp Module as shown then the problem disappears.

thanks
Was This Post Helpful? 0
  • +
  • -

#4 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 24
  • Joined: 04-January 14

Re: Reference to a non-shared member requires an object reference

Posted 30 August 2019 - 02:38 PM

Hi

Found the problem and was a simple issue.

If you look at my declarations, you'll see that I've used a keyword in their and once removed the problem evaporated.

Was able to remove the temp module and now waiting for My hair to grow back.

thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1