0
Reply

Problem with on_load event. Why is this happening?

gangsta_rafiki

gangsta_rafiki

Apr 7 2005 6:47 AM
1.8k
Could someone please take a look at my code below and see if they can spot what is going wrong. Basically i am developing a small application using the smart device platform. I have a button on a form named Info2 (code below) that when clicked should open up a form named Requirements and then the Requirements_Load event should then populate each of the forms text boxes with the correct value. However, currently the last two text boxes which require the 'chosen_type' and 'feed_repetitions' (both in bold below)variables do not display the correct value when the Requirements form is loaded. Instead, the 'chosen_type' variable is set to Jevity-the first entry in the array, and the feed_repetitions is still at zero. However, then when i click on a button back to Info2 and then from Info2 click 'Next' to go forward to the Requirements form all of the text boxes display the correct values. I have bolded section pertaining to assigning values to the chosen_type and feed_repetitions in the code below. CAN ANYONE HELP ME PLEASE?? Code for Info2 form visual basic code:--------------------------------------------------------------------------------Private Sub BtnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNext.Click If Me.ComBxMob.Text = "" Then MessageBox.Show("Please Select the Mobility Value", "Input Error") ElseIf Me.ComBxTempAdj.Text = "" Then MessageBox.Show("Please Select the Energy Adjustment for Temperature", "Input Error") ElseIf ComBxProtein.Text = "" Then MessageBox.Show("Please Select the Nitrogen Value", "Input Error") ElseIf Me.ComBxEnergyChange.Text <> "" And Me.TxtBxEnergyChange.Text = "" Then MessageBox.Show("Please Enter the Energy Change Value", "Input Error") ElseIf Me.ComBxEnergyChange.Text = "" And Me.TxtBxEnergyChange.Text = "" Then 'goReq_Details = New Req_Details goRequirements = New Requirements goRequirements.Show() goInfo2.Hide() Else If Me.ComBxEnergyChange.Text = "Increase" Then EnergyChangeAdd = Me.TxtBxEnergyChange.Text 'goReq_Details = New Req_Details goRequirements = New Requirements goRequirements.Show() goInfo2.Hide() End If If Me.ComBxEnergyChange.Text = "Decrease" Then EnergyChangeMin = Me.TxtBxEnergyChange.Text 'goReq_Details = New Req_Details goRequirements = New Requirements goRequirements.Show() goInfo2.Hide() End If End If End Sub-------------------------------------------------------------------------------- Code for Requirements_Load in Requirements Form visual basic code:--------------------------------------------------------------------------------Private Sub Requirements_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim chosen_type As String Dim qty_required As Integer Dim i As Integer Dim j As Integer Dim k As Integer Dim mj As Integer mj = 999999 Dim feed_divisor As Double Dim feed_repetitions As Integer If Temperature > 37 Then AddFluid = (Temperature - 37) * 2 ElseIf Temperature <= 37 Then AddFluid = 0 End If If Sex = "Male" Then Select Case Age Case "15-18" BMR = ((17.6 * Weight) + 656) TotalFluid = (AddFluid + (35 * Weight)) Case "19-30" BMR = ((15.0 * Weight) + 690) TotalFluid = (AddFluid + (35 * Weight)) Case "31-60" BMR = ((11.4 * Weight) + 870) TotalFluid = (AddFluid + (35 * Weight)) Case "61+" BMR = ((11.7 * Weight) + 585) TotalFluid = (AddFluid + (35 * Weight)) End Select Else Select Case Age Case "15-18" BMR = ((13.3 * Weight) + 690) TotalFluid = (AddFluid + (35 * Weight)) Case "19-30" BMR = ((14.8 * Weight) + 485) TotalFluid = (AddFluid + (35 * Weight)) Case "31-60" BMR = ((8.1 * Weight) + 842) TotalFluid = (AddFluid + (35 * Weight)) Case "61+" BMR = ((9 * Weight) + 656) TotalFluid = (AddFluid + (35 * Weight)) End Select End If Select Case Mobility Case "Bedbound Immobile" MobilityVal = (BMR * 0.1) Case "Bedbound Mobile" MobilityVal = (BMR * 0.15) Case "Mobile On Ward" MobilityVal = (BMR * 0.2) End Select Select Case TemperatureAdj Case "None" TemperatureVal = (0) Case "10% Increase" TemperatureVal = (BMR * 0.1) End Select For i = 0 To UBound(feed_data) j = TotalEnergy Mod feed_data(i, 1) k = TotalEnergy Mod feed_data(i, 1) If j > 50 Then j = feed_data(i, 1) - j End If If j < mj Then mj = j feed_divisor = feed_data(i, 1) If k > 50 Then feed_repetitions = (TotalEnergy / feed_divisor) + 1 Else feed_repetitions = (TotalEnergy / feed_divisor) End If chosen_type = feed_data(i, 0) End If Next TotalEnergy = (BMR + MobilityVal + TemperatureVal + EnergyChangeAdd - EnergyChangeMin) TxtBxTot2.Text = TotalEnergy TotalProtein = (Nitrogen * 6.25 * Weight) TxtBxProtein.Text() = TotalProtein TxtBxFluid.Text() = TotalFluid TotalSodium = (Weight * 1) + AddFluid TxtBxSodium.Text() = TotalSodium TotalPotassium = (Weight * 1) + AddFluid TxtBxPotassium.Text() = TotalPotassium TxtBxFeedSuggested.Text() = chosen_type TxtBxQuantitySuggested.Text() = 100 * feed_repetitions End Sub