Use only one parameter

Asked

Viewed 89 times

1

Hello, it is possible to use only one parameter of a function?

My problem is I have a Function

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

In which parameter Posicao can be set in two ways. The user can manually select from DropDown or is selected automatically via a If

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

But an error is generated since in Page Load i set as default load the DropDown with the 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 don’t know how to make Posicao has value, continue this value and if no value is 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 Charging Stadiumanalysis:

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
  • Or rather: you want to indicate the initial position of your DropDownList, right?

  • Yes, but if it already contains a value, I want that value to be maintained and if not, to be equal to Dim item As New ListItem

1 answer

1


First of all, I would Posicao be 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

Secondly, 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

Should be inside CarregarListaDominioAnalise, not of Page_LoadX, because after all the list is assembled there, and there is no reason for this piece of code to be outside.

This line would have to check whether 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 doesn’t make much sense. I think you wanted to do something like this:

If Not Controle.SelectedIndex > 0 Then
    Posicao = Controle.SelectedValue
End If
  • 1

    I made all these changes and it worked on the first one. Thank you !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.