Results 1 to 6 of 6

Thread: [2005] how can i loop this text..

  1. #1

    Thread Starter
    Addicted Member Gameunreal's Avatar
    Join Date
    Jun 2006
    Location
    gone fishing
    Posts
    249

    [2005] how can i loop this text..

    hi all again.
    when i am loading my favourites(in my browser) i do the method below.
    is there a loop that will do all of the below code?

    --- in the form the button order is button1,2,5,3,4,7, that is why the order is the way it is----------------
    <code>
    Private Sub favourites_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim fileExists As Boolean
    fileExists = My.Computer.FileSystem.FileExists("c:\Program files\WeBrowz\favourite1.text")
    If fileExists = True Then
    Dim fileContents1 As String
    fileContents1 = My.Computer.FileSystem.ReadAllText("c:\Program files\WeBrowz\favourite1.text")
    Button1.Text = fileContents1
    Dim fileContents2 As String
    fileContents2 = My.Computer.FileSystem.ReadAllText("c:\Program files\WeBrowz\favourite2.text")
    Button2.Text = fileContents2
    Dim fileContents3 As String
    fileContents3 = My.Computer.FileSystem.ReadAllText("c:\Program files\WeBrowz\favourite3.text")
    Button5.Text = fileContents3
    Dim fileContents4 As String
    fileContents4 = My.Computer.FileSystem.ReadAllText("c:\Program files\WeBrowz\favourite4.text")
    Button3.Text = fileContents4
    Dim fileContents5 As String
    fileContents5 = My.Computer.FileSystem.ReadAllText("c:\Program files\WeBrowz\favourite5.text")
    Button4.Text = fileContents5
    Dim fileContents6 As String
    fileContents6 = My.Computer.FileSystem.ReadAllText("c:\Program files\WeBrowz\favourite6.text")
    Button7.Text = fileContents6
    End If
    <Code>

    cheers,
    patrick
    -=PATRICK=-
    Using Visual Basic .NET 2005


    If you found a post useful then please Rate it!



    Hidden DOS secret: add BUGS=OFF to your CONFIG.SYS
    A program is a device used to convert data into error messages.
    Programmer's Drinking Song: 99 programming bugs in the code/99 programing bugs/Fix one bug/compile it again/now there's 100 bugs in the code! (repeat until bugs==0)
    All wiyht. Rho sritched mg kegtops awound?

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [2005] how can i loop this text..

    1) "If fileExists = True Then" takes more code, and more time to run, than "If fileExists Then"

    2) Dim all your strings at the top. It's cleaner looking code, and Dim statements are executed unconditionally.

    3) If you define your string as an array of string, you can build the file name based on the loop counter and your string is ArrayName(<loop counter>).
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3
    Lively Member
    Join Date
    Jun 2006
    Location
    City of Angles. Right Angles.
    Posts
    110

    Re: [2005] how can i loop this text..

    If you are linking buttons to files, I would load them dynamically at runtime instead of having a set number of buttons already on the form. Then just set the Tag property of each dynamically loaded button to contain the contents of the files. Also, I'd use a For Each loop on IO.Directory.GetFiles to dynamically load the favorites.

    Or actually, if you are making a browser favorites list, I would try to go with a single formatted document that contains all the favorites and then just load the single file. It'd probably be faster than opening and closing a lot of files on the hard drive, if you just open 1 file and loop through it line by line.

    And a side note, if you want to post code, use the [vbcode] tags so your code is easy to read in the forums.

  4. #4

    Thread Starter
    Addicted Member Gameunreal's Avatar
    Join Date
    Jun 2006
    Location
    gone fishing
    Posts
    249

    Re: [2005] how can i loop this text..

    Quote Originally Posted by supertotallyawesome

    Or actually, if you are making a browser favorites list, I would try to go with a single formatted document that contains all the favorites and then just load the single file.

    how do i do that? i thought that it was possible but i didnt know how to do it. if you want check out my program it is here
    http://www.vbforums.com/showthread.php?t=412859

    cheers
    patrick
    -=PATRICK=-
    Using Visual Basic .NET 2005


    If you found a post useful then please Rate it!



    Hidden DOS secret: add BUGS=OFF to your CONFIG.SYS
    A program is a device used to convert data into error messages.
    Programmer's Drinking Song: 99 programming bugs in the code/99 programing bugs/Fix one bug/compile it again/now there's 100 bugs in the code! (repeat until bugs==0)
    All wiyht. Rho sritched mg kegtops awound?

  5. #5
    Lively Member
    Join Date
    Jun 2006
    Location
    City of Angles. Right Angles.
    Posts
    110

    Re: [2005] how can i loop this text..

    Quote Originally Posted by Gameunreal
    how do i do that? i thought that it was possible but i didnt know how to do it. if you want check out my program it is here
    http://www.vbforums.com/showthread.php?t=412859

    cheers
    patrick
    Just do a really simple formatted file named something like "favorites.txt":
    Code:
    Website Title|http://www.website.com
    Super Cool Site|http://www.supercool.com
    Google|http://www.google.com
    and to read it, use a StreamReader or TextReader to read the file in:
    VB Code:
    1. Dim Temp As String TempA() As String
    2. Dim sr As New StreamReader("favorites.txt")
    3. Do While sr.Peek <> -1
    4.   Temp = sr.ReadLine()
    5.   TempA = Temp.Split("|")
    6.   ' here is where you would create the dynamic control
    7.   ' whether it be a button or a menu item, then
    8.   YourDynamicItem.Text = TempA(0)
    9.   YourDynamicItem.Tag = TempA(1)
    10. Loop

    And just so you know, your zip file is missing a lot of image files in the resource folder. I had to create a bunch of fake ones to coerce the program into compiling.

  6. #6
    Hyperactive Member sheikh78's Avatar
    Join Date
    Apr 2006
    Location
    C:/
    Posts
    423

    Re: [2005] how can i loop this text..

    Should have just debugged it, or downloaded mine: http://www.freewebs.com/tegadigital/. And I'm not saying mine is better but just saying if you wanted to try it out go ahead....I'm uploading a better version over the weekend.
    "Imagination is more important than knowledge" - Albert Einstein, born on March 14th 1879.
    Can't find it here on VBForums? Go to the CodeProject. MSDN is your friend . I have such a bad website, my friend decided it would be funny to change the template and he moderates the site for me: visit my site!

    "Thinking of you, wherever you are
    We pray for our sorrows to end, and hope that our hearts will blend.
    Now I will step forward to realize this wish.
    And who knows, starting a new journey may not be so hard…
    Or maybe it has already begun.
    There are many worlds, but they share the same sky
    one sky, one destiny..."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width