Use only one parameter

1

Hello, can you use only one parameter of a function ?

My problem is that I have a function

oUtils.CarregarListaDominioAnalise(Session("idioma"), lst_cdocorrencia, 30, True, "", "")

In which the Posicao parameter can be defined in two ways. The user can select manually in DropDown or is automatically selected by If

 If Not Controle.SelectedIndex < 0 Then
                Posicao = Controle.SelectedValue
            End If

But an error is generated since in Page Load I defaults to load DropDown with value 0 (SELECT)

  Dim item As New ListItem
                    item.Value = "0"
                    item.Text = "SELECIONE"
                    Me.lst_cdocorrencia.Items.Insert(0, item)
                    Me.lst_cdocorrencia.Items.FindByValue("0").Selected = True

I do not know how to make% w / o have value, continue this value, and if it does not have value it gets value = 0

Page_Load:

Private Sub Page_LoadX(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try

            Session("menu") = oUtils.MontarMenu(Session("idioma"), Session("usuario"), Session("caminho"), Session("nivelusuario"), "ocorrencias_veiculo")

            If Not Me.IsPostBack Then

                btnhelp.Attributes.Add("OnClick", "window.showModalDialog('../help.aspx?tela=OCORRENCIAS','Dialog','dialogWidth:650px;dialogHeight:400px;');return false;")

                CriarSessoesFu()

                Me.trconcessionario.Visible = False

                If Session("nivelusuario") >= 10 Then
                    Me.txtmotivo_analista.ReadOnly = True
                    Me.txtmotivo_analista.BackColor = Me.txtmotivo_analista.BackColor.Gainsboro
                    Me.txt_motivo.ReadOnly = False
                Else
                    Me.txt_motivo.ReadOnly = True
                    Me.txt_motivo.BackColor = Me.txt_motivo.BackColor.Gainsboro
                    Me.txtmotivo_analista.ReadOnly = False
                End If

                oUtils.CarregarRotulosTela(Session("idioma"), Controls, "ocorrencias_veiculo")


                If Session("nivelusuario") > 1 AndAlso Session("siglaconcessionario") <> "GA001" Then
                    oUtils.CarregarListaDominio(Session("idioma"), lst_cdocorrencia, 30, True, "", "C")
                Else
                    oUtils.CarregarListaDominio(Session("idioma"), lst_cdocorrencia, 30, True)
                End If

                If Not Me.Request.QueryString("id") Is Nothing AndAlso Me.Request.QueryString("id").ToString.Length > 0 Then
                    oUtils.CarregarListaDominioAnalise(Session("idioma"), lst_cdocorrencia, 30, True, "", "")
                    Call ObterOcorrencia(1, System.Convert.ToInt64(Me.Request.QueryString("id")))
                Else
                    Me.hdnIdOcorrencia.Text = "0"
                End If

                Dim item As New ListItem
                item.Value = "0"
                item.Text = "SELECIONE"
                Me.lst_cdocorrencia.Items.Insert(0, item)
                Me.lst_cdocorrencia.Items.FindByValue("0").Selected = True

                If Me.txt_dtocorrencia.Text.Length = 0 Then
                    Me.txt_dtocorrencia.Text = Now.ToString("dd/MM/yyyy")
                End If

            End If

            Me.txt_dtocorrencia.ReadOnly = True
            Me.txt_dtocorrencia.BackColor = Color.Gainsboro

            Session("chassi_corrente") = txt_chassi.Text

        Catch ex As Exception
            Response.Write("Page_Load - " & ex.Message)
            Response.End()
        End Try

    End Sub

Function LoadListDomainAnalysis:

Shared Function CarregarListaDominioAnalise(ByVal Idioma As Integer, ByRef Controle As ListControl, ByVal Dominio As Integer, ByVal Habilitado As Boolean, ByVal Posicao As String, ByVal flag1 As String, Optional ByVal apresentacodigo As Boolean = False) As Boolean

        Dim oData As DataSet
        Dim oBDD As New clsUtils
        Dim oCon As OracleClient.OracleConnection = oBDD.AbrirConexao()
        Dim sSql As String

        sSql = "select "
        sSql += "vl_dominio, "
        If apresentacodigo Then
            sSql += "vl_dominio||'-'||ds_dominio_idioma" & Idioma & " as ds_dominio_idioma "
        Else
            sSql += "ds_dominio_idioma" & Idioma & " as ds_dominio_idioma "
        End If
        sSql += "from Dominio "
        sSql += "where "
        sSql += "dt_exclusao is null and "
        sSql += "id_tipo_dominio = " & Convert.ToString(Dominio) & " "
        If Len(flag1) > 0 Then
            sSql += " and flag1 = '" & flag1 & "' "
        End If
        sSql += "order by nu_ordem"

        oData = oBDD.ListarRegistros(sSql, oCon)
        oBDD.FecharConexao(oCon)

        If Not Controle.SelectedIndex < 0 Then
            Posicao = Controle.SelectedValue
        End If

        Controle.Items.Clear()

        If oData.Tables(0).Rows.Count > 0 Then
            For lin As Integer = 0 To oData.Tables(0).Rows.Count - 1
                Controle.Items.Add(IIf(oData.Tables(0).Rows(lin).Item("ds_dominio_idioma").ToString.Length = 0, oData.Tables(0).Rows(lin).Item(1).ToString, oData.Tables(0).Rows(lin).Item("ds_dominio_idioma").ToString))
                Controle.Items(Controle.Items.Count - 1).Value = oData.Tables(0).Rows(lin).Item("vl_dominio").ToString
                If Posicao = oData.Tables(0).Rows(lin).Item("vl_dominio").ToString Then
                    Controle.Items(Controle.Items.Count - 1).Selected = True
                End If
            Next
        End If

        Controle.Enabled = Habilitado

        Return True

    End Function
    
asked by anonymous 11.06.2014 / 17:13

1 answer

1

First, I'd make Posicao a default parameter:

Shared Function CarregarListaDominioAnalise(ByVal Idioma As Integer, ByRef Controle As ListControl, ByVal Dominio As Integer, ByVal Habilitado As Boolean, ByVal flag1 As String, Optional ByVal Posicao As String = "", Optional ByVal apresentacodigo As Boolean = False) As Boolean

Second, this code here:

    Dim item As New ListItem
            item.Value = "0"
            item.Text = "SELECIONE"
            Me.lst_cdocorrencia.Items.Insert(0, item)
            Me.lst_cdocorrencia.Items.FindByValue("0").Selected = True

It should be within CarregarListaDominioAnalise , not Page_LoadX , because after all the list is mounted there, and there is no reason for this snippet of code to be outside.

This line would have to check if Posicao is different from "" :

If Posicao <> "" And Posicao = oData.Tables(0).Rows(lin).Item("vl_dominio").ToString Then
    Controle.Items(Controle.Items.Count - 1).Selected = True
End If

The line below the way it is in the question does not make much sense. I think you wanted to do something like this:

If Not Controle.SelectedIndex > 0 Then
    Posicao = Controle.SelectedValue
End If
    
11.06.2014 / 18:41