Radio Button question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DonnaDarko
    New Member
    • Mar 2007
    • 8

    Radio Button question

    I need help again if possible!

    I want to offer two options for a future user of my program. In Option1(0), the variable resSat must be known and is then used to calculate the variable Mass_BLOB. For Option1(1), it is just the other way around. So if you know one, then the other can be calculated.

    So far, I have it that if you select Option1(0), everything calculates correctly from the current input file; however, if i update one of the other variables (such as BLOB_Width), it does not update the variable that is to be calculated, and which is affected by this change. And the second option does not calculate correctly at all. Finally, there seems to be something wrong with the OKButton procedure as the program crashes if it is activated.

    This is somewhat confusing i know, but here comes the code for this form:

    [CODE=vb]Option Explicit
    Dim i As Integer
    Dim Mass_BLOB As Double ' initial mass
    Dim resSat As Double ' Residual Saturation
    _______________ _______________ _______________ _

    Private Sub Form_Load()

    ' make sure that one option is selected (Option1 button)
    Dim allfalse As Boolean
    ' check if one option for description type is selected
    allfalse = True
    For i = 0 To 1
    If index_blob = i Then
    allfalse = False
    Option1(i).Valu e = True
    End If
    Next i
    'if no option is selected: select 1st
    If allfalse Then Option1(0).Valu e = True

    'Geometry
    For i = 0 To 3
    Text1(i).text = blobzone(i)
    '0: width
    '1: length
    '2: thickness
    '3: depth to contamination
    Next i

    'Further characteristics & Blob zone data
    'Time of spill
    Text11.text = gwspilltime(1)

    Text3(1).text = Format(blobzone (4), "0.000") '4: initial mass Blob zone
    Text2(1).text = Format(blobzone (5), "0.00") '5: Accessability Factor
    Text2(0).text = Format(blobzone (6), "0.00") '6: Total porosity
    Text3(0).text = Format(blobzone (7), "0.00") '7: residual saturation

    Call update_frame
    Call Estimate_values

    End Sub
    _______________ _______________ _____________

    Private Sub OKButton_Click( )

    'Check date format
    Dim textlength As Integer
    Dim minuspos As Integer
    Dim iswrong As Integer

    iswrong = 0
    textlength = Len(Text11.text )
    minuspos = InStr(Text11.te xt, "-")

    If textlength <> 7 Or minuspos <> 3 Then
    iswrong = 1
    Text11.BackColo r = &H6D74F5
    Else
    Text11.BackColo r = &HC0C0C0
    End If

    If iswrong = 1 Then

    Message = MsgBox("Wrong Date Format!", vbOKOnly + vbExclamation)

    Else

    'Geometry
    For i = 0 To 3
    If Text1(i).text = "" Then
    Text1(i).text = 1
    End If
    Next i
    'Further characteristics
    For i = 0 To 1
    If Text2(i).text = "" Then Text2(i).text = 0
    Next i
    ' Blob zone data
    For i = 0 To 1
    If Text3(i).text = "" Then Text3(i).text = 1
    Next i

    'Geometry
    For i = 0 To 3
    blobzone(i) = Text1(i).text
    '0: width
    '1: length
    '2: thickness
    '3: depth to contamination
    Next i
    'Time of spill
    gwspilltime(1) = Text11.text
    If Text11.text = "" Then
    gwspilltime_inm onths(1) = 0
    Else
    gwspilltime_inm onths(1) = (Right(Text11.t ext, 4) - 1900) * 12 + Left(Text11.tex t, 2)
    End If

    blobzone(4) = Text3(1).text '4: initial mass Blob zone
    blobzone(5) = Text2(1).text '5: Accessability Factor
    blobzone(6) = Text2(0).text '6: Total porosity blob zone
    blobzone(7) = Text3(0).text '7: residual saturation

    frmspecific_gws ource_Blob.Visi ble = False
    Unload frmspecific_gws ource_Blob

    End If ' end of "if iswrong = 1 then ... else"

    'set description type (Option1 button)
    For i = 0 To 1
    If Option1(i) = True Then
    index_blob = i
    End If
    Next i

    End Sub
    _______________ _______________ ___________
    Private Sub Option1_Click(I ndx As Integer)

    index_blob = Indx

    Call update_frame

    End Sub
    _______________ _______________ ____________-

    Private Sub CANCELButton_Cl ick()

    Unload frmspecific_gws ource_Blob
    frmspecific_gws ource_Blob.Visi ble = False

    End Sub
    _______________ _______________ _______________ ________
    Private Sub Estimate_values ()

    Dim Vol_BLOB As Double
    Dim BLOB_Width As Double
    Dim BLOB_Length As Double
    Dim z As Double
    Dim ntot As Double ' total porosity
    Dim rho As Double ' rho-NAPL
    Dim theta As Double ' after Eberhardt&Gratw ohl(2002): theta = NAPL porosity: theta = S° * ntot

    ' --------------------------------------------------------------------------
    ' determine input values
    ' --------------------------------------------------------------------------
    ' BLOB geometry
    BLOB_Width = Val(Text1(0).te xt)
    BLOB_Length = Val(Text1(1).te xt)
    ' BLOB thickness
    z = Val(Text1(2).te xt)
    ntot = Val(Text2(0).te xt)
    ' BLOB density
    rho = mixdat_unspec(1 )

    ' --------------------------------------------------------------------------
    ' calculations
    ' --------------------------------------------------------------------------

    'initial volume BLOB
    Vol_BLOB = BLOB_Width * BLOB_Length * z

    Select Case index_blob
    'description through residual phase
    Case 0
    resSat = Val(Text3(0).te xt) / 100
    theta = resSat * ntot ' NAPL porosity
    ' initial mass calculated from resSat
    Mass_BLOB = Vol_BLOB * 1000 * rho * theta
    'Mass_BLOB = Val(Text3(1).te xt)
    'description through initial mass
    Case 1
    Mass_BLOB = Val(Text3(1).te xt)
    ' resSat calculated from initial mass
    resSat = Mass_BLOB / rho * 1000 / (Vol_BLOB * ntot)
    ' theta ' NAPL porosity
    theta = Text3(0).text * ntot

    End Select
    Debug.Print "resSat: " & resSat & " ntot: " & ntot & "Mass_BLOB: " & Mass_BLOB;

    Label3.Caption = Format(Vol_BLOB , "0.000")
    Label4.Caption = Format(theta, "0.000000")
    Text3(1).text = Format(blobzone (4), "0.000")
    Text3(0).text = Format(blobzone (7), "0.00")

    End Sub
    _______________ _______________ _______________ _

    Private Sub update_frame()

    Select Case index_blob
    ' description through residual saturation
    Case 0
    Option1(0).Valu e = True
    Option1(1).Valu e = False
    Text3(0).BackCo lor = &HC0C0C0 ' residual saturation can be entered
    Text3(0).Enable d = True
    Text3(1).BackCo lor = &H808080 ' inital mass is calculated; cannot be entered
    Text3(1).Enable d = False
    ' description through inital mass
    Case 1
    Option1(0).Valu e = False
    Option1(1).Valu e = True
    Text3(0).BackCo lor = &H808080 ' inital mass can be entered
    Text3(0).Enable d = False
    Text3(1).BackCo lor = &HC0C0C0 ' residual saturation is calculated; cannot be entered
    Text3(1).Enable d = True
    End Select

    Call Estimate_values

    End Sub
    _______________ _______________ _______________ __
    Private Sub UpdateValuesBUT TON_Click()

    Call Estimate_values

    End Sub[/CODE]
    _______________ _______________ _______________ ___

    Thanks for helping!!
    Donna
    Last edited by Killer42; Aug 9 '07, 07:49 AM. Reason: Added [CODE=vb] tag
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Have you tried stepping through the code? That's one of the most effective debugging techniques. By interrupting the code and then hitting F8 to execute one statement at a time, you can watch exactly what's happening, and examine the values of variables and properties as you go. It's often surprising how different it is to what you thought was happening.

    Comment

    • DonnaDarko
      New Member
      • Mar 2007
      • 8

      #3
      Originally posted by Killer42
      Have you tried stepping through the code? That's one of the most effective debugging techniques. By interrupting the code and then hitting F8 to execute one statement at a time, you can watch exactly what's happening, and examine the values of variables and properties as you go. It's often surprising how different it is to what you thought was happening.

      Forgot to say thanks...didnt know about F8ing! have another question now, and will start a new tab. thanks, figured this one out!

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by DonnaDarko
        Forgot to say thanks...didnt know about F8ing! have another question now, and will start a new tab. thanks, figured this one out!
        Great! Glad to hear it's sorted. :)

        Those debugging tools are well worth learning about.

        Comment

        • sgrec7
          New Member
          • Aug 2007
          • 58

          #5
          Originally posted by Killer42
          Great! Glad to hear it's sorted. :)

          Those debugging tools are well worth learning about.
          is there any others that we should know about

          BTW. is it bad to necro old threads like this ???

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by sgrec7
            is there any others that we should know about
            Hm... sounds like a good topic for an article on the Articles area. But briefly, it probably depends on the version of VB you're using. In VB6, you can set breakpoints or watchpoints to interrupt execution at a particular place in the code or when a particular condition is met, respectively. You can step through execution one statement at a time, you can examine and change variables during the interruption. You can also examine the "call stack" to see how you reached this point in the code, but I haven't really used that.

            During an interruption (by breakpoint or whatever) you can also, within certain limits, set execution to continue at a different point.

            One important tip. Learn the difference between "step into" and "step over" on the Debug menu. This will save you a lot of time and effort.

            I have no idea what debugging facilities are available in later versions.


            Originally posted by sgrec7
            BTW. is it bad to necro old threads like this ???
            Probably. Who knows... :)

            Comment

            Working...