IT NEWS PC REVUE PC FORUM FreeBSDInternet time: @014
Obsah fóra
Pravidlá  •  Kontakt  •  Prihlásenie  •  Registrácia

Slovenský hokej čaká na teba

Ukáž čo v tebe je a pomôž Slovensku vyhrať zlato v online hokejovej hre. www.hrajhokej.sk

Lacné ubytovanie pri Balatone

Ubytuj sa teraz až s 50% zľavou Akciové zľavy na viac ako 1000 ubytovaní szallasguru.sk

Zaregistruj sa!

Tvoj názor sa ráta a oplatí! Pridaj sa a vyhraj iPad. www.marketagent.com

Efektívna reklama s Etarget

PPC reklama = *účinná reklama.* Radi Vám poradíme! www.etarget.sk

Dostaň sa cez leto do formy.

10000 už stratili hmotnosť s Açaí na Slovensku. Môžete to urobiť tiež. www.janinblog.com

AKO OTVORIT SUBOR VO VB z nejakeho servera ?

Zaslať odpoveď
AutorSpráva
stevo_alex19
Užívateľ
Užívateľ

Založený: 16.03.2008
Príspevky: 9

PríspevokZaslal: St 28.05.08 18:58Odpovedať s citátomNávrat hore

Potrebujem nejake napady ako by slo aby som nacital napriklad tento subor.. www.mgng.eu/skuska/pocitace.txt vo visual basicu...

Alebo ak pouzivam WEBCONTROL, a otvorim pomocou neho stranku v programe... Ako zistim jej HTML kod ?

Vodpred VDAKA.
Zobraziť informácie o autoroviOdoslať súkromnú správu
Patkoo
Užívateľ
Užívateľ

Založený: 02.11.2008
Príspevky: 85

PríspevokZaslal: Ne 02.11.08 15:18Odpovedať s citátomNávrat hore

Visual Basic 6 sam o sebe neposkytuje funkciu na nacitanie textoveho suboru z internetu priamo, preto musis spravit pred tym niekolko krokov.

1.) Bud skusit spravit cez WebBrowser

2.) Stiahnut si ten subor a otvorit ho z HDD - tento ti ukazem


Nechcelo sa mi pisat celu funkciu na stiahntie suboru z netu, tak som si pozical funkciu z (http://www.devx.com/vb2themax/Tip/19203).

Vytvor si novy form na ktory vlozis Command1 a Text1.

Budeme chcet nacitat z internetu do Textboxu obsah suboru (http://www.google.com/robots.txt).


kód:

Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_FLAG_EXISTING_CONNECT = &H20000000

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
    (ByVal lpszAgent As String, ByVal dwAccessType As Long, _
    ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, _
    ByVal dwFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias _
    "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, _
    ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, _
    ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As _
    Long) As Integer
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As _
    Long, ByVal lpBuffer As String, ByVal dwNumberOfBytesToRead As Long, _
    lNumberOfBytesRead As Long) As Integer

' Download a file from Internet and save it to a local file
'
' it works with HTTP and FTP, but you must explicitly include
' the protocol name in the URL, as in
'    CopyURLToFile "http://www.vb2themax.com/default.asp", "C:\vb2themax.htm"

Sub CopyURLToFile(ByVal URL As String, ByVal FileName As String)
    Dim hInternetSession As Long
    Dim hUrl As Long
    Dim FileNum As Integer
    Dim ok As Boolean
    Dim NumberOfBytesRead As Long
    Dim Buffer As String
    Dim fileIsOpen As Boolean

    On Error GoTo ErrorHandler

    ' check obvious syntax errors
    If Len(URL) = 0 Or Len(FileName) = 0 Then Err.Raise 5

    ' open an Internet session, and retrieve its handle
    hInternetSession = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, _
        vbNullString, vbNullString, 0)
    If hInternetSession = 0 Then Err.Raise vbObjectError + 1000, , _
        "An error occurred calling InternetOpen function"

    ' open the file and retrieve its handle
    hUrl = InternetOpenUrl(hInternetSession, URL, vbNullString, 0, _
        INTERNET_FLAG_EXISTING_CONNECT, 0)
    If hUrl = 0 Then Err.Raise vbObjectError + 1000, , _
        "An error occurred calling InternetOpenUrl function"

    ' ensure that there is no local file
    On Error Resume Next
    Kill FileName

    On Error GoTo ErrorHandler
   
    ' open the local file
    FileNum = FreeFile
    Open FileName For Binary As FileNum
    fileIsOpen = True

    ' prepare the receiving buffer
    Buffer = Space(4096)
   
    Do
        ' read a chunk of the file - returns True if no error
        ok = InternetReadFile(hUrl, Buffer, Len(Buffer), NumberOfBytesRead)

        ' exit if error or no more data
        If NumberOfBytesRead = 0 Or Not ok Then Exit Do
       
        ' save the data to the local file
        Put #FileNum, , Left$(Buffer, NumberOfBytesRead)
    Loop
   
    ' flow into the error handler

ErrorHandler:
    ' close the local file, if necessary
    If fileIsOpen Then Close #FileNum
    ' close internet handles, if necessary
    If hUrl Then InternetCloseHandle hUrl
    If hInternetSession Then InternetCloseHandle hInternetSession
   
    ' report the error to the client, if there is one
    If Err Then Err.Raise Err.Number, , Err.Description
End Sub


Private Sub Command1_Click()
Dim FF As Integer
Dim Riadok As String
Dim Text_vystup As String

FF = FreeFile

CopyURLToFile "http://www.google.com/robots.txt", "data.dat"

Open "data.dat" For Input As FF

Text_vystup = Input(LOF(FF), #FF)
 
 Text1.Text = Text_vystup

End Sub
Zobraziť informácie o autoroviOdoslať súkromnú správu
Zobraziť príspevky z predchádzajúcich:    
Zaslať odpoveď
Nemôžete pridávať nové témy do tohto fóra.
Nemôžete odpovedať na témy v tomto fóre.
Nemôžete upravovať svoje príspevky v tomto fóre.
Nemôžete mazať svoje príspevky v tomto fóre.
Nemôžete hlasovať v tomto fóre.

Powered by phpBB 2.x.x © 2005 - 2012 PCforum, webhosting by WebSupport, edited by JanoF

SEO - optimalizácia pre vyhľadávače

Freebsd