Sunday, August 28, 2011

all done

i finished at work my programming for dynamic web interface in visual studio 2010

i had logic problem clearing frames
and also the program crash on start sometimes, because the internet explorer is not ready to process commands

i tried to add some "ready state" wait loop, but it report never ready when the object internet explorer is not visible, i guess the ready status is based on the status bar, and if it's not visible, the ready status never come to "ready"

i'll try different ways for this, like after creating the object, i'll chek if it's equal to nothing and loop until it's different from nothing

also instead of pusing many line from an array in internet explorer object, i'll push them in a variable, then push the whole string in one command, so my internet explorer object will not report not ready and crash the program if i send too many line in a short amount of time

(although if the object is not ready for the big string, it will still crash)

it will be perfect! ;) one day

i'll start programming it for other applications than the troubleshooting database for crucible cleaner for STAS



Monday, August 22, 2011

not working with simply the files

i will have to check the references i addded
i added the 2.8 for adodb
maybe i should have added the 2.7
the computer i tried it on was windows server 2008 fully updated with frame work 4.0

first test on another computer

i did a first test on another computer and obviously it's not working

i'll simply copy the exe and all it's files and see if it's working

publish status include

setup working

i had to go to the publish tab in visual studio 2010
then on my .MDB, publish status: include (no auto)

and all is published and work fine when i click setup

i still wonder why it's not compiling a MSI file, but a setup that publish the application in a temp folder instead of "program files"

will check that later to make a true MSI

funny visual studio

after i told studio my images were embedded ressources
it did not include them in the setup

so much for honesty and protocol haha
ill revert thoses properties to CONTENT


compiling the application

compile work, half of it

when i insert a MDB file, visual studio does not let me edit it's properties and set it as embedded ressource
so he does not copy the mdb in the executable directory, thus program not working...

for the images it work fine

Sunday, August 21, 2011

all done

all done, the program:
crucible cleaning troubleshooting database
is now fully working in visual studio 2010
with internet explorer as interface

now i need to find how to compile a setup with visual studio 2010
add the images in this setup and the database (mdb)


found how to integrate to vb 2010 onquit for internet explorer

found how to integrate to vb 2010 onquit for internet explorer without linking to the SHDocVw.dll as least not directly in the syswow64 directory but with the com reference that was created for it


right click on project in visual studio 2010:

'add reference, com, microsoft internet control

    Public oIE As SHDocVw.InternetExplorer



        oIE = New SHDocVw.InternetExplorer
        AddHandler oIE.onQuit, AddressOf oIE_onQuit



    Private Sub oIE_onQuit()
        End
    End Sub

so when my user quit internet explorer (wich is the main interface), the program end

now working on the 2 other functions of the project
causes search and component search



web interface raising custom event for when internet explorer close

working on the closing event

for internetexplorer.application


enough for tonight event handling

so i had to fiin d how to create an event handling if the OIE object disappear
(if the user close internet explorer)

it's long... lots of research

going to bed

hide console window

simply changed console application to windows application in visual studio, project, application panel

programming again

