none
textbox and a Label Depending on the value of textbox I want the label to say something RRS feed

  • Question

  • Hi Good People

    On my Form I have A Text Box called (txtAvailableCredit) I have set this text box to read only. The Text value is put into Text box (txtAvailableCredit) Via the sum of other text boxes, 

    My Issue is when the value of (txtAvailableCredit) is changed and the Value is Greater > than £0.00 then I want a Label called(lbWarning) to say in credit.

    But if the value of (txtAvailableCredit) is changed and the value is less < than £0.00, Then I want a label called (lbWarning) to say Credit Limit Has been Exceeded. 

    But if the Value of (txtAvailableCredit) is changed to = £0.00 then I want Label (lbWarning) to hide..

    Below is some of the code that I have tried to no Avail...

    Private Sub txtAvailableCredit_TextChanged(sender As Object, e As EventArgs) Handles txtAvailableCredit.TextChanged
    
        If Val(txtAvailableCredit.Text) < Val("0.00") Then
            lbWarning.Text = "WARNING THE COMPANY:  " & txtCompanyName.Text & "  HAS EXCCEDED THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Red
        ElseIf Val(txtAvailableCredit.Text) > Val("0.00") Then
            lbWarning.Text = "THE COMPANY: " & txtCompanyName.Text & "  IS WITHIN THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Green
        ElseIf Val(txtAvailableCredit.Text) = Val("0.00") Then
            lbWarning.Hide()
        End If
    End Sub
    
    
    Private Sub txtAvailableCredit_TextChanged(sender As Object, e As EventArgs) Handles txtAvailableCredit.TextChanged
    
        Dim Value1 As Decimal = txtAvailableCredit.Text
    
        If Val(txtAvailableCredit.Text) < Value1 Then
            lbWarning.Text = "WARNING THE COMPANY:  " & txtCompanyName.Text & "  HAS EXCCEDED THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Red
        ElseIf Val(txtAvailableCredit.Text) > Value1 Then
            lbWarning.Text = "THE COMPANY: " & txtCompanyName.Text & "  IS WITHIN THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Green
        ElseIf Val(txtAvailableCredit.Text) = Value1 Then
            lbWarning.Hide()
    
        End If
    End Sub
    
    
    Private Sub txtAvailableCredit_TextChanged(sender As Object, e As EventArgs) Handles txtAvailableCredit.TextChanged
    
        Dim Value1 As Decimal = txtAvailableCredit.Text
    
        If Val(FormatCurrency(txtAvailableCredit.Text) < (FormatCurrency(Value1))) Then
            lbWarning.Text = "WARNING THE COMPANY:  " & txtCompanyName.Text & "  HAS EXCCEDED THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Red
        ElseIf Val(FormatCurrency(txtAvailableCredit.Text) > (FormatCurrency(Value1))) Then
            lbWarning.Text = "THE COMPANY: " & txtCompanyName.Text & "  IS WITHIN THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Green
        ElseIf Val(FormatCurrency(txtAvailableCredit.Text) = (FormatCurrency(Value1))) Then
            lbWarning.Hide()
    
        End If
    End Sub
    
    Private Sub txtAvailableCredit_TextChanged(sender As Object, e As EventArgs) Handles txtAvailableCredit.TextChanged
        If Val(txtAvailableCredit.Text) < Val("0.00") Then
            lbWarning.Text = "WARNING THE COMPANY:  " & txtCompanyName.Text & "  HAS EXCCEDED THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Red
        ElseIf Val(txtAvailableCredit.Text) > Val("0.00") Then
            lbWarning.Text = "THE COMPANY: " & txtCompanyName.Text & "  IS WITHIN THEIR CREDIT LIMIT "
            lbWarning.ForeColor = Color.Green
        ElseIf Val(txtAvailableCredit.Text) = Val("0.00") Then
            lbWarning.Hide()
    
        End If
    End Sub

    I hope you can help me please...

    Kind Regards

    Gary


    Gary Simpson


    • Edited by Gary Simpson Sunday, October 29, 2017 11:20 PM missed something out
    Sunday, October 29, 2017 11:17 PM

Answers

  •  You did not tell us what problem you are having or if you are getting an exception.  It would also help if you showed an example of how the numbers look in the textbox.  For example,  if you are using a character other than a number or decimal point,  that would cause the Val function to give you 0 (zero).

     The below seems to work for me.  However,  there are other methods to do it too.

        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            Dim CreditValue As Decimal = 0.0D
    
            Dim numstr As String = ""
            For Each c As Char In TextBox1.Text.ToCharArray
                If Char.IsDigit(c) OrElse c = "." OrElse c = "-" Then numstr &= c
            Next
    
            If Decimal.TryParse(numstr, CreditValue) Then
                If CreditValue > 0.0 Then
                    Label1.Text = "You have credit."
                    Label1.Visible = True
                ElseIf CreditValue < 0.0 Then
                    Label1.Text = "You have no credit you bum."
                    Label1.Visible = True
                Else
                    Label1.Visible = False
                End If
            Else
                Label1.Visible = False
            End If
        End Sub


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, October 29, 2017 11:46 PM
    • Marked as answer by Gary Simpson Monday, October 30, 2017 12:34 AM
    Sunday, October 29, 2017 11:42 PM
  • Hi

    I can't find a declaration for the variable CreditValue. For example, you would need a line just before the If Decimal.TryParse(numstr, CreditValue) to declare it such as

    Dim CreditValue as Decimal = 0D
    If Decimal.TryParse(numstr, CreditValue)Then


    Regards Les, Livingston, Scotland

    • Marked as answer by Gary Simpson Monday, October 30, 2017 10:03 PM
    Monday, October 30, 2017 9:43 PM
  • Hi

    Sounds like you are trying to use a string representation of a number in a calculation.

    If so, then you could use a function to convert the string to a number, such as:

            Dim s As String = "12.34"
            Dim value1 As Decimal = GetDecimal(s) * 2
    
            ' could be from TextBox1.text 
            Dim value2 As Decimal = GetDecimal(TextBox1.Text) * 2
    
            ' or any string value of a number .........
    
    
    '---------------------------------------------------
    
        Function GetDecimal(s As String) As Decimal
            Dim v As Decimal = 0D
            If Decimal.TryParse(s, v) Then Return v
    
            ' failed conversion so return zero
            Return 0D
        End Function
    
    


    Regards Les, Livingston, Scotland

    • Marked as answer by Gary Simpson Monday, October 30, 2017 1:03 AM
    Monday, October 30, 2017 12:28 AM

