Public Class Form1 Function Calculate() As Double Dim material As Double If Rad_lead.Checked Then material = 0.85 Else material = 0 End If Return material End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Declare variables Dim distravelled As Double Dim occupanfact As Double Dim usefact As Double Dim weeklyunshielded As Double Dim numpatients As Double Dim primaryker As Double Dim transmissionfactor As Double Dim designgoal As Double Dim leadthickness As Double Dim alpha, beta, gamma As Double ' Dim alphabeta, xbarrier, NTK As Double ' Validate textboxes If Not IsNumeric(Txt_numberofpatients.Text) Then MsgBox("Please Enter Number only for patient", MsgBoxStyle.Critical) Txt_numberofpatients.Focus() Exit Sub Else numpatients = Convert.ToDouble(Txt_numberofpatients.Text) End If If Not IsNumeric(Txtbox_distance.Text) Then MsgBox("Please Enter Number for distance", MsgBoxStyle.Critical) Txtbox_distance.Focus() Exit Sub Else distravelled = Convert.ToDouble(Txtbox_distance.Text) End If If Not IsNumeric(Txtbox_unshieldedairkerma.Text) Then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) Txtbox_unshieldedairkerma.Focus() Exit Sub Else primaryker = Convert.ToDouble(Txtbox_unshieldedairkerma.Text) End If If Not IsNumeric(Txtbox_designgoal.Text) Then MsgBox("Please Enter Number for design goal", MsgBoxStyle.Critical) Txtbox_usefactor.Focus() Exit Sub Else designgoal = Convert.ToDouble(Txtbox_designgoal.Text) End If If Not IsNumeric(Txtbox_occupancyfactor.Text) Then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) Txtbox_occupancyfactor.Focus() Exit Sub Else occupanfact = Convert.ToDouble(Txtbox_occupancyfactor.Text) End If If Not IsNumeric(Txtbox_usefactor.Text) Then MsgBox("Please Enter Number for usefactor", MsgBoxStyle.Critical) Txtbox_usefactor.Focus() Exit Sub Else End If usefact = Convert.ToDouble(Txtbox_usefactor.Text) If Not IsNumeric(txtalpha.Text) Then MsgBox("Please select a value in combobox", MsgBoxStyle.Critical) txtalpha.Focus() Exit Sub Else alpha = Convert.ToDouble(txtalpha.Text) End If If Not IsNumeric(txtbeta.Text) Then MsgBox("Please select a value in combobox", MsgBoxStyle.Critical) txtbeta.Focus() Exit Sub Else beta = Convert.ToDouble(txtbeta.Text) End If If Not IsNumeric(txtgamma.Text) Then MsgBox("Please select a value in combobox", MsgBoxStyle.Critical) txtgamma.Focus() Exit Sub Else gamma = Convert.ToDouble(txtgamma.Text) End If 'Calculate the weekly unshielded primary air kerma ' weeklyunshielded = primaryker * distravelled * numpatients weeklyunshielded = ((primaryker * usefact * numpatients) / (distravelled ^ 2)) Txt_weeklyunshielded.Text = weeklyunshielded Txt_weeklyunshielded.Text = weeklyunshielded.ToString("#.000") 'Calculate the transmission factor required for the primary barriers transmissionfactor = ((designgoal / occupanfact) / weeklyunshielded) Txt_transmissionfactor.Text = transmissionfactor Txt_transmissionfactor.Text = transmissionfactor.ToString("#.0E+0") 'Calculate the thickness of the lead needed to shield the dedicated chest unit Dim alphagamma, xbarrier, NTK, betaalpha As Double alphagamma = 1 / (alpha * gamma) NTK = ((numpatients * occupanfact * primaryker) / (designgoal * distravelled ^ 2)) ^ gamma betaalpha = beta / alpha xbarrier = (NTK + betaalpha) / (1 + betaalpha) Dim calc As Double leadthickness = (alphagamma) * Math.Log(xbarrier) calc = Calculate() leadthickness = leadthickness - calc Txt_leadthickness.Text = leadthickness.ToString("#.00")
9 Replies - 1143 Views - Last Post: 13 March 2013 - 04:08 AM
#1
wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 03:34 PM
Replies To: wrong product in a textbox when I calculate function is called
#2
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 04:26 PM
Hello koppong,
I see a few errors that should be fixed before continuing. Make these 2 lines the VERY 1st 2 lines of code in your program above the (Public Class Form1) line.
This will catch some errors and place a little blue line with a red spot on the end of the blue line. You can then put your mouse over the little red spot and it will pop up a red box that you can click on. Then it will show you how to fix the errors. It is a very very handy thing to use.
I don`t understand what problem you are having but, if the above tip does not help then let us know what the error is or what part is not working correct.
I would also recommend checking out this LINK on debuging your code by andrewsw.
/>
I see a few errors that should be fixed before continuing. Make these 2 lines the VERY 1st 2 lines of code in your program above the (Public Class Form1) line.
Option Explicit On Option Strict On
This will catch some errors and place a little blue line with a red spot on the end of the blue line. You can then put your mouse over the little red spot and it will pop up a red box that you can click on. Then it will show you how to fix the errors. It is a very very handy thing to use.
I don`t understand what problem you are having but, if the above tip does not help then let us know what the error is or what part is not working correct.
I would also recommend checking out this LINK on debuging your code by andrewsw.