added the path variable


        Dim strAppPath As String
        strAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location()
        BASEDIR = Left(strAppPath, InStrRev(strAppPath, "\"))


now working on hiding the system.console (the dos windows that pop up when program execute


Saturday, August 20, 2011

keyboard working in web interface onkeypress event handler now working


keyboard now working in web interface

that was tricky
i had to prevent the return of the code 13 (enter) in the onkeypress handler
wich i use in my program, as you enter something in a textbox, then press enter or escape
or else my textbox was not returning a string type, but something else... tum tum tum...
that was poping a conversion type error

for escape, it was not returning anything because i cancel the input when esc is pressed

           AddHandler CType(flef, mshtml.HTMLDocumentEvents2_Event).onkeypress, AddressOf prekeylef
        AddHandler CType(fmid, mshtml.HTMLDocumentEvents2_Event).onkeypress, AddressOf prekeymid
        AddHandler CType(fbot, mshtml.HTMLDocumentEvents2_Event).onkeypress, AddressOf prekeybot


'==================


 Private Function prekeylef(ByVal e As mshtml.IHTMLEventObj) As Boolean
        'System.Console.Write("button clicked: " & e.srcElement.tagName.ToString() & vbCrLf)
        reskeylef = e.keyCode
        If reskeylef <> 13 And reskeylef <> 27 Then
            Return e.keyCode
        End If
        'System.Console.Write("keypressed " & reskeylef.ToString)
    End Function
    Private Function prekeymid(ByVal e As mshtml.IHTMLEventObj) As Boolean
        'System.Console.Write("button clicked: " & e.srcElement.tagName.ToString() & vbCrLf)
        reskeymid = e.keyCode
        If reskeymid <> 13 And reskeymid <> 27 Then
            'eee
            'MsgBox(" keycode" & reskeylef.ToString)
            Return e.keyCode
        End If


        'System.Console.Write("button clicked: " & resbutmidstr & vbCrLf)
    End Function
    Private Function prekeybot(ByVal e As mshtml.IHTMLEventObj) As Boolean
        'System.Console.Write("button clicked: " & e.srcElement.tagName.ToString() & vbCrLf)
        reskeybot = e.keyCode
        If reskeybot <> 13 And reskeybot <> 27 Then
            Return e.keyCode
        End If


        'System.Console.Write("button clicked: " & resbutbotstr & vbCrLf)
    End Function

corrected the button click event in a grey area


corrected the button click event in a grey area


    Private Function butclilef(ByVal e As mshtml.IHTMLEventObj) As Boolean
        'System.Console.Write("button clicked: " & e.srcElement.tagName.ToString() & vbCrLf)
        If e.srcElement.id IsNot Nothing Then
            resbutlefstr = LCase(Trim(e.srcElement.id.ToString()))
        End If
        'System.Console.Write("button clicked: " & resbutlefstr & vbCrLf)
    End Function
first part working:
problem search to symptoms to component to diagnostic
(4 table related in a mdb)

as it's 3 loop search one in another it was the longest part
strangely i had to correct some column name ([num1] is now [s/n] wich is not dynamic at all...) for second search and third search results

i also noticed if i click in the web page white area, the click event is executing and returning an error as i try to convert the result to a string

as a result of the compilation in vb.net instead of a wsh (wscript) the result display much faster




Friday, August 19, 2011

number of row corrected


i did not change this sub the right way
my catch was bad, now it's ok

the ubound fonction will return an error id you chek the number of elements in the second dimension and there is only one line in the array

so if there is only one line we return the number of line of the first dimension, not the second


    '=== count the number of record in the array
    Function cnttotrec(ByVal aara As Array)
        Dim aa As Integer


        xmax = UBound(aara, 1) 'Returns the Number of columns  --- elements in first dimension
        '=== chek the number of elements in second dimension
        '=== if there is none, then the array have only 1 row
        Try
            ymax = UBound(aara, 2) 'Returns the Number of rows     --- elements in second dimension
            aa = ymax
        Catch ex As Exception
            aa = xmax
        End Try


        '=== number of dimensions in case there is only 1 column
        Return (aa)
    End Function

array and adodb recordset

now my array is filled up with 6 rows
ara03 = tag.GetRows()

but i see clearly the problem, as the number of row the array get is in fact the number of columns

working on it...

record number in dataset

I found my first problem

my adodb.recordset was not configured to count the number of records correctly

of course there was 1000 solution on internet, but none was for visual basic net 2010
I finally found the good one!

here is my new code for the sql request:


    Function exesql( _
    ByVal oobjcon As ADODB.Connection, _
    ByVal dummy As ADODB.Recordset, _
    ByVal SQL01 As String)


        Dim cmd As New ADODB.Command()
        Dim aaa As String
        Dim count As Integer
        'On Error Resume Next
        Const adOpenStatic = 3
        Const adLockOptimistic = 3
        Const adOpenForwardOnly = 0


        ttag = New ADODB.Recordset
        ttag.CacheSize = 1
        ttag.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        ttag.CursorType = ADODB.CursorTypeEnum.adOpenStatic
        ttag.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic


        Try
            If logall = 1 Then
                fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " query:")
                fil02.writeline(SQL01)
            End If
            '=== caca3
            '=== ADODB.Recordset how many did we get? bug


            'objRecordset.Open source,actconn,cursortyp,locktyp,opt


            'ttag.Open(SQL01, oobjcon)
            'ttag.CacheSize = 1000
            'ttag = objcon.Execute(SQL01)


            ttag.Open(SQL01, objcon)


            'ttag.CacheSize = 1000
            'ttag.MoveLast()


            'count = ttag.Fields.Count
            count = ttag.RecordCount


            If logall = 1 Then
                fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " query done without error")
                fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " total count in recordset: " & count)
            End If
        Catch ex As Exception
            aaa = Err.Description
            l1 = "error in query"
            l2 = "query: " & SQL01
            l3 = "error: " & aaa
            l4 = "the program will now end"
            fbot.WriteLn(l1 & "<BR><br>" & l2 & "<BR><br>" & l3 & "<BR><br>" & l4 & "<BR><br>")


            If logall = 1 Then
                fil02.writeline("query:")
                fil02.writeline(SQL01)
                fil02.writeline(Err.Description)
            End If
        End Try
        'wscript.quit()
        '=== END PROGRAM 
        Return (ttag)
    End Function




vb.net 2010 web interface programming

i got 6 results instead of 600

finding problem...

that one was hard validate dynamically an input of wich the frame and name change

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

code working

ok i am now cleaning code

adding lots of new subs, object oriented, because i cannot manage all thoses variables the same way (public) as in a simple script (wsh)

i also add a lot of new subs, because i do not want to rewrite all code next time

Thursday, August 18, 2011

premier resultats woohoo

After few modifications to dataset management

and lots of modification to array (redim cannot change number of dimensions)

its giving its first results in internet explorer (my web interface):