All replies

  • Hi

    Here is an example that might help

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim myTable As New DataTable("Freddy")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' some dummy data
            With myTable
                .Columns.Add("C1", GetType(Decimal))
                .Columns.Add("C2", GetType(Decimal))
                .Columns.Add("Total", GetType(Decimal))

                .Rows.Add(12.1D, 22.4D)
                .Rows.Add(11.9D, 12.6D)
                .Rows.Add(1.1D, -22D)
                .Rows.Add(1.9D, -12.8D)

                .Columns("Total").Expression = "C1 + c2"
            End With
            dgv.DataSource = myTable
            GetCredit()
        End Sub
        Private Sub dgv_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellEndEdit
            GetCredit()
        End Sub
        Sub GetCredit()
            Dim result As Decimal = CDec(myTable.Compute("sum(total)", Nothing))
            Label1.Text = result.ToString
            Select Case result
                Case < 0
                    Label2.Text = "EXCEDED CREDIT LIMIT"
                    Label2.ForeColor = Color.Red
                    Label2.Visible = True
                Case > 0
                    Label2.Text = "WITHIN THEIR CREDIT LIMIT"
                    Label2.ForeColor = Color.Green
                    Label2.Visible = True
                Case Else
                    Label2.Visible = False
            End Select
        End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, October 29, 2017 11:43 PM
    Sunday, October 29, 2017 11:40 PM
  •  You did not tell us what problem you are having or if you are getting an exception.  It would also help if you showed an example of how the numbers look in the textbox.  For example,  if you are using a character other than a number or decimal point,  that would cause the Val function to give you 0 (zero).

     The below seems to work for me.  However,  there are other methods to do it too.

        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            Dim CreditValue As Decimal = 0.0D
    
            Dim numstr As String = ""
            For Each c As Char In TextBox1.Text.ToCharArray
                If Char.IsDigit(c) OrElse c = "." OrElse c = "-" Then numstr &= c
            Next
    
            If Decimal.TryParse(numstr, CreditValue) Then
                If CreditValue > 0.0 Then
                    Label1.Text = "You have credit."
                    Label1.Visible = True
                ElseIf CreditValue < 0.0 Then
                    Label1.Text = "You have no credit you bum."
                    Label1.Visible = True
                Else
                    Label1.Visible = False
                End If
            Else
                Label1.Visible = False
            End If
        End Sub


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, October 29, 2017 11:46 PM
    • Marked as answer by Gary Simpson Monday, October 30, 2017 12:34 AM
    Sunday, October 29, 2017 11:42 PM
  •  You did not tell us what problem you are having or if you are getting an exception.  It would also help if you showed an example of how the numbers look in the textbox.  For example,  if you are using a character other than a number or decimal point,  that would throw an exception.

     The below seems to work for me.  However,  there are other methods to do it too.

        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            Dim CreditValue As Decimal = 0.0D
    
            Dim numstr As String = ""
            For Each c As Char In TextBox1.Text.ToCharArray
                If Char.IsDigit(c) OrElse c = "." OrElse c = "-" Then numstr &= c
            Next
    
            If Decimal.TryParse(numstr, CreditValue) Then
                If CreditValue > 0.0 Then
                    Label1.Text = "You have credit."
                    Label1.Visible = True
                ElseIf CreditValue < 0.0 Then
                    Label1.Text = "You have no credit you bum."
                    Label1.Visible = True
                Else
                    Label1.Visible = False
                End If
            Else
                Label1.Visible = False
            End If
        End Sub


    If you say it can`t be done then i`ll try it

    Hi IronRazrez

    Here Is A Picture of the text box in question called (txtAvailableCredit) I am not getting an exception My code doesn't work properly Basically it is all to do with the value in said text box, if the value is greater than £0.00 or Less than £0.00 or Equal to £0.00. that will governed the Label (lbWarning) text.

     


    Gary Simpson

    Sunday, October 29, 2017 11:55 PM
  • On my Form I have A Text Box called (txtAvailableCredit) I have set this text box to read only. The Text value is put into Text box (txtAvailableCredit) Via the sum of other text boxes,

    If the text box is read-only, how does the value get changed?   The code that changes the text box should also update the label.   If you do it like that you can test the actual credit amount as a number, rather than testing the text box text.  Testing a string for greater or less than 0 requires first converting the string to a number, but if you use the code that puts this that value into the text box, then you can test the number before you turn it into a string.

    Sunday, October 29, 2017 11:58 PM
  • Hi

    Here is an example that might help

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim myTable As New DataTable("Freddy")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' some dummy data
            With myTable
                .Columns.Add("C1", GetType(Decimal))
                .Columns.Add("C2", GetType(Decimal))
                .Columns.Add("Total", GetType(Decimal))

                .Rows.Add(12.1D, 22.4D)
                .Rows.Add(11.9D, 12.6D)
                .Rows.Add(1.1D, -22D)
                .Rows.Add(1.9D, -12.8D)

                .Columns("Total").Expression = "C1 + c2"
            End With
            dgv.DataSource = myTable
            GetCredit()
        End Sub
        Private Sub dgv_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellEndEdit
            GetCredit()
        End Sub
        Sub GetCredit()
            Dim result As Decimal = CDec(myTable.Compute("sum(total)", Nothing))
            Label1.Text = result.ToString
            Select Case result
                Case < 0
                    Label2.Text = "EXCEDED CREDIT LIMIT"
                    Label2.ForeColor = Color.Red
                    Label2.Visible = True
                Case > 0
                    Label2.Text = "WITHIN THEIR CREDIT LIMIT"
                    Label2.ForeColor = Color.Green
                    Label2.Visible = True
                Case Else
                    Label2.Visible = False
            End Select
        End Sub
    End Class


    Regards Les, Livingston, Scotland


    Hi Les 

    I have tried your code but with some modification But now I get an error Saying ( Value of type ' Char ' Cannot be converted to Decimal ...

    Regards 


    Gary Simpson

    Monday, October 30, 2017 12:14 AM
  • Hi

    Sounds like you are trying to use a string representation of a number in a calculation.

    If so, then you could use a function to convert the string to a number, such as:

            Dim s As String = "12.34"
            Dim value1 As Decimal = GetDecimal(s) * 2
    
            ' could be from TextBox1.text 
            Dim value2 As Decimal = GetDecimal(TextBox1.Text) * 2
    
            ' or any string value of a number .........
    
    
    '---------------------------------------------------
    
        Function GetDecimal(s As String) As Decimal
            Dim v As Decimal = 0D
            If Decimal.TryParse(s, v) Then Return v
    
            ' failed conversion so return zero
            Return 0D
        End Function
    
    


    Regards Les, Livingston, Scotland

    • Marked as answer by Gary Simpson Monday, October 30, 2017 1:03 AM
    Monday, October 30, 2017 12:28 AM
  • Hi Again IronRazerz

    I have tried your code with some Modification, I do get a warning saying "(Variable 'CreditValue' is passed by reference before it has been assigned a value, A Null reference exception could result in run time' )But I have set the said text box to a Value of £0.00 if the textbox is of null Value. here is your code but modified....

     Private Sub txtAvailableCredit_TextChanged(sender As Object, e As EventArgs) Handles txtAvailableCredit.TextChanged
    
            Dim numstr As String = ""
            For Each c As Char In txtAvailableCredit.Text.ToCharArray
                If Char.IsDigit(c) OrElse c = "." OrElse c = "-" Then numstr &= c
            Next
    
            If Decimal.TryParse(numstr, CreditValue) Then
                If CreditValue > 0.0 Then
                    lbWarning.Text = "You have credit."
                    lbWarning.Visible = True
                ElseIf CreditValue < 0.0 Then
                    lbWarning.Text = "You have no credit you bum."
                    lbWarning.Visible = True
                Else
                    lbWarning.Visible = False
                End If
            Else
                lbWarning.Visible = False
            End If
        End Sub

    Thank you IronRazerz 


    Gary Simpson


    • Edited by Gary Simpson Monday, October 30, 2017 12:36 AM to insert Picture
    Monday, October 30, 2017 12:34 AM
  • @ Gary

     We would need to see where you are declaring the variable in your code and what line of code is giving you that error/warning.

     


    If you say it can`t be done then i`ll try it

    Monday, October 30, 2017 1:44 AM
  • @ Gary

     We would need to see where you are declaring the variable in your code and what line of code is giving you that error/warning.

     


    If you say it can`t be done then i`ll try it

    Hi IronRazerz

    Here is a Picture of the Warning in my code ... Line 594

    Here is my code for the whole form so far...

    Public Class frmEditAccounts
    
        Private SQL As New SQLControl
    
        Dim temp1 As Decimal
        Dim temp2 As Decimal
        Dim temp3 As Decimal
        Private Sub frmEditAccounts_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'Start the Date and Time in Label (lbDateTime)
            Timer1.Start()
            'Activate Private Sub FetchAccount
            FetchAccount()
            'txtUpdatedBy = value of form1 EmployeeName
            txtUpdatedBy.Text = Form1.txtEmployeeName.Text
            'Disable Textboxes, combobox, DateTimePickers
            txtCompanyName.Enabled = False
            txtAddress.Enabled = False
            txtContactName.Enabled = False
            txtTelephoneNumber.Enabled = False
            txtMobileNumber.Enabled = False
            txtAccountNumber.Enabled = False
            txtAccountReference.Enabled = False
            txtCreditLimit.Enabled = False
            txtAvailableCredit.Enabled = False
            txtPaymentTerms.Enabled = False
            cbxPayTerms.Enabled = False
            txtPaymentMade.Enabled = False
            dtpDateStart.Enabled = False
            dtpDateStopped.Enabled = False
            txtWeekNumber.Enabled = False
            txtDriverName.Enabled = False
            txtVehicleUsed.Enabled = False
            txtNotes.Enabled = False
            cmdEditAccount.Enabled = False
    
            'Check Textbox values for Null Values If no Values the Insert Values 
            If txtInsertMoney.Text = "" Then
                txtInsertMoney.Text = FormatCurrency("0.00")
            Else
            End If
            If txtMoneyOwed.Text = "" Then
                txtMoneyOwed.Text = FormatCurrency("0.00")
            Else
            End If
            If txtPaymentMade.Text = "" Then
                txtPaymentMade.Text = FormatCurrency("0.00")
            Else
            End If
            If txtMoneyTotal.Text = "" Then
                txtMoneyTotal.Text = FormatCurrency("0.00")
            End If
            If txtCreditLimit.Text = "" Then
                txtCreditLimit.Text = FormatCurrency("0.00")
            Else
            End If
            If txtAvailableCredit.Text = "" Then
                txtAvailableCredit.Text = FormatCurrency("0.00")
            End If
            'Disable Buttons cmdUpdateMoney, cmdSaveMoney)
            cmdUpdateMoney.Enabled = False
            cmdSaveMoney.Enabled = False
        End Sub
        Private Sub FetchAccount()
            'Load the List box ( lbxAccounts ) from txtFilter .text
            lbxAccounts.Items.Clear()
    
            SQL.AddParam("@CompanyName", "%" & txtFilter.Text & "%")
            SQL.ExecQuery("SELECT CompanyName " & _
                          "FROM Accounts " & _
                          "WHERE CompanyName LIKE @CompanyName " & _
                          "ORDER BY CompanyName ASC; ")
            If SQL.HasException(True) Then Exit Sub
    
            For Each r As DataRow In SQL.SQLDT.Rows
                lbxAccounts.Items.Add(r("CompanyName"))
            Next
        End Sub
    
        Private Sub GetAccountDetails(CompanyName As String)
            'Private Sub to Fill Values into relevant Textboxes
            'When an Item is selected or Clicked in the List box
            SQL.AddParam("@CompanyName", CompanyName)
            SQL.ExecQuery("SELECT * " & _
                          "FROM Accounts " & _
                           "WHERE CompanyName=@CompanyName;")
    
            If SQL.RecordCount < 1 Then Exit Sub
    
            For Each r As DataRow In SQL.SQLDT.Rows
                txtAccountID.Text = r("AccountID").ToString
                txtCompanyName.Text = r("CompanyName").ToString
                txtAddress.Text = r("Address").ToString
                txtContactName.Text = r("ContactName").ToString
                txtTelephoneNumber.Text = r("TelephoneNumber").ToString
                txtMobileNumber.Text = r("MobileNumber").ToString
                txtAccountNumber.Text = r("AccountNumber").ToString
                txtAccountReference.Text = r("AccountReference").ToString
                txtCreditLimit.Text = r("CreditLimit").ToString
                txtAvailableCredit.Text = r("AvailableCredit").ToString
                txtMoneyOwed.Text = r("MoneyOwed").ToString
                txtPaymentTerms.Text = r("PaymentTerms").ToString
                txtPaymentMade.Text = r("PaymentMade").ToString
                txtMoneyTotal.Text = r("MoneyTotal").ToString
                txtDateAccountStarted.Text = r("DateAccountStarted").ToString
                txtdateAccountStopped.Text = r("dateAccountStopped").ToString
                txtWeekNumber.Text = r("WeekNumber").ToString
                txtUpdatedBy.Text = r("UpdatedBy").ToString
                txtDateUpdated.Text = r("DateUpdated").ToString
                txtDriverName.Text = r("DriverName").ToString
                txtVehicleUsed.Text = r("VehicleUsed").ToString
                txtNotes.Text = r("Notes").ToString
            Next
            'Change the Value of the Date in the txtDateAccountStarted And txtdateAccountStopped
            Dim myDate1 As Date = txtDateAccountStarted.Text
            txtDateAccountStarted.Text = myDate1.ToLongDateString
            Dim myDate2 As Date = txtdateAccountStopped.Text
            txtdateAccountStopped.Text = myDate2.ToLongDateString
    
            'Disable Textboxes, combobox, DateTimePickers
            txtCompanyName.Enabled = False
            txtAddress.Enabled = False
            txtContactName.Enabled = False
            txtTelephoneNumber.Enabled = False
            txtMobileNumber.Enabled = False
            txtAccountNumber.Enabled = False
            txtAccountReference.Enabled = False
            txtCreditLimit.Enabled = False
            txtInsertMoney.Enabled = False
            txtAvailableCredit.Enabled = False
            txtPaymentTerms.Enabled = False
            cbxPayTerms.Enabled = False
            txtPaymentMade.Enabled = False
            dtpDateStart.Enabled = False
            dtpDateStopped.Enabled = False
            txtWeekNumber.Enabled = False
            txtDriverName.Enabled = False
            txtVehicleUsed.Enabled = False
            txtNotes.Enabled = False
        End Sub
    
        Private Sub txtCompanyName_TextChanged(sender As Object, e As EventArgs) Handles txtCompanyName.TextChanged
            'if textbox (txtCompanyName text ) = Value CASH Then 
            'Disable textboxes, Combobox, DateTimePickers
            If txtCompanyName.Text = "CASH" Then
                txtCompanyName.Enabled = False
                txtAddress.Enabled = False
                txtContactName.Enabled = False
                txtTelephoneNumber.Enabled = False
                txtMobileNumber.Enabled = False
                txtAccountNumber.Enabled = False
                txtAccountReference.Enabled = False
                txtCreditLimit.Enabled = False
                txtAvailableCredit.Enabled = False
                txtPaymentTerms.Enabled = False
                cbxPayTerms.Enabled = False
                txtPaymentMade.Enabled = False
                dtpDateStart.Enabled = False
                dtpDateStopped.Enabled = False
                txtWeekNumber.Enabled = False
                txtDriverName.Enabled = False
                txtVehicleUsed.Enabled = False
                txtNotes.Enabled = False
            Else
                'if textbox (txtCompanyName text )  DOES NOT = Value CASH Then 
                'Enable textboxes, Combobox, DateTimePickers
                txtAddress.Enabled = True
                txtContactName.Enabled = True
                txtTelephoneNumber.Enabled = True
                txtMobileNumber.Enabled = True
                txtAccountReference.Enabled = True
                txtCreditLimit.Enabled = True
                txtAvailableCredit.Enabled = True
                txtPaymentTerms.Enabled = True
                cbxPayTerms.Enabled = True
                txtPaymentMade.Enabled = True
                dtpDateStopped.Enabled = True
                txtWeekNumber.Enabled = True
                txtDriverName.Enabled = True
                txtVehicleUsed.Enabled = True
                txtNotes.Enabled = True
            End If
        End Sub
    
        Private Sub txtFilter_KeyDown(sender As Object, e As KeyEventArgs) Handles txtFilter.KeyDown
            'if the Enter key on the keyboard is pressed  
            If e.KeyCode = Keys.Enter Then
                'look for Names in the Account Database and load into List box 
                FetchAccount()
                e.Handled = True
                'Suppress sound (Ding)
                e.SuppressKeyPress = True
            End If
        End Sub
    
        Private Sub lbxAccounts_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lbxAccounts.SelectedIndexChanged
            'Activate Private Sub (GetAccountDetails) when a Item is clicked in the ListBox ( lbxAccounts )
            GetAccountDetails(lbxAccounts.Text)
            Dim StartDate As Date = Date.FromOADate(Val(txtDateAccountStarted.Text))
            Dim FinishDate As Date = Date.FromOADate(Val(txtdateAccountStopped.Text))
            If FinishDate.ToOADate < StartDate.ToOADate = True Then
                txtdateAccountStopped.Text = ""
            End If
    
            'Disable and Enable Buttons
            cmdEditAccount.Enabled = True
            cmdSaveUpdate.Enabled = False
            cmdUpdateMoney.Enabled = True
            cmdSaveMoney.Enabled = False
            'Check if the Values of Labels (lbMoneyOwed, lbPayMade, lbTotalMoney) has a Value 
            'If No Value then Values of Labels (lbMoneyOwed, lbPayMade, lbTotalMoney) has a Value of £0.00
            If lbMoneyOwed.Text = "" Then
                lbMoneyOwed.Text = FormatCurrency("0.00").ToString
            Else
            End If
            If lbPayMade.Text = "" Then
                lbPayMade.Text = FormatCurrency("0.00").ToString
            Else
            End If
            If lbTotalMoney.Text = "" Then
                lbTotalMoney.Text = FormatCurrency("0.00").ToString
            Else
            End If
        End Sub
    
        Private Sub UpdateMoney()
            'Private Sub to Update and set's the values into Account SQL Database (Money Only)
            SQL.AddParam("@CreditLimit", txtCreditLimit.Text)
            SQL.AddParam("@MoneyOwed", txtMoneyOwed.Text)
            SQL.AddParam("@PaymentMade", txtPaymentMade.Text)
            SQL.AddParam("@MoneyTotal", txtMoneyTotal.Text)
            SQL.AddParam("@AvailableCredit", txtAvailableCredit.Text)
            SQL.AddParam("@AccountID", txtAccountID.Text)
    
            SQL.ExecQuery("UPDATE Accounts " & _
                           "SET CreditLimit=@CreditLimit, MoneyOwed=@MoneyOwed, PaymentMade=@PaymentMade, " & _
                           "MoneyTotal=@MoneyTotal, AvailableCredit=@AvailableCredit " & _
                           "WHERE AccountID=@AccountID;")
            If SQL.HasException(True) Then Exit Sub
    
            MsgBox("Account Name " & " ' " & txtCompanyName.Text & " ' " & " Money Has Been Updated Successfully!")
    
        End Sub
    
        Private Sub UpdateAccounts()
            'Private Sub that Updates and set the values into Account SQL Database
            SQL.AddParam("@CompanyName", txtCompanyName.Text)
            SQL.AddParam("@Address", txtAddress.Text)
            SQL.AddParam("@ContactName", txtContactName.Text)
            SQL.AddParam("@TelephoneNumber", txtTelephoneNumber.Text)
            SQL.AddParam("@MobileNumber", txtMobileNumber.Text)
            SQL.AddParam("@AccountNumber", txtAccountNumber.Text)
            SQL.AddParam("@AccountReference", txtAccountReference.Text)
            SQL.AddParam("@CreditLimit", txtCreditLimit.Text)
            SQL.AddParam("@AvailableCredit", txtAvailableCredit.Text)
            SQL.AddParam("@PaymentTerms", txtPaymentTerms.Text)
            SQL.AddParam("@PaymentMade", txtPaymentMade.Text)
            SQL.AddParam("@DateAccountStarted", txtDateAccountStarted.Text)
            SQL.AddParam("@DateAccountStopped", txtdateAccountStopped.Text)
            SQL.AddParam("@WeekNumber", txtWeekNumber.Text)
            SQL.AddParam("@UpdatedBy", txtUpdatedBy.Text)
            SQL.AddParam("@DateUpdated", txtDateUpdated.Text)
            SQL.AddParam("@DriverName", txtDriverName.Text)
            SQL.AddParam("@VehicleUsed", txtVehicleUsed.Text)
            SQL.AddParam("@Notes", txtNotes.Text)
            SQL.AddParam("@AccountID", txtAccountID.Text)
    
            SQL.ExecQuery("UPDATE Accounts " & _
                          "SET CompanyName=@CompanyName, Address=@Address, ContactName=@ContactName, " & _
                          "TelephoneNumber=@TelephoneNumber, MobileNumber=@MobileNumber, AccountNumber=@AccountNumber, " & _
                          "AccountReference=@AccountReference, CreditLimit=@CreditLimit, AvailableCredit=@AvailableCredit, " & _
                          "PaymentTerms=@PaymentTerms, PaymentMade=@PaymentMade, DateAccountStarted=@DateAccountStarted, " & _
                          "DateAccountStopped=@DateAccountStopped, WeekNumber=@WeekNumber, UpdatedBy=@UpdatedBy, " & _
                          "DateUpdated=@DateUpdated, DriverName=@DriverName, VehicleUsed=@VehicleUsed, Notes=@Notes " & _
                          "WHERE AccountID=@AccountID;")
    
            If SQL.HasException(True) Then Exit Sub
    
            MsgBox("Account Name " & " ' " & txtCompanyName.Text & " ' " & " Has Been Updated Successfully!")
    
        End Sub
    
        Private Sub txtMoneyTotal_Leave(sender As Object, e As EventArgs) Handles txtMoneyTotal.Leave
    
            Dim num1 As Decimal = txtCreditLimit.Text
            Dim num2 As Decimal = txtMoneyTotal.Text
    
            If txtMoneyTotal.Text = "" Then
                txtMoneyTotal.Text = FormatCurrency("0.00")
            End If
            If txtMoneyOwed.Text = "" Then
                txtMoneyOwed.Text = FormatCurrency("0.00")
            End If
    
            If txtAvailableCredit.Text = "" Then
                txtAvailableCredit.Text = FormatCurrency("0.00")
                'If Value of txtAvailableCredit is more than £0.00
            ElseIf txtAvailableCredit.Text > FormatCurrency("0.00") Then
                txtAvailableCredit.Text = FormatCurrency(num1 - num2)
                'txtAvailableCredit.Text = FormatCurrency(txtAvailableCredit.Text).ToString
            End If
    
    
    
    
        End Sub
    
        Private Sub cmdEditAccount_Click(sender As Object, e As EventArgs) Handles cmdEditAccount.Click
    
            'Disable Button (cmdEditAccount)
            cmdEditAccount.Enabled = False
            'Enable Button cmdSaveUpdate
            cmdSaveUpdate.Enabled = True
            'Enable Textboxes and DateTimePicker (dtpDateStopped) and ComboBox (cbxPayTerms)
            txtAddress.Enabled = True
            txtContactName.Enabled = True
            txtTelephoneNumber.Enabled = True
            txtMobileNumber.Enabled = True
            txtAccountReference.Enabled = True
            txtAvailableCredit.Enabled = True
            txtPaymentTerms.Enabled = True
            cbxPayTerms.Enabled = True
            txtPaymentMade.Enabled = True
            txtInsertMoney.Enabled = True
            dtpDateStopped.Enabled = True
            txtWeekNumber.Enabled = True
            txtDriverName.Enabled = True
            txtVehicleUsed.Enabled = True
            txtNotes.Enabled = True
        End Sub
    
        Private Sub cmdSaveUpdate_Click(sender As Object, e As EventArgs) Handles cmdSaveUpdate.Click
            'Activate Private Sub Called UpdateAccounts
            UpdateAccounts()
            'Insert Date and Time into txtDateUpdated
            txtDateUpdated.Text = DateTime.Now
            'Disable Buttons and Textboxes
            cmdSaveUpdate.Enabled = False
            cmdEditAccount.Enabled = True
            txtCompanyName.Enabled = False
            txtAddress.Enabled = False
            txtContactName.Enabled = False
            txtTelephoneNumber.Enabled = False
            txtMobileNumber.Enabled = False
            txtAccountNumber.Enabled = False
            txtAccountReference.Enabled = False
            txtAvailableCredit.Enabled = False
            txtPaymentTerms.Enabled = False
            cbxPayTerms.Enabled = False
            txtPaymentMade.Enabled = False
            dtpDateStart.Enabled = False
            dtpDateStopped.Enabled = False
            txtWeekNumber.Enabled = False
            txtDriverName.Enabled = False
            txtVehicleUsed.Enabled = False
            txtNotes.Enabled = False
        End Sub
    
        Private Sub txtPaymentMade_Enter(sender As Object, e As EventArgs) Handles txtPaymentMade.Enter
            'If no value is in txtInsertMoney, Then Put A value In txtInsertMoney of Currency = £0.00
            If txtInsertMoney.Text = "" Then
                txtInsertMoney.Text = FormatCurrency("0.00")
    
            End If
        End Sub
    
        Private Sub txtPaymentMade_Leave(sender As Object, e As EventArgs) Handles txtPaymentMade.Leave
            'if txtPaymentMade = Nothing then Make the Value of txtPaymentMade £0.00
            If txtPaymentMade.Text = "" Then
                txtPaymentMade.Text = (FormatCurrency("0.00"))
            ElseIf temp3.ToString = "" Then
                temp3 = FormatCurrency("0.00").ToString
                txtMoneyTotal.Text = "£0.00"
                'if txtMoneyPaidIn Has Value, Then that value is Formatted to currency
            Else
                txtPaymentMade.Text = FormatCurrency(txtPaymentMade.Text)
                txtMoneyTotal.Text = FormatCurrency(txtMoneyOwed.Text - txtPaymentMade.Text)
                'Disable txtMoneyPaidIn on Leave
                'txtMoneyPaidIn.Enabled = False
            End If
        End Sub
    
        Private Sub txtInsertMoney_Leave(sender As Object, e As EventArgs) Handles txtInsertMoney.Leave
            'txtMoneyOwed.text = Value of txtInsertMoney.text
            txtMoneyOwed.Text = Val(txtInsertMoney.Text)
            'Clear txtInsertMoney Change the Value of txtInsertMoney to Currency = £0.00 
            txtInsertMoney.Text = FormatCurrency("0.00")
            Dim Num1 As Double = CDec(Val(txtInsertMoney.Text))
            Dim Num2 As Decimal = CDec(temp3).ToString
            'txtMoneyOwed = Value txtInsertMoney Plus the Value of temp3 
            txtMoneyOwed.Text = txtInsertMoney.Text
            'Change All Values to currency 
            txtInsertMoney.Text = FormatCurrency(Val(txtInsertMoney.Text))
            txtMoneyOwed.Text = FormatCurrency(Val(txtMoneyOwed.Text))
            'txtMoneyOwed is the Value txtInsertMoney.Text Plus (+) Value of temp3
            txtMoneyOwed.Text = FormatCurrency(CDec(txtMoneyOwed.Text + Num2))
            txtInsertMoney.Text = FormatCurrency("0.00")
            'Disable txtInsertMoney
            txtInsertMoney.Enabled = False
    
        End Sub
        Private Sub cmdSaveUpdate_Enter(sender As Object, e As EventArgs) Handles cmdSaveUpdate.Enter
            'Set the Date and time in txtDateUpdated.Text with Date time Now
            txtDateUpdated.Text = DateTime.Now
        End Sub
    
        Private Sub cmdSaveUpdate_MouseHover(sender As Object, e As EventArgs) Handles cmdSaveUpdate.MouseHover
            'Also Sets the Date and time in txtDateUpdated.Text with Date time Now
            txtDateUpdated.Text = DateTime.Now
        End Sub
    
        Private Sub txtCreditLimit_Leave(sender As Object, e As EventArgs) Handles txtCreditLimit.Leave
            'if txtCreditLimit = Has no value the Put Value a into txtCreditLimit = £0.00 
            If txtCreditLimit.Text = "" Then
                txtCreditLimit.Text = FormatCurrency("0.00")
            Else
                'ElseIf txtAvailablCredit  = Has a Value then Format that value to Currency And Also Format txtCreditLimit to currency
                txtAvailableCredit.Text = FormatCurrency(txtCreditLimit.Text)
                txtCreditLimit.Text = FormatCurrency(txtCreditLimit.Text)
                'Disable  txtCreditLimit
                txtCreditLimit.Enabled = False
            End If
        End Sub
    
        Private Sub cbxPayTerms_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxPayTerms.SelectedIndexChanged
            ' txtPaymentTerms . text = value of ComboBox(cbxPayTerms.Text)
            txtPaymentTerms.Text = cbxPayTerms.Text
        End Sub
    
        Private Sub dtpDateStopped_CloseUp(sender As Object, e As EventArgs) Handles dtpDateStopped.CloseUp
            'On Close of the DateTimePicker(dtpDateStopped) txtdateAccountStopped = Value of DateTimePicker(dtpDateStopped)
            txtdateAccountStopped.Text = dtpDateStopped.Value.ToLongDateString
        End Sub
    
        Private Sub txtFilter_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtFilter.KeyPress
            'Activate Private Sub FetchAccount
            FetchAccount()
        End Sub
    
        Private Sub cmdUpdateMoney_Click(sender As Object, e As EventArgs) Handles cmdUpdateMoney.Click
            'when cmdUpdateMoney is clicked Label(labCaption1) Tells User to insert Money into txtInsertMoney textbox
            lbCaption1.Text = "Insert Money Owed By Company"
            'Disable And Hide Button cmdUpdateMoney
            cmdUpdateMoney.Enabled = False
            cmdUpdateMoney.Hide()
            'Enable and show button cmdSaveMoney
            cmdSaveMoney.Enabled = True
            cmdSaveMoney.Show()
            'temp1 = Value of txtMoneyOwed
            If txtMoneyOwed.Text = "" Then
                txtMoneyOwed.Text = FormatCurrency("0.00")
            End If
            temp1 = CDec(txtMoneyOwed.Text).ToString
            'Label2 = Value of temp1, Then formats the value to currency, Then add message   
            lbPayMade.Text = FormatCurrency(temp1) & "  Money Owed Last Visit"
            'temp2 = Value of txtMoneyPaidIn
            If txtPaymentMade.Text = "" Then
                txtPaymentMade.Text = FormatCurrency("0.00")
            End If
            temp2 = CDec(txtPaymentMade.Text).ToString
            'Label3 = Value of temp2, Then formats the value to currency, Then add message
            lbMoneyOwed.Text = FormatCurrency(temp2) & "  Money Paid in Last Visit"
            'temp3 = value txtMoneyTotal
            If txtMoneyTotal.Text = "" Then
                txtMoneyTotal.Text = FormatCurrency("0.00")
            End If
            temp3 = CDec(txtMoneyTotal.Text).ToString
            'Label4 = value of temp3, Then formats the value to currency, Then add message
            lbTotalMoney.Text = FormatCurrency(temp3) & "  Money Total Owed Last Visit"
            'Enable txtInsertMoney 
            txtInsertMoney.Enabled = True
            'txtInsertMoney Value is cleared
            txtInsertMoney.Clear()
            'txtMoneyOwed value is cleared , But temp1 still holds the previous Value of txtMoneyOwed
            txtMoneyOwed.Clear()
            'Enabled txtMoneyPaidIn
            txtPaymentMade.Enabled = True
            'txtMontxtPaymentMadeeyPaidIn Value is cleared, But temp2 still holds the previous Value of txtMoneyPaidIn 
            txtPaymentMade.Clear()
            'txtMoneyTotal value is cleared, But temp3 still holds the Previous Value of txtMoneyTotal
            txtMoneyTotal.Clear()
            'Use Private Function HighOrLow
            HighOrLow()
            'Disable Button (cmdUpdateMoney)
            cmdUpdateMoney.Enabled = False
            'Enable Button (cmdSaveMoney)
            cmdSaveMoney.Enabled = True
        End Sub
    
    
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            'A Label called (lbDateTime) shows  Day Date Time Now 
            Select Case Weekday(Now)
                Case Is = vbSaturday
                    lbDateTime.Text = "Today: " & " Saturday " + CStr(Today) & "  " & CStr(TimeOfDay)
                Case Is = vbSunday
                    lbDateTime.Text = "Today: " & " Sunday  " + CStr(Today) & "  " & CStr(TimeOfDay)
                Case Is = vbMonday
                    lbDateTime.Text = "Today: " & " Monday " + CStr(Today) & "  " & CStr(TimeOfDay)
                Case Is = vbTuesday
                    lbDateTime.Text = "Today: " & " Tuesday " + CStr(Today) & "  " & CStr(TimeOfDay)
                Case Is = vbWednesday
                    lbDateTime.Text = "Today: " & " Wednesday " + CStr(Today) & "  " & CStr(TimeOfDay)
                Case Is = vbThursday
                    lbDateTime.Text = "Today: " & " Thursday " + CStr(Today) & "  " & CStr(TimeOfDay)
                Case Is = vbFriday
                    lbDateTime.Text = "Today: " & " Friday " + CStr(Today) & "  " & CStr(TimeOfDay)
            End Select
        End Sub
    
        Private Sub cmdGoToBookings_Click(sender As Object, e As EventArgs) Handles cmdGoToBookings.Click
            'Shows Another Form called Bookings 
            frmBookings.Show()
        End Sub
    
        Private Sub cmdCloseAccountForm_Click(sender As Object, e As EventArgs) Handles cmdCloseAccountForm.Click
            'Closes the Form
            Me.Close()
        End Sub
    
        Private Sub txtMoneyTotal_Enter(sender As Object, e As EventArgs) Handles txtMoneyTotal.Enter
            Dim Num1 As Decimal = CDec((txtMoneyOwed.Text))
            Dim Num2 As Decimal = CDec((txtPaymentMade.Text))
            'The Office Owes the Driver Money IE.. If the value (txtMoneyTotal) is Above '>' £0.00 Then 
            'The BackColour of txtMoneyTotal is LightPink The Fore colour is black
            If Not Num1 - Num2 > CDec(FormatCurrency("0.00")) Then
                txtMoneyTotal.BackColor = Color.LightPink
                txtMoneyTotal.ForeColor = Color.Black
                lbCaption1.Text = "You Owe the Company " & txtCompanyName.Text & "  =  " & txtMoneyTotal.Text
            Else
                'If the Driver Owes the Office Money IE.. If the Value (txtMoneyTotal) is Below '<' £0.00 Then
                'txtMoneyTotal BackColour is Red And the Fore colour is White
                txtMoneyTotal.BackColor = Color.Red
                txtMoneyTotal.ForeColor = Color.White
                lbCaption1.Text = "The Company " & txtCompanyName.Text & " Owes You = " & txtMoneyTotal.Text
    
            End If
        End Sub
    
        Private Sub cmdSaveMoney_Click(sender As Object, e As EventArgs) Handles cmdSaveMoney.Click
            'This Button cmdSave Save's the data to the SQL Database 
            UpdateMoney()
            'Disable and Hide the Button cmdSave
            cmdSaveMoney.Enabled = False
            cmdSaveMoney.Hide()
            'Enable and Show Button called cmdUpdateMoney
            cmdUpdateMoney.Enabled = True
            cmdUpdateMoney.Show()
            'Disable textboxes txtInsertMoney and txtPaymentMade
            txtInsertMoney.Enabled = False
            txtPaymentMade.Enabled = False
    
        End Sub
    
        Private Sub cmdEditAccount_Enter(sender As Object, e As EventArgs) Handles cmdEditAccount.Enter
            'condition if the textbox (txtCompanyName.Text) = a value of (CASH) Then Disable
            ' Buttons cmdEditAccount and cmdUpdateMoney so User cannot edit the Account called CASH
            If txtCompanyName.Text = "CASH" Then
                cmdEditAccount.Enabled = False
                cmdUpdateMoney.Enabled = False
                'messagebox Tell User What or why they cannot edit Account name CASH
                MsgBox("SORRY " & txtUpdatedBy.Text & " YOU CANNOT UPDATE A CASH ACCOUNT ", MsgBoxStyle.Information, "THIS IS A CASH ACCOUNT")
            End If
        End Sub
    
        Private Sub cmdUpdateMoney_Enter(sender As Object, e As EventArgs) Handles cmdUpdateMoney.Enter
            'condition if the textbox (txtCompanyName.Text) = a value of (CASH) Then Disable
            ' Buttons cmdEditAccount and cmdUpdateMoney so User cannot edit the Account called CASH
            If txtCompanyName.Text = "CASH" Then
                cmdUpdateMoney.Enabled = False
                cmdEditAccount.Enabled = False
                'messagebox Tell User What or why they cannot edit Account name CASH
                MsgBox("SORRY " & txtUpdatedBy.Text & " YOU CANNOT UPDATE A CASH ACCOUNT ", MsgBoxStyle.Information, "THIS IS A CASH ACCOUNT")
            Else
                txtInsertMoney.Focus()
            End If
        End Sub
    
        Private Sub txtAvailableCredit_TextChanged(sender As Object, e As EventArgs) Handles txtAvailableCredit.TextChanged
            'Activate Private Function HighOrLow
            HighOrLow()
    
        End Sub
    
        Private Function HighOrLow()
            Dim numstr As String = ""
            For Each c As Char In txtAvailableCredit.Text.ToCharArray
                If Char.IsDigit(c) OrElse c = "." OrElse c = "-" Then numstr &= c
            Next
    
            If Decimal.TryParse(numstr, CreditValue) Then
                If CreditValue > 0.0 Then
                    txtAvailableCredit.BackColor = Color.LightGreen
                    txtAvailableCredit.ForeColor = Color.White
                    txtInsertMoney.Enabled = True
                    lbWarning1.Text = "This Company. ( " & txtCompanyName.Text & " ) Has Credit"
                    lbWarning2.Hide()
                    lbWarning1.Visible = True
                    lbWarning1.ForeColor = Color.Green
                ElseIf CreditValue < 0.0 Then
                    txtAvailableCredit.BackColor = Color.Pink
                    txtAvailableCredit.ForeColor = Color.White
                    txtInsertMoney.Enabled = False
                    lbWarning1.Text = "This Bum. ( " & txtCompanyName.Text & " ) Has No Credit Left"
                    lbWarning2.Show()
                    lbWarning2.Text = "!!! PAYMENT IS NEEDED !!! "
                    lbWarning1.ForeColor = Color.Red
                    lbWarning1.Visible = True
                ElseIf CreditValue = 0.0 AndAlso txtCreditLimit.Text = 0.0 Then
                    lbWarning2.Hide()
                    lbWarning1.Text = "This Person Or Company Pay's on the Day "
                    lbWarning1.ForeColor = Color.Blue
                End If
            Else
                lbWarning1.Visible = False
            End If
            Return 0
        End Function
    
    End Class

    I hope This is what you need...

    Kind Regards

    Gary


    Gary Simpson

    Monday, October 30, 2017 9:28 PM
  • Hi

    I can't find a declaration for the variable CreditValue. For example, you would need a line just before the If Decimal.TryParse(numstr, CreditValue) to declare it such as

    Dim CreditValue as Decimal = 0D
    If Decimal.TryParse(numstr, CreditValue)Then


    Regards Les, Livingston, Scotland

    • Marked as answer by Gary Simpson Monday, October 30, 2017 10:03 PM
    Monday, October 30, 2017 9:43 PM
  • Hi

    I can't find a declaration for the variable CreditValue. For example, you would need a line just before the If Decimal.TryParse(numstr, CreditValue) to declare it such as

    Dim CreditValue as Decimal = 0D
    If Decimal.TryParse(numstr, CreditValue)Then


    Regards Les, Livingston, Scotland

    Hi Les

    the issue has gone now

    Thank you Les


    Gary Simpson

    Monday, October 30, 2017 10:06 PM