3 Replies - 418 Views - Last Post: 17 October 2013 - 06:46 AM Rate Topic: -----

#1 nico123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-October 13

This code is not working

Posted 16 October 2013 - 06:05 AM

This code is not working. It does not seem to return anything. The variables dblCost and dblMarkup do not seem to contain any value after the user enters data. Could someone please help? Thank you.



Public Class Form1

    'Variable to hold the cost entered by the user
    Dim dblCost As Double
    'Variable to hold the markup entered by the user
    Dim dblMarkup As Double
    'Variable to hold the final retail cost entered by the user
    Dim dblRetailCost As Double

    Dim blnValidate As Boolean



    Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click


        'Validating Cost
        Call Validate_Cost(dblCost, blnValidate)

        'Validating Markup
        Call Validate_Markup(dblMarkup, blnValidate)



        'Calling function to calculate final retail cost
        dblRetailCost = CalcRetail(dblCost, dblMarkup)



        Call Display_Retail_Cost(dblRetailCost)

    End Sub




    'Validating Cost
    Private Sub Validate_Cost(ByVal Cost As Double, ByVal Validated As Boolean)

        If IsNumeric(txtCost.Text) Then
            Cost = Val(txtCost.Text)

        Else
            MessageBox.Show("Enter a number", "Enter Number", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Validated = False
            txtCost.Text = ""
            txtCost.Focus()
            Exit Sub

        End If


        If Cost < 0 Then
            MessageBox.Show("Number must be positive", "Enter Positive Number", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Validated = False
            txtCost.Text = ""
            txtCost.Focus()
            Exit Sub

        Else
            Cost = Val(txtCost.Text)

        End If



    End Sub

This post has been edited by AdamSpeight2008: 17 October 2013 - 09:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: This code is not working

#2 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 297
  • View blog
  • Posts: 1,525
  • Joined: 11-May 12

Re: This code is not working

Posted 16 October 2013 - 06:12 AM

If you want to change the original values in your sub, you would use ByRef instead of ByVal in your arguments.
Was This Post Helpful? 1
  • +
  • -

#3 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 795
  • View blog
  • Posts: 3,486
  • Joined: 03-December 12

Re: This code is not working

Posted 17 October 2013 - 05:57 AM

Either use what ybadragon has stated or use a function to return the value, such as after doing validation or math on a variable, as opposed to a procedure to change the value.
Was This Post Helpful? 1
  • +
  • -

#4 nico123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-October 13

Re: This code is not working

Posted 17 October 2013 - 06:46 AM

It is working now. Thanks a lot.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1