Hi there my program is a simple adding calculation.
I have some products that when ticked ask for a input box that ask for the quanity of the type needed.
The user then selects the calculate button to calculate the price of the selections
My program works fine when every item is selected (via tick boxes)
but crashes with the error "Conversion from string "" to type 'Double' is not valid. " when a selection is not ticked here is my code
i have been told that my conversion procedure is outdated but this is what my lecturer has taught us and his marking requirments need to keep using this old method
thank you.Code:Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged 'declare variables Dim network As Double Dim network_num As Double Dim network_total As Double 'Make Text boxes Visable when ticked textbox_network_no.Visible = True TextBox_netcost.Visible = True TextBox_networksub.Visible = True 'Error trapping Try 'Inout box displayed to ask how much network cards are needed network = InputBox("How Many 100Mbit Network Cards Would You Like?") Catch ex As Exception 'simple message MsgBox("sorry could not accept the input") 'repeat error message network = InputBox("How Many 100Mbit Network Cards Would You Like?") End Try 'set network_num to 35 network_num = CDbl(35) 'display network num in textbox TextBox_netcost.Text = CDbl(network_num) 'display ammount ordered in textbox textbox_network_no.Text = CDbl(network) 'calculation for network_total network_total = network * network_num TextBox_networksub.Text = CDbl(network_total) End Sub Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged Dim hdd As Double Dim hdd_num As Double Dim hdd_total As Double 'Make Text boxes Visable when ticked textbox_hdd_no.Visible = True TextBox_hddcost.Visible = True TextBox_hddsub.Visible = True 'Error trapping Try 'Inout box displayed to ask how much network cards are needed hdd = InputBox("How Many Hard Drives Would You Like?") Catch ex As Exception 'simple message MsgBox("sorry could not accept the input") 'repeat error message hdd = InputBox("How Many Hard Drives Would You Like?") End Try 'set hdd_num to 120 hdd_num = CDbl(120) 'display hdd num in textbox TextBox_hddcost.Text = CDbl(hdd_num) 'display ammount ordered in textbox textbox_hdd_no.Text = CDbl(hdd) 'calculation for hdd_total hdd_total = hdd * hdd_num TextBox_hddsub.Text = CDbl(hdd_total) End Sub Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged Dim MOT As Double Dim MOT_num As Double Dim MOT_total As Double 'Make Text boxes Visable when ticked textbox_MOT_no.Visible = True TextBox_MOTcost.Visible = True TextBox_MOTsub.Visible = True 'Error trapping Try 'Inout box displayed to ask how much MOT are needed MOT = InputBox("How MOT Health check Would You Like?") Catch ex As Exception 'simple message MsgBox("sorry could not accept the input") 'repeat error message MOT = InputBox("How MOT Health check Would You Like?") End Try 'set MOT_num to 39 MOT_num = CDbl(39) 'display MOT num in textbox TextBox_MOTcost.Text = CDbl(MOT_num) 'display ammount ordered in textbox textbox_MOT_no.Text = CDbl(MOT) 'calculation for MOT_total MOT_total = MOT * MOT_num TextBox_MOTsub.Text = CDbl(MOT_total) End Sub Private Sub Btn_calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_calculate.Click Dim MOT_total As Double Dim hdd_total As Double Dim network_total As Double Dim total As Double MOT_total = CDbl(TextBox_MOTsub.Text) hdd_total = CDbl(TextBox_hddsub.Text) network_total = CDbl(TextBox_networksub.Text) total = MOT_total + hdd_total + network_total TextBox_total.Text = CDbl(total) End Sub End Class
Im new to VB so id imagine ther are 1000000 mistakes




Reply With Quote