This post has been edited by IronRazer: 12 March 2013 - 04:27 PM
#3
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 04:51 PM
Here's a little tip that may make your life easier in the future
Where you have things like:
This can be reduced to
Plus isNumeric can get a little flaky at times. Rare but when it happens.
Upon successful parse, it will return True and store the value into your variable you declared as double, which is also supplied to the tryparse.
As far as your immediate issue, I have to agree, it's time to step through the code and check the values the variables hold.
Work it out on paper and see that the inputs are giving the same results at each step of the operation.
Where you have things like:
If Not IsNumeric(Txtbox_occupancyfactor.Text) Then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) Txtbox_occupancyfactor.Focus() Exit Sub Else occupanfact = Convert.ToDouble(Txtbox_occupancyfactor.Text) End If
This can be reduced to
If Not Double.TryParse(TxtBox_occupancyFactore.Text, occupanfact) then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) txtbox_occupancyfactor.Focus() exit sub End if
Plus isNumeric can get a little flaky at times. Rare but when it happens.
Upon successful parse, it will return True and store the value into your variable you declared as double, which is also supplied to the tryparse.
As far as your immediate issue, I have to agree, it's time to step through the code and check the values the variables hold.
Work it out on paper and see that the inputs are giving the same results at each step of the operation.
#4
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 06:34 PM
CharlieMay, on 12 March 2013 - 04:51 PM, said:
Here's a little tip that may make your life easier in the future
Where you have things like:
This can be reduced to
Plus isNumeric can get a little flaky at times. Rare but when it happens.
Upon successful parse, it will return True and store the value into your variable you declared as double, which is also supplied to the tryparse.
As far as your immediate issue, I have to agree, it's time to step through the code and check the values the variables hold.
Work it out on paper and see that the inputs are giving the same results at each step of the operation.
Where you have things like:
If Not IsNumeric(Txtbox_occupancyfactor.Text) Then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) Txtbox_occupancyfactor.Focus() Exit Sub Else occupanfact = Convert.ToDouble(Txtbox_occupancyfactor.Text) End If
This can be reduced to
If Not Double.TryParse(TxtBox_occupancyFactore.Text, occupanfact) then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) txtbox_occupancyfactor.Focus() exit sub End if
Plus isNumeric can get a little flaky at times. Rare but when it happens.
Upon successful parse, it will return True and store the value into your variable you declared as double, which is also supplied to the tryparse.
As far as your immediate issue, I have to agree, it's time to step through the code and check the values the variables hold.
Work it out on paper and see that the inputs are giving the same results at each step of the operation.
Thank you very! I always learn new things here.
IronRazer, on 12 March 2013 - 04:26 PM, said:
Hello koppong,
I see a few errors that should be fixed before continuing. Make these 2 lines the VERY 1st 2 lines of code in your program above the (Public Class Form1) line.
This will catch some errors and place a little blue line with a red spot on the end of the blue line. You can then put your mouse over the little red spot and it will pop up a red box that you can click on. Then it will show you how to fix the errors. It is a very very handy thing to use.
I don`t understand what problem you are having but, if the above tip does not help then let us know what the error is or what part is not working correct.
I would also recommend checking out this LINK on debuging your code by andrewsw.
/>/>
I see a few errors that should be fixed before continuing. Make these 2 lines the VERY 1st 2 lines of code in your program above the (Public Class Form1) line.
Option Explicit On Option Strict On
This will catch some errors and place a little blue line with a red spot on the end of the blue line. You can then put your mouse over the little red spot and it will pop up a red box that you can click on. Then it will show you how to fix the errors. It is a very very handy thing to use.
I don`t understand what problem you are having but, if the above tip does not help then let us know what the error is or what part is not working correct.
I would also recommend checking out this LINK on debuging your code by andrewsw.

