Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[vbscript] CreateObject() servers name
#1
Hello,

I am trying the Antview ocx.
Is exists the servers name for the functions working vithr CreateObject() in vbscript ?
Set Document = CreateObject("AntViewAx.AntViewDocument", "?? cServerName ??")

With MSWinsock, I worked with :
Set winsock = Wscript.CreateObject("MSWinsock.Winsock", "winsock_")

Thanks for an answer.

Regards,
Bernard
Reply
#2
Hello Bernard,

Thank you for your question.
Interesting to try it with wscript, might give that a shot in a bit myself.

The servername should be empty as the ActiveX is installed on the local machine.

I notice that you are creating the document interface object. The document interface does not function standalone, you need to connect it to an AntView instance.
So you'd also need to create a AntViewAx.AntView

eg.
Something like:
Code:
Set Browser = CreateObject("AntViewAx.AntView","")

--
Wil
Reply
#3
(2023-01-10, 10:39:35)wila Wrote: Hello Bernard,

Thank you for your question.
Interesting to try it with wscript, might give that a shot in a bit myself.

The servername should be empty as the ActiveX is installed on the local machine.

I notice that you are creating the document interface object. The document interface does not function standalone, you need to connect it to an AntView instance.
So you'd also need to create a AntViewAx.AntView

eg.
Something like:
Code:
Set Browser = CreateObject("AntViewAx.AntView","")

--
Wil
Hello Wil,
Thanks for your answer.
I try this and something and I give you the result.
Regards,
Bernard.
Reply
#4
Bernard,

..and.. I just see that the wscript.CreateObject and vba's CreateObject have a difference in how they interpret the 2nd parameter.
See:
https://stackoverflow.com/questions/7873...eateobject

--
Wil
Reply
#5
(2023-01-10, 10:50:41)Bernard Mouille Wrote: Hello Wil,
Thanks for your answer.
I try this and something and I give you the result.
Regards,
Bernard.

Bernard,

I played a bit with it and wasn't successful.
Not sure yet, but I think that we're missing an application object to host the control on.
Eg. something like "AntViewAx.Application" ...

Similar like the internet explorer had and all the office products.

Perhaps you're more lucky, but for the moment it looks like we're missing something in order to be able to do this.
I have opened a ticket for this to look into.

That will take a bit of time though as there are a few other feature requests in the line before this one.
--
Wil
Reply
#6
(2023-01-10, 11:23:25)wila Wrote:
(2023-01-10, 10:50:41)Bernard Mouille Wrote: Hello Wil,
Thanks for your answer.
I try this and something and I give you the result.
Regards,
Bernard.

Bernard,

I played a bit with it and wasn't successful.
Not sure yet, but I think that we're missing an application object to host the control on.
Eg. something like "AntViewAx.Application" ...

Similar like the internet explorer had and all the office products.

Perhaps you're more lucky, but for the moment it looks like we're missing something in order to be able to do this.
I have opened a ticket for this to look into.

That will take a bit of time though as there are a few other feature requests in the line before this one.
--
Wil
Reply
#7
Thanks.
Reply
#8
Hello,

I have made a little code for that I want.

Antother question :
- It is an example to accept the cookies ?

Regards,
Bernard.

Code:

' Test de AntView ocx with VBScript.

' Defaults :
' 1 - Can not use the default webview2 folder ( CreateWebView() failed ).
' 2 - Error "violation memory" in line :
'    Set EdgeWebBrowser = Wscript.CreateObject( "AntViewAx.Antview", "EdgeWebBrowser_" )
'    but works.

' Using 2023-01-16 :
' - Windows 10 up to date.
' - AntWiew ocx last version.

option explicit

Const ct_cUrl = "https://www.cabinet-louis-reynaud.eu/index.php/clr-labs-3/" ' URL to use.

Public pu_cHtml : pu_cHtml = bv_DirBase() & "\_Result_html.txt"  ' TXT source file created.
Public pu_cPdf  : pu_cPdf  = bv_DirBase() & "\_Result_pdf.pdf"    ' PDF file created.

Public pu_nEvent ' Indicate when the event function is finish.
                ' 0 = In work.
                ' 1 = Finshed ok.
                ' 2 = Finished fail.

Dim Document          ' AntViewAx.AntViewDocument object.
Dim EdgeWebBrowser    ' AntViewAx.Antview object.
Dim i                  ' Count variable.

' Erase the old files.
bv_fErase( pu_cPdf  )
bv_fErase( pu_cHtml )

' Create a directory for the user datas, not works with the default folder.
bv_Makedir( bv_DirBase() & "\vb_UserDatas" )

' Error Violation memory, no exception.
On Error Resume Next
  Set EdgeWebBrowser = Wscript.CreateObject( "AntViewAx.Antview", "EdgeWebBrowser_" )
  If Err.Number <> 0 Then
      MsgBox( "Error = " & Err.Number & " Description = "  & Err.Description )
      Err.Clear
  End If
On Error GoTo 0

