---
title: "problem att starta metoden"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/161693-problem-att-starta-metoden"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "Vinnaren"
published: "2007-06-19T13:09:19.000Z"
updated: "2007-06-24T13:21:03.000Z"
replies: 10
views: 666
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/161693-problem-att-starta-metoden"
---

# problem att starta metoden

## #1 — Vinnaren, 2007-06-19T13:09Z

Hej

Jag får inte igång min metod, ShowInfo.

koden jag har:

```
Public Class Form1
    Private mybox As Box
    Private info As arvBox

    Private graphArea As Graphics

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mybox.MoveUpp(20)
        graphArea.Clear(gPic.BackColor)
        mybox.ShowBox(graphArea)
    End Sub
End Class
```

 

```
Public Class Box
    Public x As Integer = 10 'Private
    Public y As Integer = 50
    Public widthR As Integer = 15
    Public heightR As Integer = 15
    Dim myPen As Pen = New Pen(Color.Red, 2)

    Public Sub ShowBox(ByVal graphArea As Graphics)
        graphArea.DrawRectangle(myPen, x, y, widthR, heightR)
    End Sub

    Public Sub MoveUpp(ByVal dy As Integer)
        y -= dy
    End Sub
End Class
```

 

Det är denna jag vill starta, men det vill sig inte  :( 

```
Public Class arvBox
    Inherits Box

    Public Sub ShowInfo(ByVal graphArea As Graphics)
        Dim sb As SolidBrush = New SolidBrush(Color.Red)
        Dim st As String = x & " " & y
        Dim f As Font = New Font("Arial", 12, FontStyle.Bold)
        graphArea.DrawString(st, f, sb, x, y)
    End Sub

End Class
```

 

Har provat med 

```
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mybox.MoveUpp(20)
        graphArea.Clear(gPic.BackColor)
        mybox.ShowBox(graphArea)
        

        info.ShowInfo(graphArea)

    End Sub
```

 

Men får då felmeddelandet:
Objektreferensen har inte angetts till en instans av ett objekt.

Hur löser jag detta??

Tacksam för all hjälp   :stud

Permalänk: https://www.webforum.nu/p/161693

## #2 — P, 2007-06-19T14:19Z

Någonstans måste du instansiera "info".

```
info = new arvBox()
```

Permalänk: https://www.webforum.nu/p/1994395

## #3 — Vinnaren, 2007-06-19T14:24Z

ok, tack, hade visst glömt () efter arvBox.

Men nu får jag felmeddelandet:
'ShowInfo' is not a member of 'System.Array'.

på raden:

info.ShowInfo(graphArea)

Hur löser jag det?   :q

Permalänk: https://www.webforum.nu/p/1994397

## #4 — P, 2007-06-19T16:29Z

Hur ser instansieringen av info ut nu då?

Permalänk: https://www.webforum.nu/p/1994419

## #5 — Vinnaren, 2007-06-19T16:41Z

så:

```
info = new arvBox()
```

 

o sen anropar den:

```
info.ShowInfo(graphArea)
```

 

denna anropas:

```
Public Class arvBox
    Inherits Box

    Public Sub ShowInfo(ByVal graphArea As Graphics)
        Dim sb As SolidBrush = New SolidBrush(Color.Red)
        Dim st As String = x & " " & y
        Dim f As Font = New Font("Arial", 12, FontStyle.Bold)
        graphArea.DrawString(st, f, sb, x, y)
    End Sub

End Class
```

Permalänk: https://www.webforum.nu/p/1994424

## #6 — emission, 2007-06-20T02:52Z

Dim info as new arvBox

Permalänk: https://www.webforum.nu/p/1994498

## #7 — Vinnaren, 2007-06-20T06:47Z

tack, får nu detta felmeddelande under körning:
Objektreferensen har inte angetts till en instans av ett objekt.

på raden

```
info.ShowInfo(graphArea)
```

 

  x(

Permalänk: https://www.webforum.nu/p/1994511

## #8 — Vinnaren, 2007-06-24T07:48Z

ingen som vet/kan  :q

Permalänk: https://www.webforum.nu/p/1995343

## #9 — emission, 2007-06-24T10:52Z

Du får nog visa mer komplett kod, för nu är det tillsnurrat.

Permalänk: https://www.webforum.nu/p/1995389

## #10 — P, 2007-06-24T11:29Z

> **Vinnaren skrev:**
>
> Men nu får jag felmeddelandet:
> 'ShowInfo' is not a member of 'System.Array'.

Det meddelandet känns skumt. Var kommer Array ifrån...

Permalänk: https://www.webforum.nu/p/1995398

## #11 — Vinnaren, 2007-06-24T13:21Z

Det löste sig. Hade glömt: info = New arvBox()

Permalänk: https://www.webforum.nu/p/1995424

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/161693-problem-att-starta-metoden
