Как проверить параметр из другой формы в Visual Basic? - PullRequest
0 голосов
/ 06 ноября 2019

У меня есть две формы, form1 и form2. Мне нужно вызвать параметр form1 из form2, чтобы проверить это в form2.

Это код в form1:

Public Sub New(ByVal parametro1 As Integer)

    InitializeComponent()
    TXB_MontoARetirar.Text = param1



End Sub

Public Sub New()

    InitializeComponent()
End Sub 

Это код в form2:

Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click

    Dim FRM As FRM_RetiroEfectivo2

    FRM = New FRM_RetiroEfectivo2()



    If FRM.TXB_MontoARetirar.Text = 100 Then

        FRM_RetireSuEfectivo1_100pesos.Show()
        Me.Hide()


    Else

        FRM_RetireSuEfectivo1.Show()
        Me.Hide()

    End If

End Sub

Когда я запускаю программу, я получаю следующую ошибку:

System.InvalidCastException: «Преобразование из строки» в тип «Double» недопустимо. '

Внутреннее исключениеFormatException: входная строка была в неправильном формате.

Ответы [ 4 ]

0 голосов
/ 07 ноября 2019

введите описание изображения здесь

См. Прикрепленное изображение

0 голосов
/ 06 ноября 2019

Все так же. Не позволяйте нажимать на PictureBox4. В форме FRM_RetireEfectivo2 у меня есть следующий код:

Public Sub New(ByVal parametro1 As String)

    InitializeComponent()
    TXB_MontoARetirar.Text = parametro1



End Sub

Public Sub New()

    InitializeComponent()
End Sub


Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click



End Sub

Private Sub BTN_Aceptar_Click(sender As Object, e As EventArgs) Handles BTN_Aceptar.Click


    Dim Cant_2 As Integer = 100
    Dim Cant_3 As Integer = 200
    Dim Cant_4 As Integer = 500
    Dim Cant_5 As Integer = 1000
    Dim Cant_6 As Integer = 2000
    Dim NumMultiplo2 As Integer
    Dim NumMultiplo3 As Integer
    Dim NumMultiplo4 As Integer
    Dim NumMultiplo5 As Integer
    Dim NumMultiplo6 As Integer

    If TXB_MontoARetirar.Text.Length = 0 Then

        MsgBox("Debe llenar el campo.")

    Else

        If TXB_MontoARetirar.Text = 0 Then

            MsgBox("Introduzca el monto a retirar.")

        Else

            If TXB_MontoARetirar.Text > 10000 Then

                MsgBox("Solo es posible retirar hasta RD$10000.00 en los cajeros.")

            Else

                If TXB_MontoARetirar.Text > 6000 Then

                    MsgBox("Fondos Insuficientes. Favor intentarlo otra vez.")


                Else


                    NumMultiplo2 = (TXB_MontoARetirar.Text Mod Cant_2)
                    NumMultiplo3 = (TXB_MontoARetirar.Text Mod Cant_3)
                    NumMultiplo4 = (TXB_MontoARetirar.Text Mod Cant_4)
                    NumMultiplo5 = (TXB_MontoARetirar.Text Mod Cant_5)
                    NumMultiplo6 = (TXB_MontoARetirar.Text Mod Cant_6)

                    If NumMultiplo2 = 0 Then

                        Dim Respuesta As Object
                        Respuesta = MsgBox("Desea imprimir un recibo?", MsgBoxStyle.YesNo, "Imprimir Recibo")
                        If Respuesta = vbYes Then


                            FRM_RetireSuTarjeta.Show()

                            TXB_MontoARetirar.Text = ""

                        Else

                            FRM_RetireSuTarjeta1.Show()
                            TXB_MontoARetirar.Text = ""
                            Me.Hide()
                        End If

                        TXB_MontoARetirar.Text = ""
                        Me.Hide()
                    Else

                        If NumMultiplo3 = 0 Then

                            Dim Respuesta As Object
                            Respuesta = MsgBox("Desea imprimir un recibo?", MsgBoxStyle.YesNo, "Imprimir Recibo")
                            If Respuesta = vbYes Then


                                FRM_RetireSuTarjeta.Show()

                                TXB_MontoARetirar.Text = ""

                            Else

                                FRM_RetireSuTarjeta1.Show()
                                TXB_MontoARetirar.Text = ""
                                Me.Hide()
                            End If

                            TXB_MontoARetirar.Text = ""
                            Me.Hide()
                        Else

                            If NumMultiplo4 = 0 Then

                                Dim Respuesta As Object
                                Respuesta = MsgBox("Desea imprimir un recibo?", MsgBoxStyle.YesNo, "Imprimir Recibo")
                                If Respuesta = vbYes Then


                                    FRM_RetireSuTarjeta.Show()

                                    TXB_MontoARetirar.Text = ""

                                Else

                                    FRM_RetireSuTarjeta1.Show()
                                    TXB_MontoARetirar.Text = ""
                                    Me.Hide()
                                End If

                                TXB_MontoARetirar.Text = ""
                                Me.Hide()
                            Else

                                If NumMultiplo5 = 0 Then

                                    Dim Respuesta As Object
                                    Respuesta = MsgBox("Desea imprimir un recibo?", MsgBoxStyle.YesNo, "Imprimir Recibo")
                                    If Respuesta = vbYes Then


                                        FRM_RetireSuTarjeta.Show()

                                        TXB_MontoARetirar.Text = ""


                                    Else

                                        FRM_RetireSuTarjeta1.Show()
                                        TXB_MontoARetirar.Text = ""
                                        Me.Hide()

                                    End If

                                    TXB_MontoARetirar.Text = ""
                                    Me.Hide()
                                Else

                                    If NumMultiplo6 = 0 Then

                                        Dim Respuesta As Object
                                        Respuesta = MsgBox("Desea imprimir un recibo?", MsgBoxStyle.YesNo, "Imprimir Recibo")
                                        If Respuesta = vbYes Then


                                            FRM_RetireSuTarjeta.Show()

                                            TXB_MontoARetirar.Text = ""


                                        Else

                                            FRM_RetireSuTarjeta1.Show()

                                            Me.Hide()
                                        End If

                                        TXB_MontoARetirar.Text = ""
                                        Me.Hide()
                                    Else

                                        MsgBox("Solo se pueden realizar retiros en multiplos de billetes de RD$100.00, RD$200.00, RD$500.00, RD$1000.00 y RD$2000.00 pesos.")

                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If



