Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    .Celtics's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    148
    Reputation
    10
    Thanks
    5
    My Mood
    Crappy

    [Question]Reading in ftp by line

    I wanna read a site/ftp by line, for example, in the ftp, its
    1
    2
    3
    4
    So each line, will go to another Label.
    So if I have 4 labels, label one would be "1", label 2 would be "2" and so on..

    I already know how to read from a site/ftp using Blubbs code
    But I dont know how to read by line

    So can you guys help

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    Quote Originally Posted by .Celtics View Post
    I wanna read a site/ftp by line, for example, in the ftp, its


    So each line, will go to another Label.
    So if I have 4 labels, label one would be "1", label 2 would be "2" and so on..

    I already know how to read from a site/ftp using Blubbs code
    But I dont know how to read by line

    So can you guys help
    Code:
    Dim DownloadedData as string = DataDownloadedUsingBlubb'sCode...
    DownloadedData=DownloadedData.Trim
    Dim param() as string=DownloadedData.Split(chrw(10))
    If param.length>0 Then
    For i as integer =1 to param.length
    Dim lbl as object = Me.controls("Label" & i)
    lbl.text=param(i)
    Next
    End If
    Just replace DownloadedData variable's value with the value you retrieved from FTP, and you're good to go !!

  3. The Following User Says Thank You to Hassan For This Useful Post:

    .Celtics (10-31-2010)

  4. #3
    .Celtics's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    148
    Reputation
    10
    Thanks
    5
    My Mood
    Crappy
    Thanks for the fast reply

    What will I replace in "DataDownloadedUsingBlubb'sCode..."?
    I dont know what to replace it with

    And what would i add to continue to the next line after label 1?

    /

  5. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    Quote Originally Posted by .Celtics View Post
    Thanks for the fast reply

    What will I replace in "DataDownloadedUsingBlubb'sCode..."?
    I dont know what to replace it with

    And what would i add to continue to the next line after label 1?

    /
    Dude, you said in your original post that:

    I already know how to read from a site/ftp using Blubbs code.

    Just store that value in the variable "DownloadedData".

    And it will continue the loop automatically. If you want to add code each time a label is assigned a value, add between:

    [php]For i as integer =1 to param.length

    Next
    [/php]

  6. The Following User Says Thank You to Hassan For This Useful Post:

    .Celtics (10-31-2010)

  7. #5
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by Xscapism View Post

    Code:
    Dim DownloadedData as string = DataDownloadedUsingBlubb'sCode...
    DownloadedData=DownloadedData.Trim
    Dim param() as string=DownloadedData.Split(chrw(10))
    If param.length>0 Then
    For i as integer =1 to param.length
    Dim lbl as object = Me.controls("Label" & i)
    lbl.text=param(i)
    Next
    End If
    Just replace DownloadedData variable's value with the value you retrieved from FTP, and you're good to go !!
    That will work only if the file is saved as unicode O:

    If it's ASCII, then you'll need to split it with chr(10), not chrw(10).

  8. #6
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    Quote Originally Posted by freedompeace View Post
    That will work only if the file is saved as unicode O:

    If it's ASCII, then you'll need to split it with chr(10), not chrw(10).
    Nope. It will work in any case.

    The valid range for Chr is 0 through 255, and the valid range for ChrW is -32768 through 65535. So, ChrW supports Unicode as well as non-Unicode characters.

  9. #7
    .Celtics's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    148
    Reputation
    10
    Thanks
    5
    My Mood
    Crappy
    Theres an error:

    Object variable or With block variable not set.

    Do you know why?

  10. #8
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    Quote Originally Posted by .Celtics View Post
    Theres an error:

    Object variable or With block variable not set.

    Do you know why?
    Some code will help !!

    Edit: This is a know bug. Have a look here:

    https://support.microsof*****m/kb/316478

    But do post your code here too !!
    Last edited by Hassan; 11-01-2010 at 06:23 AM.

  11. #9
    .Celtics's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    148
    Reputation
    10
    Thanks
    5
    My Mood
    Crappy
    Im using this code of Blubb:
    [php]Private Const _test As String = "http:ftp/test.txt"

    Private Function loadPage(ByVal page As String)
    Dim req As WebRequest = WebRequest.Create(page)
    Dim resp As WebResponse = req.GetResponse()

    Dim s As Stream = resp.GetResponseStream()
    Dim sr As StreamReader = New StreamReader(s, Encoding.ASCII)
    Dim doc As String = sr.ReadToEnd()
    Return doc[/php]

    Then I just did this with your code
    [php] Dim DownloadedData As String = loadPage(_activator)
    DownloadedData = DownloadedData.Trim
    Dim param() As String = DownloadedData.Split(ChrW(10))
    If param.Length > 0 Then
    For i As Integer = 1 To param.Length
    Dim lbl As Object = Me.Controls("Label" & i)
    lbl.text = param(i)
    Next
    End If

    End Sub[/php]

    So did I do something wrong?

  12. #10
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    I'd stream the downloaded text and use a IO.Streamreader...easier IMO



  13. #11
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    Quote Originally Posted by .Celtics View Post
    Im using this code of Blubb:
    So did I do something wrong?
    Try this:

    [php]Private Const _test As String = "http:ftp/test.txt"

    Private Function loadPage(ByVal page As String)
    Dim req As WebRequest = WebRequest.Create(page)
    Dim resp As WebResponse = req.GetResponse()

    Dim s As Stream = resp.GetResponseStream()
    Dim sr As StreamReader = New StreamReader(s, Encoding.ASCII)
    Dim doc As String = sr.ReadToEnd()
    Return doc

    Dim DownloadedData As String = loadPage(_activator)
    DownloadedData = DownloadedData.Trim
    Dim param() As String = DownloadedData.Split(ChrW(10))
    If param.Length > 0 Then
    For i As Integer = 1 To param.Length
    Dim lbl As Object = Me.Controls("Label" & i)
    lbl.text = param(i)
    Next
    End If

    End Function[/php]

    You must close Function with "End Function"

  14. The Following User Says Thank You to Hassan For This Useful Post:

    .Celtics (11-02-2010)

  15. #12
    .Celtics's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    148
    Reputation
    10
    Thanks
    5
    My Mood
    Crappy
    @Blubb How?

    @Xscapism

    Sorry for the mistake in c/p pasting the code, there is already an End Function in the 1st code, and the 2nd code is in form load

    It has another erorr if i merge them

  16. #13
    Imported's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    142
    Reputation
    27
    Thanks
    47
    My Mood
    Relaxed
    To get the stream as blubb suggested, try something like this:

    [php]
    Private function GetPageStream(ByVal pageURL as string) as io.stream
    Dim webReq as Net.httpWebRequest = Directcast(net.webrequest.create(pageURL),net.http webrequest)
    Dim webResp as net.httpwebresponse = DirectCast(webReq.getresponse, net.httpwebresponse)
    Return webResp.getresponsestream
    End function
    [/php]

    Whew that took a long time to type. Noon iPhone typer = me

    Edit, I think this would be an easier method:
    [php]
    Using wc as new net.webclient
    Dim textArray() as string = wc.Downloadstring("yoursite here").split(VbNewLine)
    For I as integer = 0 to textArray.count -1
    DirectCast(Me.controls("Label" & (I+1).tostring, label).Text = textArray(I)
    Next [/php]
    Last edited by Imported; 11-01-2010 at 07:32 AM.

  17. The Following 2 Users Say Thank You to Imported For This Useful Post:

    .Celtics (11-02-2010),Hassan (11-01-2010)

  18. #14
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    Quote Originally Posted by Imported View Post
    To get the stream as blubb suggested, try something like this:

    [php]
    Private function GetPageStream(ByVal pageURL as string) as io.stream
    Dim webReq as Net.httpWebRequest = Directcast(net.webrequest.create(pageURL),net.http webrequest)
    Dim webResp as net.httpwebresponse = DirectCast(webReq.getresponse, net.httpwebresponse)
    Return webResp.getresponsestream
    End function
    [/php]Whew that took a long time to type. Noon iPhone typer = me

    Edit, I think this would be an easier method:
    [php]
    Using wc as new net.webclient
    Dim textArray() as string = wc.Downloadstring("yoursite here").split(VbNewLine)
    For I as integer = 0 to textArray.count -1
    DirectCast(Me.controls("Label" & (I+1).tostring, label).Text = textArray(I)
    Next [/php]
    GJ. I prefer the second one !! But use DirectCast only when other methods fail. (Optimization xD)

  19. The Following User Says Thank You to Hassan For This Useful Post:

    .Celtics (11-02-2010)

  20. #15
    Imported's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    142
    Reputation
    27
    Thanks
    47
    My Mood
    Relaxed
    Turn option strict on choob.

    Properly, the first one should just use net.httpwebrequest.create to avoid any casting at all haha

  21. The Following User Says Thank You to Imported For This Useful Post:

    .Celtics (11-02-2010)

Page 1 of 2 12 LastLast

Similar Threads

  1. [READ] Any Questions? [READ]
    By Trunky in forum Combat Arms Help
    Replies: 8
    Last Post: 09-18-2009, 07:46 AM
  2. Super human Question READ
    By sukhans in forum Visual Basic Programming
    Replies: 0
    Last Post: 05-12-2009, 07:39 PM
  3. [Question] *Read*
    By DoubleDutch in forum MapleStory Hacks, Cheats & Trainers
    Replies: 0
    Last Post: 10-13-2007, 12:12 PM
  4. [Tutorial] Reading from the CMD line
    By shercipher in forum C++/C Programming
    Replies: 7
    Last Post: 04-04-2006, 12:49 PM