' CreateWebView() failed if use defaut directory.
EdgeWebBrowser.UserDataFolder = bv_DirBase() & "\vb_UserDatas"

EdgeWebBrowser.CreateWebView

For i = 1 to 60 Step 1
  if EdgeWebBrowser.WebViewCreated Then Exit For
  wscript.sleep 1000
Next

If not EdgeWebBrowser.WebViewCreated Then
  Set EdgeWebBrowser = Nothing
  MsgBox "WebViewCreated() fail !"
  wscript.Quit
End If

Set Document = Wscript.CreateObject( "AntViewAx.AntViewDocument", "Document_" )
Document.BrowserDispatch( EdgeWebBrowser.IDispatchPointer )

' Open the URL.
pu_nEvent = 0
EdgeWebBrowser.Navigate( ct_cUrl )
For i = 1 to 60 Step 1
  If pu_nEvent <> 0 Then Exit For
  wscript.sleep 1000
Next
If pu_nEvent <> 1 Then
  MsgBox "Navigate() fail !"
  EdgeWebBrowser.CloseBrowserProcess
  EdgeWebBrowser.CloseWebView
  Set EdgeWebBrowser = Nothing
  Set Document      = Nothing
  wscript.quit
End If

' Print to PDF.
pu_nEvent = 0
EdgeWebBrowser.PrintToPdf pu_cPdf, ""
For i = 1 to 60 Step 1
  If pu_nEvent <> 0 Then Exit For
  wscript.sleep 1000
Next

' Get HTML source.
pu_nEvent = 0
Document.RequestCurrentHtml()
For i = 1 to 60 Step 1
  If pu_nEvent <> 0 Then Exit For
  wscript.sleep 1000
Next

EdgeWebBrowser.CloseBrowserProcess
EdgeWebBrowser.CloseWebView
Set EdgeWebBrowser = Nothing
Set Document      = Nothing

MsgBox "End of script, look the created files."

' ***** Event functions *****

Sub Document_OnRequestCurrentHtml( cHtml )
  pu_nEvent = 1
  bv_MemoWrit pu_cHtml, cHtml
End Sub

Sub EdgeWebBrowser_OnNavigationCompleted( IsSuccess, WebErrorStatus, NavigationId )
  If IsSuccess Then
      pu_nEvent = 1
  Else
      pu_nEvent = 2
  End If
End Sub

Sub EdgeWebBrowser_OnPrintToPdfCompleted( HResult, IsSuccessful )
  If IsSuccessful Then
      pu_nEvent = 1
  Else
      pu_nEvent = 2
      MsgBox "OnPrintToPdfCompleted() fail, HResult = ] " & HResult
  End If
End Sub

' ***** Used tools *****

