Author Topic: web navigation O2  (Read 1084 times)

0 Members and 1 Guest are viewing this topic.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 698
    • Charles Pegge
Re: web navigation O2
« Reply #30 on: July 12, 2019, 11:09:35 PM »
There are likely to be limits on the internal read-buffer. So it may take a few ReadFile calls to get the complete web page/file. Perhaps I'm being over-cautious :)

No buffer limits:
Code: [Select]
extern lib "wininet.dll"

! InternetOpenA
! InternetOpenUrlA
! InternetCloseHandle
! InternetReadFile

string buf=nuls 0x20000 '128k
string tbuf
string url="https://www.oxygenbasic.org/index.html"
int cbytes
sys hInternet
sys hFile
int c
hInternet = InternetOpenA( "o2demo",0,0,0,0 )
hFile = InternetOpenUrlA( hInternet,url,0,0,0,0 )
do
  cbytes=0
  InternetReadFile( hFile,buf,len(buf),@cbytes )
  if cbytes
    tbuf+=left(buf,cbytes)
    c++
  else
    exit do
  endif
loop
InternetCloseHandle( hFile )
InternetCloseHandle( hInternet )
'print tbuf
putfile( "t.txt",tbuf )
'print c 'readfile loops

improved loop!
« Last Edit: July 12, 2019, 11:43:23 PM by Charles Pegge »

Offline Eduardo Jorge

  • Jr. Member
  • **
  • Posts: 69
Re: web navigation O2
« Reply #31 on: July 12, 2019, 11:34:18 PM »
Yes, it worked perfectly
Is it advisable to use the other for those of limited size or can this be used for everyone without problems?
It's amazing how there are so many different tools and ways of doing the same task
only years of dedication and a mind capable of assimilating all this

Many thanks Charles

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 698
    • Charles Pegge
Re: web navigation O2
« Reply #32 on: July 12, 2019, 11:47:41 PM »
It will work for all sizes, and it is optimizable.

I've also improved the loop.

Offline Eduardo Jorge

  • Jr. Member
  • **
  • Posts: 69
Re: web navigation O2
« Reply #33 on: July 13, 2019, 12:20:34 AM »
cool
can I use the same method to download zip files?
may be interesting a ".inc" for use on the web, after all today everything is captured and sent to the big network
"The internet here is horrible today"

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 698
    • Charles Pegge
Re: web navigation O2
« Reply #34 on: July 13, 2019, 04:48:03 AM »
It should work. Both http and ftp protocols are supported, (ftp files could be of any type).
« Last Edit: July 13, 2019, 04:50:20 AM by Charles Pegge »

Offline Eduardo Jorge

  • Jr. Member
  • **
  • Posts: 69
Re: web navigation O2
« Reply #35 on: July 13, 2019, 11:08:24 PM »
Thanks, Charles.
I can probably do things by myself, I'm off here looking for examples and doing tests.
most changes little of how I do in vba
« Last Edit: July 13, 2019, 11:10:48 PM by Eduardo Jorge »

Offline Eduardo Jorge

  • Jr. Member
  • **
  • Posts: 69
Re: web navigation O2
« Reply #36 on: July 13, 2019, 11:58:48 PM »
Charles, it might be a good idea to put a separate folder in github to put new examples and .inc files, so you could organize better, besides having a range of examples located without having to change the zip of O2

Offline Chris Chancellor

  • Sr. Member
  • ****
  • Posts: 320
Re: web navigation O2
« Reply #37 on: July 14, 2019, 07:04:10 PM »
Hello Charles , Jose, Eduardo

i found the below code from PB about cursor browser

https://forum.powerbasic.com/forum/jose-s-corner/discussion/763266-big-browser-cursor

can this be converted to O2 ?

Code: [Select]
#Compile Exe
#Dim All
%Unicode = 1
%UseWebBrowser = 1            ' // Use the WebBrowser control
#Include Once "CWindow.inc"   ' // CWindow class
%IDC_WebBrowser = 1001
Global hDlg, hBrowser, hCursor As Dword, OldProc&, pWindow As IWindow

Function PBMain
   Dialog New Pixels, 0, "WebBrowser", , , 800, 600, %WS_OverlappedWindow To hDlg
   pWindow = Class "CWindow"
   hBrowser = pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, "http://www.powerbasic.com",Nothing, 0, 0, 600,400)
   Dialog Show Modal hDlg, Call DlgProc
End Function

