Visualizzazione dei risultati da 1 a 3 su 3

Visualizzazione discussione

  1. #1

    [VB.NET] Funzione che restituisce una lista

    Buongiorno, alla pressione di un button sul form1 vorrei che il programma andasse su un modulo dove con una function carico delle stringhe in una lista attraverso List of eccc e poi mi venga restituita da poterla usare nel form1.


    questo è l' errore anche in allegato:
    errore eccezione non gestita, riferimento ad un oggetto non impostato su una istanza di oggetto

    Ho provato ma non funziona.

    codice HTML:
    Module ModuloConfig
    
    
        Public Function MainConfig(ByVal ListaConfig As List(Of String))
    
            Dim Var As String
    
            Try
                Dim appSettings = ConfigurationManager.AppSettings
    
    
                If appSettings.Count = 0 Then
                    Console.WriteLine("AppSettings is empty.") ' è vuoto
                Else
    
                    For Each key As String In appSettings.AllKeys 'legge tutte le key
    
                        Var = (ConfigurationManager.AppSettings(key))
    
                        ListaConfig.Add(key & ":" & Var) ' errore eccezione non gestita, riferimento ad un oggetto non impostato su una istanza di oggetto
    
                    Next
                End If
            Catch e As ConfigurationErrorsException
                Console.WriteLine("Error reading app settings")
            End Try
            Return ListaConfig
        End Function
    questa la chiamata al button:

    codice HTML:
    Public Class Form1
        Public Lista As List(Of String)
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            MainConfig(lista)
        End Sub
    End Class
    questo il file config che leggo e carico nella list:
    codice HTML:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
      </startup>
    
      <appSettings>
        <add key="Setting1" value="Pippo1" />
        <add key="Setting2" value="Pippo2" />
      </appSettings>
    </configuration>
    Magari sbaglio perchè questa non è una funzione, nel tal caso mi potete aiutare a capire con che metodo riesco ad ottenere quello che vorrei accadesse?

    grazie
    Immagini allegate Immagini allegate

Tag per questa discussione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.