• Welcome to Jose's Read Only Forum 2023.
 

web navigation O2

Started by Eduardo Jorge, June 28, 2019, 06:48:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

#30
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:

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!

Eduardo Jorge

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

Charles Pegge

It will work for all sizes, and it is optimizable.

I've also improved the loop.

Eduardo Jorge

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"

Charles Pegge

#34
It should work. Both http and ftp protocols are supported, (ftp files could be of any type).

Eduardo Jorge

#35
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

Eduardo Jorge

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

Chris Chancellor

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 ?


#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





Zlatko Vid

Yes it could be if you have
CWindow.inc from powerBasic translated to o2 inc.

Eduardo Jorge

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

Eduardo Jorge

#40
ainda apanhando para escrever algo



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 )


Zlatko Vid

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...

Eduardo Jorge

#42
but what is the default of O2?
is the basic C standard?
As I said, O2's strongest point is its virtually free syntax, and it's also its weakest point.
In the case of "REDIM", note that it is accepted to declare variables with "DIM x AS LONG", not that I prefer to use this mode, but I hope that accepting a mode using dim is also suitable for REDIM, and the error appeared in another line. took longer to know where it was
I had commented before that I would prefer syntax blocks, to force the chosen syntax avoiding typos
to me, C's bad point is his "symbolism" {}; && ++! = ... I couldn't get used to it, I don't miss Gosub so much despite having certain uses,
but for me End if, Next .., is paramount to locate me in the logic of what I'm doing
Having so many ways to declare variables as I see it is only useful for reusing code, because writing something from scratch is the most important thing.

Zlatko Vid

The simpliest way to declare variables in 02 is
INT a,s,d,f,g,h
STRING q,w,e,r,t,z
FLOAT x,y,c,v,b

INT arr1[100] : STRING s[200] : FLOAT x[300]

as you can see there is no need to use DIM

Eduardo Jorge

Yes I know,
as I said the possibility of so many methods is only useful for reusing lines of code without having to rewrite
but this feat has to be consistent, or at least show syntax error on the right line and not elsewhere
I wouldn't mind if O2 had only one method of declaring variables that would just force manually declaring without being able to paste ready-made codes
would even be good because it would make O2 independent of other languages and make it easier for Charles