Sub lblRecap_Click
Dim lbl As Label
lbl = Sender
Dim id As CustomDialog2
Dim ph As Phone
Dim rentry, msg, idi As String
'r = row. there are many labels per row, and many rows, like a grid
'each labels .Tag on a row is the number for that row
r = lbl.Tag
Dim pnl As Panel 'panel for CustomDialog2
pnl.Initialize("")
pnl.Color = Colors.DarkGray
Dim idl As Label 'info label for CustomDialog2
idl.Initialize("") 'it has which day your entering hours for
idl.Text = lblRecap(r, 0).Text & " " & lblRecap(r, 1).Text
idl.Color = Colors.Transparent
idl.TextColor = Colors.White
idl.TextSize = 18
idl.Gravity = Gravity.CENTER
pnl.AddView(idl, 10dip, -10dip, 200dip, 40dip) 'add to panel
Dim ide As EditText 'edittext for CustomDialog2
ide.Initialize("idEditText") 'attempt to catch text for validation
ide.Text = lblRecap(r, 3).Text.Trim 'prefill with hours from main screen
If ide.Text = "0.00" Then ide.Text = "" 'blank if zero hours
ide.Typeface = Typeface.DEFAULT_BOLD
ide.Gravity = Gravity.RIGHT
ide.InputType = ide.INPUT_TYPE_PHONE
ide.ForceDoneButton = True '???
pnl.AddView(ide, 10dip, 34dip, 70dip, 38dip) 'add to panel
Dim idc As CheckBox 'checkbox for CustomDialog2
idc.Initialize("")
idc.Text = "34 Restart"
idc.Checked = lblRecap(r, 2).Visible
idc.TextColor = Colors.White
idc.TextSize = 18
idc.Typeface = Typeface.DEFAULT_BOLD
pnl.AddView(idc, 80dip, 20dip, 160dip, 60dip) 'add to panel
id.AddView(pnl, 220, 80) 'add panel to CustomDialog2
ide.RequestFocus 'attempt to show keyboard - failed
' this is the validation loop
' it will loop forever by default and will only exit if validation passed
Do While True
'show CustomDialog2
result = id.Show("On-Duty hours", "Ok", "Cancel", "Help", Null)
If result = DialogResponse.CANCEL Then
Exit 'user pressed [Cancel] or [Back]
Else If result = DialogResponse.NEGATIVE Then
Msgbox("...display help text...", "Recap Help")
Else
idi = ide.Text.Trim 'load edittext text to string
If idi = "" Then idi = "0" 'if blank, make zero
'if not a valid number at all, display error
If Not(IsNumber(idi)) Then
Msgbox("Please enter your ON DUTY hours as a numeric value from 0 - 24, with quarter hours expressed as .25, .5 and .75" & CRLF & CRLF & "(ex. 4 or 6.25 or 9.5 or 11.75)", "Recap Error")
Else
'now, split the number into a whole part and remainder
'perform inside Try just in case of error
Try
remainder = idi Mod 1
wholepart = idi - remainder
Catch
wholepart = -1 'any error will cause validation to fail
End Try
'test number here
If wholepart < 0 OR wholepart + remainder > 24 OR (remainder <> 0 AND remainder <> .25 AND remainder <> .5 AND remainder <> .75) Then
'display error message if validation failed
Msgbox("Please enter your ON DUTY hours as a numeric value from 0 - 24, with quarter hours expressed as .25, .5 and .75" & CRLF & CRLF & "(ex. 4 or 6.25 or 9.5 or 11.75)", "Recap Error")
Else
'validation passed at this point, process the user input
'I left my code intact for this post so you can see
' what I do with it... Note the Exit statement at the end of this block
idi = lstRecap.Get(r)
idi = idi.SubString2(0, 8)
If idc.Checked Then
idi = idi & "."
Else
idi = idi & " "
End If
idi = idi & NumberFormat2(wholepart + remainder, 2, 2, 2, False)
lstRecap.Set(r, idi)
File.WriteList(File.DirDefaultExternal, "Recap.lst", lstRecap)
Calc
Exit 'validation passed, user input processed, exit the do/loop now
End If
End If
End If
Loop
'drop the keyboard (not necessary with updated Dialogs library)
DoEvents
ph.HideKeyboard(Activity)
DoEvents
End Sub