By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,813 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Radio Button question

P: 8
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:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim i As Integer
  3. Dim Mass_BLOB As Double    ' initial mass
  4. Dim resSat As Double       ' Residual Saturation
  5. ______________________________________________
  6.  
  7. Private Sub Form_Load()
  8.  
  9.     ' make sure that one option is selected (Option1 button)
  10.     Dim allfalse As Boolean
  11.     ' check if one option for description type is selected
  12.     allfalse = True
  13.     For i = 0 To 1
  14.       If index_blob = i Then
  15.          allfalse = False
  16.          Option1(i).Value = True
  17.       End If
  18.     Next i
  19.     'if no option is selected: select 1st
  20.     If allfalse Then Option1(0).Value = True
  21.  
  22.     'Geometry
  23.         For i = 0 To 3
  24.             Text1(i).text = blobzone(i)
  25.             '0: width
  26.             '1: length
  27.             '2: thickness
  28.             '3: depth to contamination
  29.         Next i
  30.  
  31.     'Further characteristics & Blob zone data
  32.         'Time of spill
  33.         Text11.text = gwspilltime(1)
  34.  
  35.         Text3(1).text = Format(blobzone(4), "0.000")   '4: initial mass Blob zone
  36.         Text2(1).text = Format(blobzone(5), "0.00")    '5: Accessability Factor
  37.         Text2(0).text = Format(blobzone(6), "0.00")    '6: Total porosity
  38.         Text3(0).text = Format(blobzone(7), "0.00")    '7: residual saturation
  39.  
  40.     Call update_frame
  41.     Call Estimate_values
  42.  
  43. End Sub
  44. ___________________________________________
  45.  
  46. Private Sub OKButton_Click()
  47.  
  48.     'Check date format
  49.     Dim textlength As Integer
  50.     Dim minuspos As Integer
  51.     Dim iswrong As Integer
  52.  
  53.     iswrong = 0
  54.     textlength = Len(Text11.text)
  55.     minuspos = InStr(Text11.text, "-")
  56.  
  57.     If textlength <> 7 Or minuspos <> 3 Then
  58.        iswrong = 1
  59.        Text11.BackColor = &H6D74F5
  60.     Else
  61.        Text11.BackColor = &HC0C0C0
  62.     End If
  63.  
  64.     If iswrong = 1 Then
  65.  
  66.     Message = MsgBox("Wrong Date Format!", vbOKOnly + vbExclamation)
  67.  
  68.     Else
  69.  
  70.         'Geometry
  71.             For i = 0 To 3
  72.                 If Text1(i).text = "" Then
  73.                     Text1(i).text = 1   
  74.                 End If
  75.             Next i
  76.         'Further characteristics
  77.         For i = 0 To 1
  78.             If Text2(i).text = "" Then Text2(i).text = 0
  79.         Next i
  80.         ' Blob zone data
  81.         For i = 0 To 1
  82.             If Text3(i).text = "" Then Text3(i).text = 1
  83.         Next i
  84.  
  85.         'Geometry
  86.             For i = 0 To 3
  87.                 blobzone(i) = Text1(i).text
  88.                 '0: width
  89.                 '1: length
  90.                 '2: thickness
  91.                 '3: depth to contamination
  92.             Next i
  93.         'Time of spill
  94.         gwspilltime(1) = Text11.text
  95.             If Text11.text = "" Then
  96.                 gwspilltime_inmonths(1) = 0
  97.             Else
  98.                 gwspilltime_inmonths(1) = (Right(Text11.text, 4) - 1900) * 12 + Left(Text11.text, 2)
  99.             End If
  100.  
  101.         blobzone(4) = Text3(1).text    '4: initial mass Blob zone
  102.         blobzone(5) = Text2(1).text    '5: Accessability Factor
  103.         blobzone(6) = Text2(0).text    '6: Total porosity blob zone
  104.         blobzone(7) = Text3(0).text    '7: residual saturation
  105.  
  106.     frmspecific_gwsource_Blob.Visible = False
  107.     Unload frmspecific_gwsource_Blob
  108.  
  109.     End If    ' end of "if iswrong = 1 then ... else"
  110.  
  111.     'set description type (Option1 button)
  112.     For i = 0 To 1
  113.        If Option1(i) = True Then
  114.          index_blob = i
  115.        End If
  116.     Next i
  117.  
  118. End Sub
  119. _________________________________________
  120. Private Sub Option1_Click(Indx As Integer)
  121.  
  122. index_blob = Indx
  123.  
  124. Call update_frame
  125.  
  126. End Sub
  127. __________________________________________-
  128.  
  129. Private Sub CANCELButton_Click()
  130.  
  131. Unload frmspecific_gwsource_Blob
  132. frmspecific_gwsource_Blob.Visible = False
  133.  
  134. End Sub
  135. _____________________________________________________
  136. Private Sub Estimate_values()
  137.  
  138.     Dim Vol_BLOB As Double
  139.     Dim BLOB_Width As Double
  140.     Dim BLOB_Length As Double
  141.     Dim z As Double
  142.     Dim ntot As Double    ' total porosity
  143.     Dim rho As Double     ' rho-NAPL
  144.     Dim theta As Double   ' after Eberhardt&Gratwohl(2002): theta = NAPL porosity: theta = S * ntot
  145.  
  146.     ' --------------------------------------------------------------------------
  147.     ' determine input values
  148.     ' --------------------------------------------------------------------------
  149.     ' BLOB geometry
  150.     BLOB_Width = Val(Text1(0).text)
  151.     BLOB_Length = Val(Text1(1).text)
  152.     ' BLOB thickness
  153.     z = Val(Text1(2).text)
  154.     ntot = Val(Text2(0).text)
  155.     ' BLOB density
  156.     rho = mixdat_unspec(1)
  157.  
  158.     ' --------------------------------------------------------------------------
  159.     ' calculations
  160.     ' --------------------------------------------------------------------------
  161.  
  162.     'initial volume BLOB
  163.     Vol_BLOB = BLOB_Width * BLOB_Length * z
  164.  
  165.     Select Case index_blob
  166.         'description through residual phase
  167.         Case 0
  168.             resSat = Val(Text3(0).text) / 100
  169.             theta = resSat * ntot     ' NAPL porosity
  170.             ' initial mass calculated from resSat
  171.             Mass_BLOB = Vol_BLOB * 1000 * rho * theta
  172.             'Mass_BLOB = Val(Text3(1).text)
  173.         'description through initial mass
  174.         Case 1
  175.               Mass_BLOB = Val(Text3(1).text)
  176.             ' resSat calculated from initial mass
  177.             resSat = Mass_BLOB / rho * 1000 / (Vol_BLOB * ntot)
  178.             ' theta           ' NAPL porosity
  179.             theta = Text3(0).text * ntot
  180.  
  181.     End Select
  182.     Debug.Print "resSat: " & resSat & " ntot: " & ntot & "Mass_BLOB: " & Mass_BLOB;
  183.  
  184.     Label3.Caption = Format(Vol_BLOB, "0.000")
  185.     Label4.Caption = Format(theta, "0.000000")
  186.     Text3(1).text = Format(blobzone(4), "0.000")
  187.     Text3(0).text = Format(blobzone(7), "0.00")
  188.  
  189. End Sub
  190. ______________________________________________
  191.  
  192. Private Sub update_frame()
  193.  
  194.     Select Case index_blob
  195.     ' description through residual saturation
  196.     Case 0
  197.         Option1(0).Value = True
  198.         Option1(1).Value = False
  199.         Text3(0).BackColor = &HC0C0C0            ' residual saturation can be entered
  200.         Text3(0).Enabled = True
  201.         Text3(1).BackColor = &H808080            ' inital mass is calculated; cannot be entered
  202.         Text3(1).Enabled = False
  203.     ' description through inital mass
  204.     Case 1
  205.         Option1(0).Value = False
  206.         Option1(1).Value = True
  207.         Text3(0).BackColor = &H808080           ' inital mass can be entered
  208.         Text3(0).Enabled = False
  209.         Text3(1).BackColor = &HC0C0C0           ' residual saturation is calculated; cannot be entered
  210.         Text3(1).Enabled = True
  211.     End Select
  212.  
  213. Call Estimate_values
  214.  
  215. End Sub
  216. _______________________________________________
  217. Private Sub UpdateValuesBUTTON_Click()
  218.  
  219.     Call Estimate_values
  220.  
  221. End Sub
________________________________________________

Thanks for helping!!
Donna
Aug 8 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 5K+
P: 8,434
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.
Aug 9 '07 #2

P: 8
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!
Aug 28 '07 #3

Expert 5K+
P: 8,434
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.
Aug 29 '07 #4

sgrec7
P: 59
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 ???
Sep 2 '07 #5

Expert 5K+
P: 8,434
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.


BTW. is it bad to necro old threads like this ???
Probably. Who knows... :)
Sep 2 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.