End Sub
0 голосов
/ 07 ноября 2019
Private Sub OPCode()
    If TXB_MontoARetirar.Text.Length = 0 Then
        MsgBox("Debe llenar el campo.")
        Return
    End If
    If TXB_MontoARetirar.Text = "0" Then
        MsgBox("Introduzca el monto a retirar.")
        Return
    End If
    Dim intMonto As Integer
    If Not Integer.TryParse(TXB_MontoARetrirar.Text, intMonto) Then
        MessageBox.Show("Please enter a number in the text box.")
        Return
    End If
    Select Case intMonto
        Case > 10000
            MsgBox("Solo es posible retirar hasta RD$10000.00 en los cajeros.")
            Return
        Case > 6000
            MsgBox("Fondos Insuficientes. Favor intentarlo otra vez.")
            Return
    End Select

    Dim NumMultiplo2 = intMonto Mod 100
    Dim NumMultiplo3 = intMonto Mod 200
    Dim NumMultiplo4 = intMonto Mod 500
    Dim NumMultiplo5 = intMonto Mod 1000
    Dim NumMultiplo6 = intMonto Mod 2000
    If NumMultiplo2 = 0 OrElse NumMultiplo3 = 0 OrElse NumMultiplo4 = 0 OrElse NumMultiplo5 = 0 OrElse NumMultiplo6 = 0 Then
        Dim Respuesta = MessageBox.Show("Desea imprimir un recibo?", "Imprimir Recibo", MessageBoxButtons.YesNo)
        If Respuesta = DialogResult.Yes Then
            FRM_RetireSuTarjeta.Show()
        Else
            FRM_RetireSuTarjeta1.Show()
        End If
        TXB_MontoARetirar.Text = ""
        Me.Hide()
    Else
        MsgBox("Solo se pueden realizar retiros en multiplos de billetes de RD$100.00, RD$200.00, RD$500.00, RD$1000.00 y RD$2000.00 pesos.")
    End If
End Sub

Я понятия не имею, что делает этот код, но, возможно, его упрощенный просмотр поможет вам понять, где он работает неправильно. Эти вложенные операторы If вышли из-под контроля. Когда вы пишете один и тот же код снова и снова, создайте Sub или Function. В этом случае я просто соединил все это с одним IF.

0 голосов
/ 06 ноября 2019

Попробуйте что-то вроде:

    If IsNumeric(FRM.TXB_MontoARetirar.Text) Then
         If CInt(FRM.TXB_MontoARetirar.Text) = 100 Then
            FRM_RetireSuEfectivo1_100pesos.Show()
            Me.Hide()
         End If
    Else
            FRM_RetireSuEfectivo1.Show()
            Me.Hide()         
    End If
...