#5
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 06:45 PM
Thank you IronRazor.... It has been very helpful and I have been able to correct some bugs already. The problem I'm having now is the calculation part. On paper my answer for lead thickness required is 1.35 but when I run the program I get 1.31.
The idea is to subtract material=0.85 which is a variable in the Calculate Function from the leadthickness value.
I made the calculate Function public so that other subroutines can access it. I would appreciate if you could take a look at it to see if you could find the error.
The idea is to subtract material=0.85 which is a variable in the Calculate Function from the leadthickness value.
I made the calculate Function public so that other subroutines can access it. I would appreciate if you could take a look at it to see if you could find the error.
#6
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 07:19 PM
koppong,
could you list the values per Input that you are using and possibly the "paper" formula you used to come up with your result?
I think that would be helpful in determining where an error might be occurring.
could you list the values per Input that you are using and possibly the "paper" formula you used to come up with your result?
I think that would be helpful in determining where an error might be occurring.
#7
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 07:28 PM
Hello CharlieMay, I have posted the entire code so that you can follow.
Option Explicit On Option Strict On Public Class Form1 Function Calculate() As Double Dim material As Double If Rad_lead.Checked Then material = 0.85 Else material = 0 End If Return material End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Declare variables Dim distravelled As Double Dim occupanfact As Double Dim usefact As Double Dim weeklyunshielded As Double Dim numpatients As Double Dim primaryker As Double Dim transmissionfactor As Double Dim designgoal As Double Dim leadthickness As Double Dim alpha, beta, gamma As Double ' Dim alphabeta, xbarrier, NTK As Double ' Validate textboxes If Not IsNumeric(Txt_numberofpatients.Text) Then MsgBox("Please Enter Number only for patient", MsgBoxStyle.Critical) Txt_numberofpatients.Focus() Exit Sub Else numpatients = Convert.ToDouble(Txt_numberofpatients.Text) End If If Not IsNumeric(Txtbox_distance.Text) Then MsgBox("Please Enter Number for distance", MsgBoxStyle.Critical) Txtbox_distance.Focus() Exit Sub Else distravelled = Convert.ToDouble(Txtbox_distance.Text) End If If Not IsNumeric(Txtbox_unshieldedairkerma.Text) Then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) Txtbox_unshieldedairkerma.Focus() Exit Sub Else primaryker = Convert.ToDouble(Txtbox_unshieldedairkerma.Text) End If If Not IsNumeric(Txtbox_designgoal.Text) Then MsgBox("Please Enter Number for design goal", MsgBoxStyle.Critical) Txtbox_usefactor.Focus() Exit Sub Else designgoal = Convert.ToDouble(Txtbox_designgoal.Text) End If If Not Double.TryParse(Txtbox_occupancyfactor.Text, occupanfact) Then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) Txtbox_occupancyfactor.Focus() Exit Sub End If If Not Double.TryParse(Txtbox_usefactor.Text, usefact) Then MsgBox("Please Enter Number for airkerma", MsgBoxStyle.Critical) Txtbox_usefactor.Focus() Exit Sub Else End If usefact = Convert.ToDouble(Txtbox_usefactor.Text) If Not IsNumeric(txtalpha.Text) Then MsgBox("Please select a value in combobox", MsgBoxStyle.Critical) txtalpha.Focus() Exit Sub Else alpha = Convert.ToDouble(txtalpha.Text) End If If Not IsNumeric(txtbeta.Text) Then MsgBox("Please select a value in combobox", MsgBoxStyle.Critical) txtbeta.Focus() Exit Sub Else beta = Convert.ToDouble(txtbeta.Text) End If If Not IsNumeric(txtgamma.Text) Then MsgBox("Please select a value in combobox", MsgBoxStyle.Critical) txtgamma.Focus() Exit Sub Else gamma = Convert.ToDouble(txtgamma.Text) End If 'Calculate the weekly unshielded primary air kerma ' weeklyunshielded = primaryker * distravelled * numpatients weeklyunshielded = ((primaryker * usefact * numpatients) / (distravelled ^ 2)) Txt_weeklyunshielded.Text = CStr(weeklyunshielded) Txt_weeklyunshielded.Text = weeklyunshielded.ToString("#.000") 'Calculate the transmission factor required for the primary barriers transmissionfactor = ((designgoal / occupanfact) / weeklyunshielded) Txt_transmissionfactor.Text = CStr(transmissionfactor) Txt_transmissionfactor.Text = transmissionfactor.ToString("#.0E+0") 'Calculate the thickness of the lead needed to shield the dedicated chest unit Dim alphagamma, xbarrier, NTK, betaalpha As Double alphagamma = 1 / (alpha * gamma) NTK = ((numpatients * occupanfact * primaryker) / (designgoal * distravelled ^ 2)) ^ gamma betaalpha = beta / alpha xbarrier = (NTK + betaalpha) / (1 + betaalpha) Dim calc As Double leadthickness = (alphagamma) * Math.Log(xbarrier) calc = Calculate() leadthickness = leadthickness - calc Txt_leadthickness.Text = leadthickness.ToString("#.00") ' Workload(Distribution) ' Wnorm (mA min/patient) 'Primary field size F( in cm^2) 'Primary Distance dF(m) 'Leakage() 'Side(Scatter) 'Leakage and Side Scatter 'Forward/Backscatter 'Leakage and Forward/Backscatter End Sub Private Sub Comb_unshieldedairkerma_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_unshieldedairkerma.SelectedIndexChanged Dim chest_bucky As Single = 2.3 Dim floor As Single = 5.2 Dim radtube As Single = 5.9 Dim chestroom As Single = 1.2 If Comb_unshieldedairkerma.SelectedItem Is "Rad Room (chest bucky)" Then Txtbox_unshieldedairkerma.Text = chest_bucky.ToString() ElseIf Comb_unshieldedairkerma.SelectedItem Is "Rad Room (floor or other)" Then Txtbox_unshieldedairkerma.Text = floor.ToString() ElseIf Comb_unshieldedairkerma.SelectedItem Is "Rad Tube (R & F Room)" Then Txtbox_unshieldedairkerma.Text = radtube.ToString() ElseIf Comb_unshieldedairkerma.SelectedItem Is "Chest Room" Then Txtbox_unshieldedairkerma.Text = chestroom.ToString() End If End Sub Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Values for usefactor Dim radfloor As Double = 0.89 Dim crosstable As Double = 0.09 Dim wallno3 As Double = 0.02 Dim chestimagereceptor = 1.0 Select Case Combo_usefactor.Text Case "Floor" With Txtbox_usefactor .Text = radfloor.ToString() End With Case "Cross-table wall" With Txtbox_usefactor .Text = crosstable.ToString End With Case "Wall No.3c" With Txtbox_usefactor .Text = wallno3.ToString() End With Case "Chest image receptor" With Txtbox_usefactor .Text = chestimagereceptor.ToString() End With End Select End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rad_control.CheckedChanged Dim controlled_area As Double = 0.1 'Dim uncontrolled_area As Double = 0.02 If Rad_control.Checked = True Then Txtbox_designgoal.Text = controlled_area.ToString() 'ElseIf Rad_uncontrolled.Checked = True Then 'Txtbox_designgoal.Text = uncontrolled_area.ToString() Exit Sub End If End Sub Private Sub Rad_uncontrolled_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rad_uncontrolled.CheckedChanged 'Dim controlled_area As Double = 0.1 Dim uncontrolled_area As Double = 0.02 'If Rad_control.Checked = True Then 'Txtbox_designgoal.Text = controlled_area.ToString() If Rad_uncontrolled.Checked = True Then Txtbox_designgoal.Text = uncontrolled_area.ToString() Exit Sub End If End Sub Private Sub Cmb_occupancyfactor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmb_occupancyfactor.SelectedIndexChanged Dim Administrative As Double = 1.0 Dim Clerical As Double = 1.0 Dim Laboratories As Double = 1.0 Dim Pharmacies As Double = 1.0 Dim Receptionist As Double = 1.0 Dim Attended As Double = 1.0 Dim children As Double = 1.0 Dim adjacentxray As Double = 1.0 Dim film As Double = 1.0 Dim nurse As Double = 1.0 Dim xray As Double = 1.0 Dim Patient As Double = 1 / 2 Dim corridor As Double = 1 / 5 Dim Patientrooms As Double = 1 / 5 Dim Lounge As Double = 1 / 5 Dim staffrest As Double = 1 / 5 Dim Corridordoors As Double = 1 / 8 Dim Publictoilets As Double = 1 / 20 Dim unattendedvending As Double = 1 / 20 Dim storagerooms As Double = 1 / 20 Dim outdoor As Double = 1 / 20 Dim unattendingwaitingroom As Double = 1 / 20 Dim Patientholdingareas As Double = 1 / 20 Dim UnattendedParkinglot As Double = 1 / 40 Dim Vehicledropoffareas As Double = 1 / 40 Dim Stairways As Double = 1 / 40 Dim Janitorsclosets As Double = 1 / 40 Dim Unattendedelevators As Double = 1 / 40 Dim Outdoorareaswithpedtraffic As Double = 1 / 40 Dim outdoorareaswithvhtraffic As Double = 1 / 40 If Cmb_occupancyfactor.SelectedItem Is "fully occupied Administrative offices" Then Txtbox_occupancyfactor.Text = Administrative.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "fully occupied Clerical offices" Then Txtbox_occupancyfactor.Text = Clerical.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "fully occupied Laboratories" Then Txtbox_occupancyfactor.Text = Laboratories.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "fully occupied Pharmacies" Then Txtbox_occupancyfactor.Text = Administrative.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Receptionist areas" Then Txtbox_occupancyfactor.Text = Receptionist.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Attended waiting rooms" Then Txtbox_occupancyfactor.Text = Attended.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Children's indoor play areas" Then Txtbox_occupancyfactor.Text = children.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Adjacent x-ray rooms" Then Txtbox_occupancyfactor.Text = adjacentxray.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Film reading areas" Then Txtbox_occupancyfactor.Text = film.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Nurse's stations" Then Txtbox_occupancyfactor.Text = nurse.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "X-ray control rooms" Then Txtbox_occupancyfactor.Text = xray.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Patient exm & trt" Then Txtbox_occupancyfactor.Text = Patient.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Corridors" Then Txtbox_occupancyfactor.Text = corridor.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Patient rooms" Then Txtbox_occupancyfactor.Text = Patientrooms.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Employee lounges" Then Txtbox_occupancyfactor.Text = Lounge.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Staff rest rooms" Then Txtbox_occupancyfactor.Text = staffrest.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Corridor doors" Then Txtbox_occupancyfactor.Text = Corridordoors.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Public toilets" Then Txtbox_occupancyfactor.Text = Publictoilets.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Unattended vending areass" Then Txtbox_occupancyfactor.Text = unattendedvending.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Storage rooms" Then Txtbox_occupancyfactor.Text = storagerooms.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Outdoor areas with seating" Then Txtbox_occupancyfactor.Text = outdoor.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Unattended waiting rooms" Then Txtbox_occupancyfactor.Text = unattendingwaitingroom.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Patient holding areas" Then Txtbox_occupancyfactor.Text = Patientholdingareas.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Unattended Parking lot" Then Txtbox_occupancyfactor.Text = UnattendedParkinglot.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Vehicle drop-off areas" Then Txtbox_occupancyfactor.Text = Vehicledropoffareas.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Stairways" Then Txtbox_occupancyfactor.Text = Stairways.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Janitors closets" Then Txtbox_occupancyfactor.Text = Janitorsclosets.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Unattended elevators" Then Txtbox_occupancyfactor.Text = Unattendedelevators.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "Outdoor areas with ped-traffic" Then Txtbox_occupancyfactor.Text = Outdoorareaswithpedtraffic.ToString() ElseIf Cmb_occupancyfactor.SelectedItem Is "outdoor areas with vh-traffic" Then Txtbox_occupancyfactor.Text = outdoorareaswithvhtraffic.ToString() End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' Clear table Form2.Show() Txtbox_unshieldedairkerma.Clear() Txtbox_unshieldedairkerma.Clear() Txtbox_distance.Clear() Txtbox_occupancyfactor.Clear() Txtbox_usefactor.Clear() Txtbox_designgoal.Clear() Txt_leadthickness.Clear() Txt_transmissionfactor.Clear() Txt_numberofpatients.Clear() Txt_weeklyunshielded.Clear() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Close() End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo_usefactor.SelectedIndexChanged 'Values for usefactor Dim radfloor As Double = 0.89 Dim crosstable As Double = 0.09 Dim wallno3 As Double = 0.02 Dim chestimagereceptor = 1.0 Select Case Combo_usefactor.Text Case "Floor" With Txtbox_usefactor .Text = radfloor.ToString() End With Case "Cross-table wall" With Txtbox_usefactor .Text = crosstable.ToString End With Case "Wall No.3c" With Txtbox_usefactor .Text = wallno3.ToString() End With Case "Chest image receptor" With Txtbox_usefactor .Text = chestimagereceptor.ToString() End With End Select End Sub Public Sub Rad_lead_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rad_lead.CheckedChanged 'Lead Fitting parameters for transmission of broad primary x-ray Dim radroom_allbarriers_alpha As Double = 2.346, radroom_allbarriers_beta As Double = 15.9, radroom_allbarriers_gamma As Double = 0.4982 Dim radroom_chestbucky_alpha As Double = 2.264, radroom_chestbucky_beta As Double = 13.08, radroom_chestbucky_gamma As Double = 0.56 Dim radroom_floor_alpha As Double = 2.651, radroom_floor_beta As Double = 16.56, radroom_floor_gamma As Double = 0.4585 Dim fluoroscopy_tube_alpha As Double = 2.347, fluoroscopy_tube_beta As Double = 12.67, fluoroscopy_tube_gamma As Double = 0.6149 Dim radtube_alpha As Double = 2.295, radtube_beta As Double = 13.0, radtube_gamma As Double = 0.5573 Dim chestroom_alpha As Double = 2.283, chestroom_beta = 10.74, chestroom_gamma As Double = 0.637 Dim mammography_alpha As Double = 30.6, mammography_beta As Double = 177.6, mammography_gamma As Double = 0.3308 Dim cardiac_angiography_alpha As Double = 2.389, cardiac_angiography_beta As Double = 14.26, cardiac_angiography_gamma As Double = 0.5948 Dim peripheral_angiography_alpha As Double = 2.728, peripheral_angiography_beta As Double = 18.52, peripheral_angiography_gamma As Double = 0.4614 If Rad_lead.Checked = True Then Select Case combo_fitting.Text Case "Cardiac Angiography" With txtalpha .Text = cardiac_angiography_alpha.ToString() End With With txtbeta .Text = cardiac_angiography_beta.ToString() End With With txtgamma .Text = cardiac_angiography_gamma.ToString() End With Case "Chest Room" With txtalpha .Text = chestroom_alpha.ToString() End With With txtbeta .Text = chestroom_beta.ToString() End With With txtgamma .Text = chestroom_gamma.ToString() End With Case "Fluroscopy Tube (R&F room)" With txtalpha .Text = fluoroscopy_tube_alpha.ToString() End With With txtbeta .Text = fluoroscopy_tube_beta.ToString() End With With txtgamma .Text = fluoroscopy_tube_gamma.ToString() End With Case "Mammography Room" With txtalpha .Text = mammography_alpha.ToString() End With With txtbeta .Text = mammography_beta.ToString() End With With txtgamma .Text = mammography_gamma.ToString() End With Case " Peripheral(Angiography)" With txtalpha .Text = peripheral_angiography_alpha.ToString() End With With txtbeta .Text = peripheral_angiography_beta.ToString() End With With txtgamma .Text = peripheral_angiography_gamma.ToString() End With Case " Rad Room (all barriers)" With txtalpha .Text = radroom_allbarriers_alpha.ToString() End With With txtbeta .Text = radroom_allbarriers_beta.ToString() End With With txtgamma .Text = radroom_allbarriers_gamma.ToString() End With Case "Rad Room (chest bucky)" With txtalpha .Text = radroom_chestbucky_alpha.ToString() End With With txtbeta .Text = radroom_chestbucky_beta.ToString() End With With txtgamma .Text = radroom_chestbucky_gamma.ToString() End With Case "Rad Room (floor or other barriers)" With txtalpha .Text = radroom_floor_alpha.ToString() End With With txtbeta .Text = radroom_floor_beta.ToString() End With With txtgamma .Text = radroom_floor_gamma.ToString() End With Case "Rad Tube (R&F room)" With txtalpha .Text = radtube_alpha.ToString() End With With txtbeta .Text = radtube_beta.ToString() End With With txtgamma .Text = radtube_gamma.ToString() End With End Select End If Exit Sub End Sub Private Sub Rad_concrete_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rad_concrete.CheckedChanged 'Concrete Fitting parameters for transmission of broad primary x-ray 'each variable was prefixed C to indicate concrete Dim Cradroom_allbarriers_alpha As Double = 0.03626, Cradroom_allbarriers_beta As Double = 0.1429, Cradroom_allbarriers_gamma As Double = 0.4932 Dim Cradroom_chestbucky_alpha As Double = 0.03552, Cradroom_chestbucky_beta As Double = 0.1177, Cradroom_chestbucky_gamma As Double = 0.6007 Dim Cradroom_floor_alpha As Double = 0.03994, Cradroom_floor_beta As Double = 0.1448, Cradroom_floor_gamma As Double = 0.4231 Dim Cfluoroscopy_tube_alpha As Double = 0.03616, Cfluoroscopy_tube_beta As Double = 0.09721, Cfluoroscopy_tube_gamma As Double = 0.5186 Dim Cradtube_alpha As Double = 0.03549, Cradtube_beta As Double = 0.1164, Cradtube_gamma As Double = 0.5774 Dim Cchestroom_alpha As Double = 0.03622, Cchestroom_beta = 0.07766, Cchestroom_gamma As Double = 0.5404 Dim Cmammography_alpha As Double = 0.2577, Cmammography_beta As Double = 1.765, Cmammography_gamma As Double = 0.3644 Dim Ccardiac_angiography_alpha As Double = 0.03717, Ccardiac_angiography_beta As Double = 0.1087, Ccardiac_angiography_gamma As Double = 0.4879 Dim Cperipheral_angiography_alpha As Double = 0.04292, Cperipheral_angiography_beta As Double = 0.1538, Cperipheral_angiography_gamma As Double = 0.4236 If Rad_concrete.Checked = True Then Select Case combo_fitting.Text Case "Cardiac Angiography" With txtalpha .Text = Ccardiac_angiography_alpha.ToString() End With With txtbeta .Text = Ccardiac_angiography_beta.ToString() End With With txtgamma .Text = Ccardiac_angiography_gamma.ToString() End With Case "Chest Room" With txtalpha .Text = Cchestroom_alpha.ToString() End With With txtbeta .Text = Cchestroom_beta.ToString() End With With txtgamma .Text = Cchestroom_gamma.ToString() End With Case "Fluroscopy Tube (R&F room)" With txtalpha .Text = Cfluoroscopy_tube_alpha.ToString() End With With txtbeta .Text = Cfluoroscopy_tube_beta.ToString() End With With txtgamma .Text = Cfluoroscopy_tube_gamma.ToString() End With Case "Mammography Room" With txtalpha .Text = Cmammography_alpha.ToString() End With With txtbeta .Text = Cmammography_beta.ToString() End With With txtgamma .Text = Cmammography_gamma.ToString() End With Case "Peripheral Angiography" With txtalpha .Text = Cperipheral_angiography_alpha.ToString() End With With txtbeta .Text = Cperipheral_angiography_beta.ToString() End With With txtgamma .Text = Cperipheral_angiography_gamma.ToString() End With Case "Rad Room (all barriers)" With txtalpha .Text = Cradroom_allbarriers_alpha.ToString() End With With txtbeta .Text = Cradroom_allbarriers_beta.ToString() End With With txtgamma .Text = Cradroom_allbarriers_gamma.ToString() End With Case "Rad Room (chest bucky)" With txtalpha .Text = Cradroom_chestbucky_alpha.ToString() End With With txtbeta .Text = Cradroom_chestbucky_beta.ToString() End With With txtgamma .Text = Cradroom_chestbucky_gamma.ToString() End With Case "Rad Room (floor or other barriers)" With txtalpha .Text = Cradroom_floor_alpha.ToString() End With With txtbeta .Text = Cradroom_floor_beta.ToString() End With With txtgamma .Text = Cradroom_floor_gamma.ToString() End With Case "Rad Tube (R&F room)" With txtalpha .Text = Cradtube_alpha.ToString() End With With txtbeta .Text = Cradtube_beta.ToString() End With With txtgamma .Text = Cradtube_gamma.ToString() End With End Select End If Exit Sub End Sub Private Sub Rad_gypsum_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rad_gypsum.CheckedChanged 'Gypsum wallboard Fitting parameters for transmission of broad primary x-ray 'each variable is prefixed G to represent Gypsum wallboard Dim Gradroom_allbarriers_alpha As Double = 0.0142, Gradroom_allbarriers_beta As Double = 0.05781, Gradroom_allbarriers_gamma As Double = 0.7445 Dim Gradroom_chestbucky_alpha As Double = 0.01278, Gradroom_chestbucky_beta As Double = 0.04848, Gradroom_chestbucky_gamma As Double = 0.8609 Dim Gradroom_floor_alpha As Double = 0.01679, Gradroom_floor_beta As Double = 0.06124, Gradroom_floor_gamma As Double = 0.7356 Dim Gfluoroscopy_tube_alpha As Double = 0.0134, Gfluoroscopy_tube_beta As Double = 0.04283, Gfluoroscopy_tube_gamma As Double = 0.8796 Dim Gradtube_alpha As Double = 0.013, Gradtube_beta As Double = 0.04778, Gradtube_gamma As Double = 0.8485 Dim Gchestroom_alpha As Double = 0.01286, Gchestroom_beta = 0.03505, Gchestroom_gamma As Double = 0.9356 Dim Gmammography_alpha As Double = 0.09148, Gmammography_beta As Double = 0.709, Gmammography_gamma As Double = 0.3459 Dim Gcardiac_angiography_alpha As Double = 0.01409, Gcardiac_angiography_beta As Double = 0.04814, Gcardiac_angiography_gamma As Double = 0.8419 Dim Gperipheral_angiography_alpha As Double = 0.01774, Gperipheral_angiography_beta As Double = 0.06449, Gperipheral_angiography_gamma As Double = 0.7158 'Gypsum wallboard - assigning values to txtboxes If Rad_gypsum.Checked = True Then Select Case combo_fitting.Text Case "Cardiac Angiography" With txtalpha .Text = Gcardiac_angiography_alpha.ToString() End With With txtbeta .Text = Gcardiac_angiography_beta.ToString() End With With txtgamma .Text = Gcardiac_angiography_gamma.ToString() End With Case "Chest Room" With txtalpha .Text = Gchestroom_alpha.ToString() End With With txtbeta .Text = Gchestroom_beta.ToString() End With With txtgamma .Text = Gchestroom_gamma.ToString() End With Case "Fluroscopy Tube (R&F room)" With txtalpha .Text = Gfluoroscopy_tube_alpha.ToString() End With With txtbeta .Text = Gfluoroscopy_tube_beta.ToString() End With With txtgamma .Text = Gfluoroscopy_tube_gamma.ToString() End With Case "Mammography Room" With txtalpha .Text = Gmammography_alpha.ToString() End With With txtbeta .Text = Gmammography_beta.ToString() End With With txtgamma .Text = Gmammography_gamma.ToString() End With Case "Peripheral Angiography" With txtalpha .Text = Gperipheral_angiography_alpha.ToString() End With With txtbeta .Text = Gperipheral_angiography_beta.ToString() End With With txtgamma .Text = Gperipheral_angiography_gamma.ToString() End With Case "Rad Room (all barriers)" With txtalpha .Text = Gradroom_allbarriers_alpha.ToString() End With With txtbeta .Text = Gradroom_allbarriers_beta.ToString() End With With txtgamma .Text = Gradroom_allbarriers_gamma.ToString() End With Case "Rad Room (chest bucky)" With txtalpha .Text = Gradroom_chestbucky_alpha.ToString() End With With txtbeta .Text = Gradroom_chestbucky_beta.ToString() End With With txtgamma .Text = Gradroom_chestbucky_gamma.ToString() End With Case "Rad Room (floor or other barriers)" With txtalpha .Text = Gradroom_floor_alpha.ToString() End With With txtbeta .Text = Gradroom_floor_beta.ToString() End With With txtgamma .Text = Gradroom_floor_gamma.ToString() End With Case "Rad Tube (R&F room)" With txtalpha .Text = Gradtube_alpha.ToString() End With With txtbeta .Text = Gradtube_beta.ToString() End With With txtgamma .Text = Gradtube_gamma.ToString() End With End Select End If End Sub End Class
#8
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 07:31 PM
Yes after building the program i have not got a clue what is to be entered in the textboxes. I see it is returning .85 from the function so there is something else going on here. What numbers in what textboxes did you enter that should be 1.35
This post has been edited by IronRazer: 12 March 2013 - 07:34 PM
#9
Re: wrong product in a textbox when I calculate function is called
Posted 12 March 2013 - 08:06 PM
I have attached a pic and the values to be selected is shown. Everything with the code seems to be ok except the :
the code which subtract 0.85 from the leadthickness.
I have attached a pic and the values to be selected is shown. Everything with the code seems to be ok except the :
the code which subtract 0.85 from the leadthickness
the code which subtract 0.85 from the leadthickness.
I have attached a pic and the values to be selected is shown. Everything with the code seems to be ok except the :
the code which subtract 0.85 from the leadthickness
#10
Re: wrong product in a textbox when I calculate function is called
Posted 13 March 2013 - 04:08 AM
Hello koppong,
I am not sure if you debugged the code or not but, by placing some break points on these lines you should be able to follow the math and compare it to what you have on paper and see where the problem happens. You could also place a MessageBox after each math function and have it show you the math after each line.
I am not sure if you debugged the code or not but, by placing some break points on these lines you should be able to follow the math and compare it to what you have on paper and see where the problem happens. You could also place a MessageBox after each math function and have it show you the math after each line.
'Calculate the thickness of the lead needed to shield the dedicated chest unit Dim alphagamma, xbarrier, NTK, betaalpha As Double alphagamma = 1 / (alpha * gamma) NTK = ((numpatients * occupanfact * primaryker) / (designgoal * distravelled ^ 2)) ^ gamma betaalpha = beta / alpha xbarrier = (NTK + betaalpha) / (1 + betaalpha) Dim calc As Double leadthickness = (alphagamma) * Math.Log(xbarrier) calc = Calculate() leadthickness = leadthickness - calc Txt_leadthickness.Text = leadthickness.ToString("#.00")
Page 1 of 1