ok as i make the program more dynamic
i had to validate the input result dynamically
but as i do the loop, i generate my webform once for the first input:
(learned that in school, first input, validate, then input again in a loop is result is bad)
X = 0
ReDim Preserve distmp(X) : ReDim Preserve namtmp(X) : ReDim Preserve deftmp(X) : ReDim Preserve typtmp(X) : ReDim Preserve errtmp(X)
distmp(X) = "Problem" '===== description displayed in front of the field
namtmp(X) = "symptom" '===== name of variable for programming purpose
deftmp(X) = "" '===== default value inside the form (the form will be 20 char long if no value here, but you can enter more)
typtmp(X) = "textbox" '===== type of data: textbox password (futur: more to come)
errtmp(X) = "enter a keyword to search in symptoms" '=== text to display after the form "facultatif"
'=== blue text "error" red text are special keywords
BUTtmp = {"ok", "cancel"}
a = dynforgen(distmp, namtmp, deftmp, typtmp, errtmp, BUTtmp, tit)
SYMPTOM = valres("fmid", "symptom", 1, distmp, namtmp, deftmp, typtmp, errtmp, BUTtmp, tit)
so, as i was getting my result in a web object in the web form, when i was regenerating my form, the reference to the object was vanishing
so i passed as paramater the frame name (fmid), and the input name (a textbox named symptom)
then i loop through all html elements in the frame to find the input textbox named symptom
then i can validate my result again dynamically
as i use this validation very often in my code, it will really free my program lines a lot
Function valres( _
ByVal strfra As String, _
ByVal strval As String, _
ByVal minlen As Integer, _
ByVal distmp As Array, _
ByVal namtmp As Array, _
ByVal deftmp As Array, _
ByVal typtmp As Array, _
ByVal errtmp As Array, _
ByVal BUTtmp As Array, _
ByVal TIT As String)
Dim inpdon As Integer
Dim err01 As Integer
Dim val01 As String
Dim tmpstr As String
Dim tmpfra As Object
Dim str01 As String
Dim str02 As String
Do
inpdon = 0
err01 = 0
'=== flag to say input is done, since there might be a defaut value, we must validate if user was finished
'=== "ok" button or "enter" key are the same
'=== and nothing was pressed on left frame (control frame)
If resbutlefstr = "" And (resbutmidstr = "ok" Or reskeymid = 13) Then
'== User has clicked the OK button, retrieve the values
'=== frame, value of object to read in the frame
'=== we loop through all objects to find the right one
'strfra strval
'flef = oie.document.frames("flef").document
If logall = 1 Then
fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " frame name: " & strfra)
fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " textbox name: " & strval)
End If
tmpfra = oIE.document.frames(strfra.ToString).document
For Each HTMLEle In tmpfra.getElementsByTagName("input")
str01 = LCase(HTMLEle.getAttribute("name"))
If str01 = strval Then
OBJ = HTMLEle
If logall = 1 Then
fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " found symptom")
End If
str02 = LCase(HTMLEle.GetAttribute("Value"))
End If
If logall = 1 Then
fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " symptom value: " & str02)
End If
Next
astr = OBJ.Value '=== namtmp is the variable name used earlier, before we call the dynamic form generation for input
'astr = fmid.form01.symptom.Value '=== namtmp is the variable name used earlier, before we call the dynamic form generation for input
If logall = 1 Then
fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " value of objval.value: " & astr)
End If
val01 = LCase(astr)
If Len(val01) < minlen Then
'=== this is disabled to 0 caraters, cause we can search empty string
tmpstr = "error - you must enter at least one caracter"
err01 = 1
errtmp(0) = tmpstr
'=== if the value was not good, we generate the dynamic input for again, with an error message after the form in red
a = dynforgen(distmp, namtmp, deftmp, typtmp, errtmp, BUTtmp, TIT)
reskeymid = 0
resbutmidstr = ""
Else
'=== the input was validated, we flag err01 to none, and flag inpdon to exit the loop
inpdon = 1
err01 = 0
End If
End If
System.Threading.Thread.Sleep(50)
'=== while we wait for input value, user can press "escape" key, "cancel" button or close internet explorer
If resbutmidstr = "cancel" Or reskeymid = 27 Or bReady = True Or resbutlefstr <> "" Then
'=== if user pressed escape or cancel, we clear the frames
If resbutmidstr = "cancel" Or reskeymid = 27 Then
a = clefra({"fmid", "fbot"})
resbutmidstr = "cancel"
End If
Exit Do
End If
'=== if there was an input error and no one used left control frame to exit, we keep asking for input
Loop While err01 <> 0 Or inpdon = 0
Return (val01)
End Function
No comments:
Post a Comment