Hey guys,

I have been working on this problem for a while and wanted to see if you could spot what the problem is. This form is used so I can add a customer to the list which calls up another form for the adding. And also has an option for deleting a customer off the list. Visual Studio is giving me an error for the procedure that refreshes the list. It is giving me an error when I try to add the break tab to separate the customers on the list. It is giving me an error about an Option Strict On not allowing implicit conversions from 'String' to 'Integer' What am I doing wrong? Here is what I have:

Imports Microsoft.VisualBasic

Public Class frmCustomerMaintenance
    Private customers As List(Of Customer)

    Private Sub frmCustomerMaintenance_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        customers = CustomerDB.GetCustomers
        For Each Customer As Customer In customers
            Customer.GetDisplayText()
            Me.FillCustomersListBox()
        Next
    End Sub

    Private Sub FillCustomersListBox()
        lstCustomers.Items.Clear()
        For Each c As Customer In customers
            lstCustomers.Items.Add(c.GetDisplayText(vbTab)) ' This is where I am getting the error
        Next
    End Sub


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim newCustomerForm As New frmAddCustomer
        newCustomerForm.ShowDialog()
        If newCustomerForm.Customer IsNot Nothing Then
            customers.Add(newCustomerForm.Customer)
            CustomerDB.SaveCustomers(customers)
            Me.FillCustomersListBox()
        End If
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim c As Integer = lstCustomers.SelectedIndex
        If c <> -1 Then
            Dim customer As Customer = customers(c)
            Dim message As String = "Are you sure you want to delete?"
            Dim button As DialogResult = MessageBox.Show(message, _
                "Confirm Delete", MessageBoxButtons.YesNo)
            If button = DialogResult.Yes Then
                customers.Remove(customer)
                CustomerDB.SaveCustomers(customers)
                Me.FillCustomersListBox()
            End If

        End If
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

Dani AI

Generated

Brief diagnosis and practical fixes (building on and ):

The compile error is a straight type-mismatch: the GetDisplayText overload you called expects a numeric parameter, but the code passed a tab constant (a String). With Option Strict turned on VB does not allow an implicit conversion from String to Integer, so the call fails at compile time. Confirm the exact method signature in your Customer class (F12 or Peek Definition in Visual Studio).

Two safe fixes

  • If the method should accept a separator character, change its parameter to a String and return the joined text. For example:
Public Function GetDisplayText(separator As String) As String
    Return String.Join(separator, New String() {Me.LastName, Me.FirstName, Me.Phone})
End Function
  • If the method really needs a numeric width (padding/column width), call it with an integer or convert the value explicitly; or keep the Integer parameter and use a padding-based implementation:
Public Function GetDisplayText(padWidth As Integer) As String
    Return Me.Name.PadRight(padWidth) & Me.Phone
End Function

UI note and recommendation

Relying on tab characters inside a ListBox to line up columns is fragile. For aligned columns use a ListView in Details mode or a DataGridView; both provide true columns, headers and sorting without hacks. See the Microsoft docs for Option Strict and the ListView control for background: Option Strict Statement (Visual Basic) and ListView Control (Windows Forms).

Quick troubleshooting tips

  • Use F12/Peek Definition or IntelliSense to see the GetDisplayText signature.
  • Don’t disable Option Strict to silence the error; adjust types or overloads instead.
  • If you want to keep tabs for visual spacing, prefer formatting in the data source or switch to a column-aware control.

Recommended Answers

All 2 Replies

Seem to be that it is expecting you to pass an integer value in the c.GetDisplayText function but instead you are passing a tab string. Of course im only taking a guess here since I dont know what your function parameters are...

Can you post the definition of the GetDisplayText function?

EDIT: Just realized the problem was solved. ^_^; Nevermind!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.