' Get the default directory.
Function bv_DirBase()
  bv_DirBase = Left( WScript.ScriptFullName, InStrRev( WScript.ScriptFullName, "\" ) )
End Function

' Erase a file.
Sub bv_fErase( cFile_bv )
  Dim oFso_bv
  Set oFso_bv = CreateObject( "Scripting.FileSystemObject" )
  If oFso_bv.FileExists( cFile_bv ) Then
      oFso_bv.DeleteFile cFile_bv
  End If
  Set oFso_bv = Nothing
End Sub

' Create a directory.
Sub bv_Makedir( cDir_bv )
  Dim oFso_bv
  Set oFso_bv = CreateObject( "Scripting.FileSystemObject" )
  If Not oFso_bv.FolderExists( cDir_bv ) Then
      oFso_bv.CreateFolder( cDir_bv )
  End If
  Set oFso_bv = Nothing
End Sub

' Write a string in a file.
Sub bv_MemoWrit( cFile_bv, cString_bv )
  Dim oFile_bv
  Dim oFso_bv
  Set oFso_bv = CreateObject( "Scripting.FileSystemObject" )
  If oFso_bv.FileExists( cFile_bv ) Then
      oFso_bv.DeleteFile cFile_bv
  End If
  Set oFile_bv = oFso_bv.OpenTextFile( cFile_bv, vbString, True )
  oFile_bv.Write cString_bv
  oFile_bv.Close
  Set oFso_bv = Nothing
End Sub
Reply
#9
Hi Bernard,

Are you using the latest AntView version (1.1.236) ?

I'm asking as I see this code:
Code:
EdgeWebBrowser.CreateWebView

For i = 1 to 60 Step 1
  if EdgeWebBrowser.WebViewCreated Then Exit For
  wscript.sleep 1000
Next
and also:
Code:
EdgeWebBrowser.Navigate( ct_cUrl )
For i = 1 to 60 Step 1
  If pu_nEvent <> 0 Then Exit For
  wscript.sleep 1000
Next

You should be able to use CreateWebViewSync and NavigateSync for those.

Document.RequestCurrentHtml also has a synchronous version: Document.RequestCurrentHtmlSync

I'm surprised to see that the sleep works in wscript as it doesn't in most other languages.

Re. Cookies.

At the moment the only way to access cookies is by injecting Javascript in the page and read them that way.
However I will look into that asap as WebView2 does expose functionality for managing cookies and we're still missing that in AntView.

--
Wil
Reply
#10
(2023-01-16, 13:38:04)wila Wrote: Hi Bernard,

Are you using the latest AntView version (1.1.236) ?

Yes, I use.

I'm asking as I see this code:
Code:
EdgeWebBrowser.CreateWebView

For i = 1 to 60 Step 1
  if EdgeWebBrowser.WebViewCreated Then Exit For
  wscript.sleep 1000
Next
and also:
Code:
EdgeWebBrowser.Navigate( ct_cUrl )
For i = 1 to 60 Step 1
  If pu_nEvent <> 0 Then Exit For
  wscript.sleep 1000
Next

You should be able to use CreateWebViewSync and NavigateSync for those.
Document.RequestCurrentHtml also has a synchronous version: Document.RequestCurrentHtmlSync

Thanks, I shall try this.

I'm surprised to see that the sleep works in wscript as it doesn't in most other languages.

I work with this for a long time.

Re. Cookies.

At the moment the only way to access cookies is by injecting Javascript in the page and read them that way.
However I will look into that asap as WebView2 does expose functionality for managing cookies and we're still missing that in AntView.

OK, to look...

--
Wil

Hello Wil,
Thanks for your answers.
My answers arent in you before post.
Like Vasile, I work in dBase and I try in VBScript to correct the not possible things with dBase.
Regards,
Bernard.
Reply
#11
Bernard,

Sorry if I'm not completely clear.

I know what you are using sleep for. What I meant to say is that it blocks the functionality in other languages when you try to use sleep for example on CreateWebView then WebView2 never gets created.
Looks like that that is no problem for you with wscript.

Hopefully though the synchronous alternatives work for you as this is the type of logic they are designed to replace/simplify.

re. Cookie manager.
Not just look Smile
It will be implemented, just can't give an exact timeline at the moment, but I will give it high priority.

--
Wil
Reply
#12
(2023-01-16, 14:13:30)wila Wrote: Bernard,

Sorry if I'm not completely clear.

I know what you are using sleep for. What I meant to say is that it blocks the functionality in other languages when you try to use sleep for example on CreateWebView then WebView2 never gets created.
Looks like that that is no problem for you with wscript.

Hopefully though the synchronous alternatives work for you as this is the type of logic they are designed to replace/simplify.

re. Cookie manager.
Not just look Smile
It will be implemented, just can't give an exact timeline at the moment, but I will give it high priority.

--
Wil

Wil,
Ok, thanks.
I continue my tests for look if all is ok for my application and my son's company by your licence.
Regards,
Bernard.
Reply
#13
(2023-01-16, 13:00:20)Bernard Mouille Wrote: Antother question :
- It is an example to accept the cookies ?

Hello Bernard,

The cookiemanager code was just completed and I am currently testing that.
Then I looked back at your question above and I now realize that it is not what you asked! (Oh dear)

Accepting cookies on a website is not something that has a single solution as every website can use their own cookie banner.
Looking at the URL you supplied above, the cookie banner that pops up can be clicked on via javascript.
The following snippet did it for me.
Code:
var button = document.getElementsByClassName("cmplz-accept")
button[0].click();

So basically identify the html object you want to click, followed by sending a click.

You can insert any javascript you want in a page rendered by AntView.
This is showcased in the examples that come with AntView.
For example in Visual Basic see the frmExchangeRatesDemo.frm demo where the RunAnonymousFunction method is showcased.

Another way would be by using ExecuteScript.

OTOH if you want to access and manipulate cookies on any page then I can get you that now too. Tongue 
But I guess that you won't need it, at least for now.

Hope this helps,
Wil
Reply
#14
(2023-02-01, 18:02:51)wila Wrote:
(2023-01-16, 13:00:20)Bernard Mouille Wrote: Antother question :
- It is an example to accept the cookies ?

Hello Bernard,

The cookiemanager code was just completed and I am currently testing that.
Then I looked back at your question above and I now realize that it is not what you asked! (Oh dear)

Accepting cookies on a website is not something that has a single solution as every website can use their own cookie banner.
Looking at the URL you supplied above, the cookie banner that pops up can be clicked on via javascript.
The following snippet did it for me.
Code:
var button = document.getElementsByClassName("cmplz-accept")
button[0].click();

So basically identify the html object you want to click, followed by sending a click.

You can insert any javascript you want in a page rendered by AntView.
This is showcased in the examples that come with AntView.
For example in Visual Basic see the frmExchangeRatesDemo.frm demo where the RunAnonymousFunction method is showcased.

Another way would be by using ExecuteScript.

OTOH if you want to access and manipulate cookies on any page then I can get you that now too. Tongue 
But I guess that you won't need it, at least for now.

Hope this helps,
Wil

Hello Wil,
Many thanks for the sample.
I look all this.
Regards,
Bernard.
Reply
#15
OK, let me know when you have more questions.

--
Wil
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)