Bloqueado how to substract value if criteria mets?

  • domingo, 24 de junho de 2012 11:33
     
      Contém Código

    hello to all,

    can any one help me for this

    i have a five text boxes in visual basic 2010 form

    code to fill textbox1:

     Private Sub txtcatgen_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcatgen.TextChanged
            If txtcatgen.Text = "GENERALMALE" Then
                txtba1fees.Text = "510"
            End If
            If txtcatgen.Text = "GENERALFEMALE" Then
                txtba1fees.Text = "495"
            End If
            If txtcatgen.Text = "OBCMALE" Then
                txtba1fees.Text = "510"
            End If
            If txtcatgen.Text = "OBCFEMALE" Then
                txtba1fees.Text = "495"
            End If
            If txtcatgen.Text = "SCMALE" Then
                txtba1fees.Text = "0"
            End If
            If txtcatgen.Text = "SCFEMALE" Then
                txtba1fees.Text = "0"
            End If
            If txtcatgen.Text = "STMALE" Then
                txtba1fees.Text = "0"
            End If
            If txtcatgen.Text = "STFEMALE" Then
                txtba1fees.Text = "0"
            End If
        End Sub

    in the textbox2 change the code are:

    Private Sub txtba1fees_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtba1fees.TextChanged
    
            If txtcatgen.Text = "GENERALMALE" Then
                txtba1fees1.Text = txtba1fees.Text - "495"
            ElseIf txtcatgen.Text = "GENERALFEMALE" Then
                txtba1fees1.Text = txtba1fees.Text - "495"
            ElseIf txtcatgen.Text = "OBCMALE" Then
                txtba1fees1.Text = txtba1fees.Text - "495"
            ElseIf txtcatgen.Text = "OBCFEMALE" Then
                txtba1fees1.Text = txtba1fees.Text - "495"[Conversion from string "" to type 'Double' is not valid.]
            ElseIf txtcatgen.Text = "SCMALE" Then
                txtba1fees1.Text = "0"
            ElseIf txtcatgen.Text = "SCFEMALE" Then
                txtba1fees1.Text = "0"
            ElseIf txtcatgen.Text = "STMALE" Then
                txtba1fees1.Text = "0"
            ElseIf txtcatgen.Text = "STFEMALE" Then
                txtba1fees1.Text = "0"
            End If
        End Sub
    in the textbox3 change the code are:
    Private Sub txtba1fees1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtba1fees1.TextChanged
            If txtcatgen.Text = "GENERALMALE" Then
                txtba1fees2.Text = txtba1fees.Text - txtba1fees1.Text - "485"
            End If
            If txtcatgen.Text = "GENERALFEMALE" Then
                txtba1fees2.Text = txtba1fees.Text - "485"
            End If
            If txtcatgen.Text = "OBCMALE" Then
                txtba1fees2.Text = txtba1fees.Text - txtba1fees1.Text - "485"
            End If
            If txtcatgen.Text = "OBCFEMALE" Then
                txtba1fees2.Text = txtba1fees.Text - "485"
            End If
            If txtcatgen.Text = "SCMALE" Then
                txtba1fees2.Text = "0"
            End If
            If txtcatgen.Text = "SCFEMALE" Then
                txtba1fees2.Text = "0"
            End If
            If txtcatgen.Text = "STMALE" Then
                txtba1fees2.Text = "0"
            End If
            If txtcatgen.Text = "STFEMALE" Then
                txtba1fees2.Text = "0"
            End If
        End Sub

    in this code the error showing in mention line

    please help me it urgent

    if is there any other way for achieve this task.

    kindly help me.("_")

Todas as Respostas

  • segunda-feira, 25 de junho de 2012 09:15
    Moderador
     
     Respondido

    Hi Sunny,

    Welcome to the MSDN forum.

    I've tested your codes and got this exception if value of txtba1fees is nothing. For your issue, I suggest you validate its value before the calculate. 

    You can add the following codes in txtba1fees_TextChanged method:

            Dim result As Double
            If Double.TryParse(txtba1fees.Text, result) = False Then
                txtba1fees.Text = 0
            End If

    I hope this will be helpful.

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

    • Marcado como Resposta sanny007 segunda-feira, 25 de junho de 2012 17:06
    •  
  • segunda-feira, 25 de junho de 2012 17:08
     
     

    hello Zen,

    thanks for solving my problem.

    u are great.

    thanks again

    if u have time please solve this problem because i am trying this from last one week.

    how to generate unique ID based on combobox selection?

    thanks again



    • Editado sanny007 segunda-feira, 25 de junho de 2012 17:54
    • Editado sanny007 segunda-feira, 25 de junho de 2012 17:55
    • Editado sanny007 segunda-feira, 25 de junho de 2012 17:57
    •