CallBack Function DlgProc() As Long
   Select Case CbMsg
      Case %WM_InitDialog
         hCursor = LoadImage (ByVal 0, "c:\windows\cursors\larrow.cur", %IMAGE_ICON, 125, 125, %LR_LOADFROMFILE)
         OldProc& = SetWindowLong(hBrowser, %GWL_WndProc, CodePtr(NewProc))  'subclass
      Case %WM_SetCursor
         SetCursor hCursor
         Function = 1
      Case %WM_Destroy
         SetWindowLong hBrowser, %GWL_WNDPROC, OldProc&   'un-subclass
  End Select
End Function

Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Select Case Msg
      Case %WM_SetCursor
         SetCursor hCursor
         Function = 1
         Exit Function
   End Select
   Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function




Offline Zlatko Vid

  • Newbie
  • *
  • Posts: 20
Re: web navigation O2
« Reply #38 on: July 15, 2019, 01:30:03 PM »
Yes it could be if you have
CWindow.inc from powerBasic translated to o2 inc.

Offline Eduardo Jorge

  • Jr. Member
  • **
  • Posts: 69
Re: web navigation O2
« Reply #39 on: July 15, 2019, 11:14:33 PM »
I consider that, more than adapting lines of code of the PB, it has to determine direct examples with the own O2
start with simple and commented examples
o2 is very versatile in its syntax, but it also seems to be its weakest link
passing from the vba to him
ReDim Arrayindice (100) the string, and was giving errors within parts of the code
ReDim string Arrayindice (100), and it worked
ReDim string Arrayindice (C), I do not understand why it is necessary to define string of a variable that had already been defined,
the biggest failure for me is wanting to lean on other platforms, O2 is already consistent to follow with his own legs, and define a proper authority

I also noticed that simple codigo that works perfectly in 32bit hangs in 64bit

Offline Eduardo Jorge

  • Jr. Member
  • **
  • Posts: 69
Re: web navigation O2
« Reply #40 on: July 16, 2019, 01:48:39 AM »
ainda apanhando para escrever algo


Code: [Select]
extern lib "wininet.dll"

! InternetOpenA
! InternetOpenUrlA
! InternetCloseHandle
! InternetReadFile

string buf=nuls 0x20000 '128k
string tbuf
string url="http://data.ny.gov/resource/d6yy-54nr.json"
int cbytes
sys hInternet
sys hFile
int c
hInternet = InternetOpenA( "o2demo",0,0,0,0 )
hFile = InternetOpenUrlA( hInternet,url,0,0,0,0 )
do
  cbytes=0
  InternetReadFile( hFile,buf,len(buf),@cbytes )
  if cbytes
    tbuf+=left(buf,cbytes)
    c++
  else
    exit do
  endif
loop
InternetCloseHandle( hFile )
InternetCloseHandle( hInternet )

string Saida
  Dim  Arraydados(4) as string
    Dim L As int, C As int, cc As int, tt As int, s as char,s2 as string
dim ch,ch2 as int
     tt = Len(tbuf)
     C = 1: L = 1
     For cc = 1 To tt
          s = Mid tbuf, cc, 1
          If s = chr(34) Then 'para as aspas (")
                If ch2 = 0 Then ch2 = 1 Else ch2 = 0
                GoTo PULA
          End If
          If ch2 = 0 Then
                If s = "," Then  C = C + 1: L = 1: GoTo PULA
                If s = ":" Then  L = 2:  GoTo PULA
       'If s = "{" Or s = "}" Then  GoTo PULA
         End If

If s = "{"  Then GoTo PULA
        'If s = chr(13) Then 'Enter
If  s = "}" Then
        s = Mid tbuf, cc+1, 1
saida=saida & left(Arraydados(1),10) & " ; " & Arraydados(2) & " ; " & Arraydados(3) & s
Arraydados(1)="" : Arraydados(2)="" : Arraydados(3)=""
c=0: GoTo PULA
end if
If s = "[" or s = "]" Then  GoTo PULA
If L = 2 Then
Arraydados(C) =  Arraydados(C) & s
        End If
PULA:
     Next

putfile( "t2.txt",saida )
putfile( "t1.txt",tbuf )

« Last Edit: July 16, 2019, 01:56:10 AM by Eduardo Jorge »

Offline Zlatko Vid

  • Newbie
  • *
  • Posts: 20
Re: web navigation O2
« Reply #41 on: July 23, 2019, 07:11:40 PM »
ainda apanhando para escrever algo

he he ...i don't get it..
EDuardo you must learn o2 code
there is no just copy from other dialect...