Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Definitionsproblem

Empfohlene Antworten

Veröffentlicht

Hy Leute,

habe ein kleines Problem. Habe eine Funktion, die in einem Listview die Spaltenbreiten automatisch einstellt und dabei bekomme ich folgende Fehlermeldung:

Fehler beim Kompilieren: Sub oder Function nicht definiert

Markieret ist hierbei das Wort "TextWidth"

Hier ist die komplette Funktion:

Function ResizeListView(ByRef liste As ListView)

Dim itm As Long, si As Integer

Dim itmText As String

Dim subitmText As String

Dim LstCnt As Long

Dim txWidth As Long

Dim subtxWidth As Long

LstCnt = liste.ListItems.Count

For itm = 1 To LstCnt

itmText = liste.ListItems(itm).Text

txWidth = TextWidth(itmText) + (6 * 15)

If txWidth > lastwidth Then

lastwidth = txWidth

liste.ColumnHeaders(1).Width = lastwidth

End If

Next itm

LstCnt = liste.ListItems.Count

For si = 1 To UBound(txtWidth)

For itm = 1 To LstCnt

subitmText = liste.ListItems(itm).SubItems(si)

subtxWidth = TextWidth(subitmText) + (12 * 15)

If subtxWidth > txtWidth(si) Then

txtWidth(si) = subtxWidth

liste.ColumnHeaders(si + 1).Width = txtWidth(si)

End If

Next itm

Next si

End Function

Irgendwie kapiert er das nicht.

In der MSN ist diese Funktion allerdings drin!

Bitte um Hilfe!

Chiacomo

Also, bei mir funktioniert es. Ich nehme an, du verwendest Version 6.0, oder? In der MSDN hab ich auch keine Hinweise gefunden. Schreib doch einfach mal ein kleines simples Proramm, welches testet, ob die Funktion wirklich nicht vorhanden ist.

  • Autor

Hy,

bei mir funktioniert es nur dann, wenn ich es als sub oder function direkt im formular-code stehen habe. wenn ich es aber in einem modul habe, funktioniert das nicht. und ich kann mir nicht erklären warum.

Chiacomo

Ganz einfach:

Wenn Du den Code in ein Modul auslagerst muss es heissen:


[...]

txWidth = Form1.ListView1.TextWidth(itmText) + (6 * 15)

[...]

subtxWidth = Form1.ListView1.TextWidth(subitmText) + (12 * 15)

Da das ListView für das Modul nicht per Default sichtbar ist. Wenn Du es in Eventfunktionen des ListView benutzt reicht einfach:

[...]

txWidth = TextWidth(itmText) + (6 * 15)

[...]

subtxWidth = TextWidth(subitmText) + (12 * 15)

Da das ListView in den Eventfunktionen per Default sichtbar ist. Wenn Du es im Formularquellcode benutzt, allerdings ausserhalb der Eventfunktionen des ListView muss es heissen:

[...]

txWidth = ListView1.TextWidth(itmText) + (6 * 15)

[...]

subtxWidth = ListView1.TextWidth(subitmText) + (12 * 15)

Da VB per default in der aktuellen Form nach einem Objekt ListView1 sucht.

Ich habe die Funktion zwar in ein Modul ausgelagert, habe aber der Funktion 'byref' das Listview übergeben.

Chiacomo

Sorry, die Parameterübergabe habe ich übersehen. Du musst dann aber trotzdem das Attribut TextWidth vollqualifiziert ansprechen.


[...]

txWidth = liste.TextWidth(itmText) + (6 * 15)

[...]

'oder

With liste

    subtxWidth = .TextWidth(subitmText) + (12 * 15)

End With

  • Autor

"textwidth" ist keine Methode des Listviews, sondern des Formulars. Ich habe jetzt das Formular und das Listview byref übergeben und jetzt funktionierts.

Wen Interessiert hier der komplette Code für das Modul:

' -----------------------------------------------------

Option Explicit

Dim txtWidth As Variant

Dim lastwidth As Long

Function ResizeListView(ByRef formular As Form, ByRef liste As ListView)

Dim itm As Long, si As Integer

Dim itmText As String

Dim subitmText As String

Dim LstCnt As Long

Dim txWidth As Long

Dim subtxWidth As Long

ReDim txtWidth(liste.ColumnHeaders.Count - 1)

LstCnt = liste.ListItems.Count

For itm = 1 To LstCnt

itmText = liste.ListItems(itm).Text

txWidth = formular.TextWidth(itmText) + (6 * 15) + 75

If txWidth > lastwidth Then

lastwidth = txWidth

liste.ColumnHeaders(1).Width = lastwidth

End If

Next itm

LstCnt = liste.ListItems.Count

For si = 1 To UBound(txtWidth)

For itm = 1 To LstCnt

subitmText = liste.ListItems(itm).SubItems(si)

subtxWidth = formular.TextWidth(subitmText) + (12 * 15) + 75

If subtxWidth > txtWidth(si) Then

txtWidth(si) = subtxWidth

liste.ColumnHeaders(si + 1).Width = txtWidth(si)

End If

Next itm

Next si

End Function

' -----------------------------------------------------

danke trotzdem

Chiacomo

:OD

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.