Results 1 to 16 of 16

Thread: Assign an array to an open file dialog -- please help!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    27

    Assign an array to an open file dialog -- please help!

    How do you assign an array that will reference a streamreader, named ofdMain. I then need to be able to reference the first, second, and third lines in the array to be able to format them a certain way. Note that there is only one field with in each line and isn't seperated by a Delimiter.


    Sorry I can't be more specific but I'm new to VB.Net and any help would be welcome.

    Thanks,
    TheGenesi

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    ummm , I don't know what you mean .Can you explain a little more??

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Pirate
    ummm , I don't know what you mean .Can you explain a little more??
    Oh , I see your question is about StreamReader .I thought you are talking about BinaryReader .Anyways , I've not worked on that but I may give it a try !

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    27
    Ill try

    upon opening this file:

    From: Michael V. Ekedahl
    To: Course Technology
    Subject: Book
    Data
    Line one of message body.
    Line two of message body.

    I need to be able to format the first two lines and would like to do that before the text appears in the rich text box.

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by thegenesi
    Ill try

    upon opening this file:

    From: Michael V. Ekedahl
    To: Course Technology
    Subject: Book
    Data
    Line one of message body.
    Line two of message body.

    I need to be able to format the first two lines and would like to do that before the text appears in the rich text box.
    What do you mean by formating them ?? Can you just type example for this ?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    27
    Sure and I apprecite the help. The document, once formatted, will be displayed in the Rich Text Box as shown below.
    Attached Images Attached Images  

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    try this now :
    It reads line by line and then add to richtextbox also line by line
    I hope this what you are looking for :
    VB Code:
    1. Dim streamRd As StreamReader = File.OpenText("c:\test.txt")
    2.         Dim arry() As String
    3.  
    4.         arry(0) = streamRd.ReadLine()
    5.         arry(1) = streamRd.ReadLine()
    6.         arry(2) = streamRd.ReadLine()
    7.         RichText.Lines = arry
    8.         streamRd.Close()

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    27
    No, , i got this error
    Attached Images Attached Images  

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by thegenesi
    No, , i got this error
    Weird ??
    Make sure of the path file ???
    It worked for me

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    sorry ,
    VB Code:
    1. 'try to change this line :
    2. Dim arry() As String
    3.  
    4. 'with this one here :
    5. Dim arry(2) As String ' array length
    now it should work for you !

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    27
    The file location is correct....

    Here is the code:


    Imports System.IO


    Public Class frmMain
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim streamRd As StreamReader = File.OpenText("c:\test.txt")
    Dim arry() As String

    arry(0) = streamRd.ReadLine()
    arry(1) = streamRd.ReadLine()
    arry(2) = streamRd.ReadLine()
    rtbMain.Lines = arry
    streamRd.Close()

    End Sub
    End Class


    is my code.

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Pirate
    sorry ,
    VB Code:
    1. 'try to change this line :
    2. Dim arry() As String
    3.  
    4. 'with this one here :
    5. Dim arry(2) As String ' array length
    now it should work for you !
    Did you try the above code ??

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    27
    Thanks, that worked thoght I did something similar to that. I was hopeing to be able to open up a letter such as the one you saw, but perhaps with more or less lines so I declared it using a array with no initial value......to bad that wont work

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Ummm , what's that won't work ???

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    27
    Dim arry() As String

    as apposed to

    Dim arry(2) As String

    or is that where redim preserve comes in?

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by thegenesi
    Dim arry() As String

    as apposed to

    Dim arry(2) As String

    or is that where redim preserve comes in?
    Well ,
    Dim arry(2) As String ' here it declares number of elements the array can hold .

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