Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to check if text box data is between 0.0 and 9.9 1

Status
Not open for further replies.

psybertek

Technical User
Mar 26, 2002
30
US
Hello all,

Man I am not sure where to start. I have 8 textboxes that have to have numerical data entered into them. Nothing is done with the data until the user presses cmd_calcit. I need to check if the data is between 0.0 and 9.9 inclusive in the first 4 boxes and if the data is between 4 and 7 in the other 4 boxes. and if not it stays in that box until correct data entered.

the entry order is first set of boxes(1) second set of boxes(1) then wait 30 seconds and first set of boxes(2) then second set of boxes(2) then wait ......... and so on

The other problem, I am not real sure where in the module to insert the code . The processing takes place when cmd_calcit is pressed

If anyone can help I would realy appreciate it.

[alien] Psybertek [alien]
-----------------------------------------
"Computer junkies never die, They Just upload."
____________________________________________________________

Option Explicit
Dim hcread(4) As Double
Dim rateass(4) As Double
Dim negnum(4)
Dim decay As Double
Dim a
Dim Secs As Long

Private Sub cmd_calcit_Click()
Dim msg, style, title, help, ctxt, response

style = 0
help = ""
ctxt = 1000

hcread(1) = Text1.Text
negnum(1) = Text5.Text
hcread(2) = Text2.Text
negnum(2) = Text6.Text
hcread(3) = Text3.Text
negnum(3) = Text7.Text
hcread(4) = Text4.Text
negnum(4) = Text8.Text
For a = 1 To 4
title = "Invalid Entry "
msg = negnum(a)
Select Case negnum(a) 'this is to decide how to calculate the rate of assencion
Case 1 To 2: response = MsgBox(msg, style, title, help, ctxt)
Case 7: rateass(a) = hcread(a) / 10
Case 6: rateass(a) = hcread(a) * 1
Case 5: rateass(a) = hcread(a) * 10
Case 4: rateass(a) = hcread(a) * 100
Case 3: rateass(a) = hcread(a) * 1000
Case Is > 7: response = MsgBox(msg, style, title, help, ctxt)
End Select
Next a
Text9.Text = rateass(1)
Text10.Text = rateass(2)
Text11.Text = rateass(3)
Text12.Text = rateass(4)
decay = rateass(4) - rateass(2)
Text13.Text = decay
Clipboard.Clear
Clipboard.SetText Text13.Text
End Sub

Private Sub cmd_clr_Click() 'this routine clears all text boxes
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
End Sub

Private Sub cmd_start_Click()
Secs = 120
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub cmdexit_Click()
End
End Sub

Private Sub Form_Load()

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label3_Click()

End Sub

Private Sub Label4_Click()

End Sub

Private Sub Label5_Click(Index As Integer)

End Sub

Private Sub Label6_Click(Index As Integer)

End Sub

Private Sub Label7_Click()

End Sub

Private Sub Label8_Click()

End Sub

Private Sub Label9_Click()

End Sub

Private Sub Text1_Change()

End Sub

Private Sub Text10_Change()

End Sub

Private Sub Text11_Change()

End Sub

Private Sub Text12_Change()

End Sub

Private Sub Text13_Change()

End Sub

Private Sub Text2_Change()

End Sub

Private Sub Text3_Change()

End Sub

Private Sub Text4_Change()

End Sub

Private Sub Text5_Change()

End Sub

Private Sub Text6_Change()

End Sub

Private Sub Text7_Change()

End Sub

Private Sub Text8_Change()

End Sub

Private Sub Text9_Change()

End Sub

Private Sub Timer1_Timer()
Label8 = Secs
Secs = Secs - 1
If Secs < 0 Then Timer1.Enabled = False
End Sub

 
You might try something like the following:
(its brute force, but should get the job done - having an control array would simplify the process)
Code:
Private Sub cmd_calcit_Click()

   If (CheckBoxOneToFour = True) Then
      If (CheckBoxFivetoEight = True) Then
         DoTheCalcs 
      End If
   End If

End Sub

Private Function CheckBoxOneToFour as Boolean

   Dim BoxesOK as Boolean
   Dim BoxVal as Single

   BoxesOK = False
   BoxVal = Val(Text1.Text)
   If ((BoxVal >= 0.0) and BoxVal <= 9.9)) Then
      BoxVal = Val(Text2.Text)
      If ((BoxVal >= 0.0) and BoxVal <= 9.9)) Then
         BoxVal = Val(Text3.Text)
         If ((BoxVal >= 0.0) and BoxVal <= 9.9)) Then
             BoxVal = Val(Text4.Text)
            If ((BoxVal >= 0.0) and BoxVal <= 9.9)) Then
               BoxesOK = True
            Else
               Text4.SetFocus
            End If
         Else
            Text3.SetFocus
         End If
      Else
         Text2.SetFocus
      End If
   Else
      Text1.SetFocus
   End If
   CheckBoxOneToFour = BoxesOK

End Function
And a similar function for the other boxes and then a function to do the calcs. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Cajuncenturion
Thank you for the input. I actualy had to put the code in the &quot;text1_lostfocus()&quot; sub routine. but it is working quite well, oh also I had to put it in each textbox_lostfocus sub, it's a little clumsy looking right now but with some tweeking it should work.

Again thanx for your assistance.


[alien] Psybertek [alien]
-----------------------------------------
&quot;Computer junkies never die, They Just upload.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top