Overwrite visual basic parameters

0

My program will have a series of parameters that are the following example:

Public Module Program

    Public h As String = "[host]"
    Public port As Integer = "[port]"
    Public meltf As String = "[M]"
    Public Name As String = "[vn]"
    Public Y As String = "/j|n\"

End Module

And I want from my other program to override these values:

Public Class Form1
    //Aqui es donde sobrescribire los valores de mi programa de arriba.
End Class

It will be a form where I will enter the values and I will overwrite them in my other program with the corresponding values. In principle I have no idea how to start solving it in principle would have to overwrite just that the parameters. Resolution example:

  

I have two programs. One where I enter the data, because that data   entered will modify the value of my other program by assigning each   field its value either each string example host="127.0.0.1".

If more details are missing, I'll try to correct it.

    
asked by Perl 27.12.2016 в 03:13
source

1 answer

0

What I understand with your explanation is that you want to implement a type Template

I can think of the following solution (I made a small sample code):

Link to download the source

Design the following form to make the example:

We are going through steps:

  • Design the Template , or the template that will be replaced by the values
  • Obtain the values. In this case, I generate them with the Generate Values button
  • Replace the template or template with the values
  • Create an entity or class to store each of the values:

      Public Class Datos
            Public Property Port() As Int32
            Public Property Host() As String
            Public Property Meltf() As String
            Public Property Name() As String
            Public Property Y() As String
        End Class
    

    Pressing the Generate Values button fills an instance of the entity Datos

    Create a class to replace the data:

    Public Class Reemplazar
    
    
    public Function  Reemplaza(ByVal template As String, ByVal valores As Datos  ) As String
        dim resultado as String = template
        resultado = resultado.Replace("[port]",valores.Port)
        resultado = resultado.Replace("[host]",valores.Host)
        resultado = resultado.Replace("[vn]",valores.Name)
        resultado = resultado.Replace("[M]",valores.Meltf)
        resultado = resultado.Replace("/j|n\",valores.Y)
    
        Return resultado
    End Function
    
    End Class
    

    With the function Reemplaza , it receives the template and the datos , and it replaces each data of the template that we define with the corresponding values, at the end it generates a string and it is what returns the function.

    Finally I assign the results to the last textbox to show them:

    Private Sub btnReemplazar_Click(sender As Object, e As EventArgs) Handles btnReemplazar.Click
            Try     
                me._txtSalida.Text = _r.Reemplaza(me._txtEntrada.Text,_d)
            Catch ex As Exception
                MessageBox.Show(ex.ToString())
            End Try
        End Sub
    
        
    answered by 27.12.2016 в 11:24