2009-12-29 10 views
-1

Comment puis-je corriger l'erreur suivante:La référence à un membre non partagé requiert une référence d'objet vb.net?

Error 1: "Reference to a non-shared member requires an object reference." 

On Line:

shortCut = CType(WshShell.CreateShortcut(creationDir & "\" & shortcutName & 
    ".lnk"), IWshRuntimeLibrary.IWshShortcut) 

Voici mon échantillon complet de code (si nécessaire pour le contexte):

Imports IWshRuntimeLibrary 
Module MainModule 
    Public Function CreateShortCut(ByVal shortcutName As String, ByVal creationDir As String, ByVal targetFullpath As String, ByVal workingDir As String, ByVal iconFile As String, ByVal iconNumber As Integer) As Boolean 
     Try 
      If Not IO.Directory.Exists(creationDir) Then 
       Dim retVal As DialogResult = MsgBox(creationdir & " does not exist. Do you wish to create it?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo) 
       If retVal = DialogResult.Yes Then 
        IO.Directory.CreateDirectory(creationDir) 
       Else 
        Return False 
       End If 
      End If 

      Dim shortCut As IWshRuntimeLibrary.IWshShortcut 
      shortCut = CType(WshShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut) 
      shortCut.TargetPath = targetFullpath 
      shortCut.WindowStyle = 1 
      shortCut.Description = shortcutName 
      shortCut.WorkingDirectory = workingDir 
      shortCut.IconLocation = iconFile & ", " & iconNumber 
      shortCut.Save() 
      Return True 
     Catch ex As System.Exception 
      Return False 
     End Try 
    End Function 
+0

s'il vous plaît fournir une question réelle avec un fond de ce que vous essayez de faire en plus du code. Sur quelle ligne arrivez-vous? Allez-vous accepter une réponse? –

Répondre

2

Cela signifie que vous » re en utilisant une instance d'une classe pour qualifier l'un de ses membres partagés au lieu de la classe elle-même. Par exemple:

Class C 
    Public Shared x As Integer 
End Class 
Module M 
    Sub S(instance as C) 
     dim x1 = instance.X 'warning 
     dim x2 = C.X 'proper 
    End Sub 
End Module 
+0

pouvez-vous s'il vous plaît expliquer comment je voudrais le réparer –

+0

Sur quelle ligne obtenez-vous l'avertissement? –

+1

oh désolé de ne pas mettre ça! shortCut = CType (WshShell.CreateShortcut (creationDir & "\" & raccourciName & ".lnk"), IWshRuntimeLibrary.IWshShortcut) –

0

Vous devez créer une instance de WshShell, je pense:

Dim NewWshShell As New WshShell

utilisent maintenant newWshShell en place de WshShell

+0

@Alex, cette réponse a-t-elle fonctionné pour vous? –