SYMPTOMS
Select S/N S/N 2 Symptom Problem Probability Confirmation
9 1 The carrier moves only in one direction One coil of the proportional valve is not well connected 0,65 2
67 1 FAULT HYDRAULIC OIL LOW LEVEL Cumulative of minor leaks of oil during maintenance 0,4 2
41 1 Hydraulic oil level in tank too low Cumulative of minor leaks of oil during maintenance 0,4 2
20 1 Many filters clogued at the same time Oil is too cold (during start-up) 0,35 1
9 2 The carrier moves only in one direction One coil is bursted on the proportional directional valve 0,35 2
7 1 External oil leaks on a component A mechanical joint is not torqued enough 0,35 2


Now most poeple will ask the eternal question:
why you did not use a frame and a dataset and put the results in a windows made by vb.net?

same answer:
the windows generated by vb.net is not dynamic
even the GRID made by .net framework for internet explorer is bad for dynamic resizable results
when you resize it, it's not ajusting columns size horizontally (or it does, but badly)

I should use crytal report you say?
and double my job by having to generate nice reports?
no thanks

That is why i use internet explorer as interface:
resizable
zoomable (you know thoses letter become small, with thoses new screens full hd)
printable (with automatic width adjustement to the paper)
copy/past able (easy to copy a table in excel for analysis)

More to come on the progress

lots of  corrections to make on the rest of my code to make everything work
but the main thing is working:
buttons control
database access

the rest is just lots of typing and debugging

to do:
make the ENTER key work again with vb
correct all the redim that change number of dimensions
change all array variables using bad number of dimensions

Good night!




Wednesday, August 17, 2011

Monday, August 15, 2011

it work

all this to replace this command in vbscript:
flef.onkeypress = getref("Checklef")
in visual studio 2010

left click on my project (visual studio 2010) (from vbscript)
add reference
microsoft html object library

my oie (internet explorer object):

        Dim OIE As Object
        OIE = CreateObject("InternetExplorer.Application")


my frames:

        '=== object used to write in a frame with writeln
        flef = oie.document.frames("left").document
        fmid = oie.document.frames("middle").document
        fbot = oie.document.frames("bottom").document


my event definition when i define all my buttons:
(wich i can place anywhere now, as the button name is returned)
(new limitation: i cannot name two button with same name in differents frames)
   AddHandler CType(flef, mshtml.HTMLDocumentEvents2_Event).onclick, AddressOf butcli_onclick

and finally my new fonction that will display (as a test) the type and name of the button:

    Private Function butcli_onclick(ByVal e As mshtml.IHTMLEventObj) As Boolean


        'For Each HTMLEle In flef.getElementsByTagName("input")
        '    str01 = LCase(HTMLEle.getAttribute("name"))
        '    str02 = LCase(HTMLEle.getAttribute("type"))
        System.Console.Write("button clicked: " & e.srcElement.tagName.ToString() & vbCrLf)
        System.Console.Write("button clicked: " & e.srcElement.className.ToString() & vbCrLf)


    End Function


strangely, the "classname" is the name of the button that was pressed in internet explorer

also i hate when poeple does not state their imports:

Imports System
Imports System.Xml
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Reflection
'Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.Diagnostics





Sunday, August 14, 2011

not working

well, even when i pass parameters, or try to convert a javatype to normal string

it does not work


Friday, August 12, 2011

dynamic web interface programming visual studio

Hi,

i just started working on my web interface in visual studio
before, it was a vbscript (windows host script)

i had to  change the code a little to redefine all variables, some global, some local
the program is not object, so all is not local to every sub

first problem:
as i use internet as interface, in vb, you cannot access the web button and states as easily as in vbscript
here is the code i am working on at this moment:


        Dim str01 As String
        Dim str02 As String
        Dim str03 As String
        Dim HTMLEle As Object
        'For Each HTMLEle In OIE.document.frames("left").document.getElementsByTagName("input")
        For I = 0 To 1000000
            For Each HTMLEle In flef.getElementsByTagName("input")
                str01 = LCase(HTMLEle.getAttribute("name"))
                str02 = LCase(HTMLEle.getAttribute("type"))
                Dim controlName As String = HTMLEle.GetAttribute("buttonlef").ToString
                str03 = LCase(HTMLEle.GetAttribute("Value"))
                System.Console.Write(str01 & "   ")
                System.Console.Write(str02 & "   ")
                System.Console.Write("value: " & str03 & "   ")
                System.Console.Write(vbCrLf)
                For i2 = 0 To 50000000

                Next

            Next
        Next I

with this i can access the internet explorer objects but i need the state of them as the internet explorer buttons control my program

the interface is divided in 3 parts:
control (left frame)
input (middle frame, actually in top)
output (bottom frame)

as i use internet explorer as interface i don't need to have a report management, i simply added dynamically a java print button on the frame i wanna print

more to come!

it's been long since i programmed some vb in visual studio, i am eager to see what i can do with it and a dynamic interface