Results 1 to 2 of 2

Thread: [RESOLVED] [2005] BinaryWriter question

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Resolved [RESOLVED] [2005] BinaryWriter question

    I've never used it before and now need to due to the amount of data that needs to be outputted takes too long from excel. I was just wondering if there is a quick way to say output the entire contents of a List (of Single). (I know it doesn't matter what the variable is - was just to clarify).

    Just as an example: Here is a simple example of what I'm sort of dealing with:

    VB Code:
    1. Private Structure ImageData
    2.         Dim XCoordinates As List(Of Integer)
    3.         Dim YCoordinates As List(Of Integer)
    4.     End Structure
    5.  
    6.     Dim Cases(4) As ImageData
    7.  
    8.  
    9.         Dim myRnd As New Random
    10.         Dim myCountX As Integer = 0
    11.  
    12.         For i As Integer = 0 To 4   'Populate with dummy data
    13.             Cases(i).XCoordinates = New List(Of Integer)
    14.             Cases(i).YCoordinates = New List(Of Integer)
    15.             myCountX = myRnd.Next(150, 400)
    16.             For x As Integer = 0 To myCountX
    17.                 Cases(i).XCoordinates.Add(myRnd.Next(20, 150))
    18.                 Cases(i).YCoordinates.Add(myRnd.Next(20, 150))
    19.             Next
    20.         Next  
    21.  
    22.  Dim myBinary As New IO.BinaryWriter(System.IO.File.Open("D:\My Documents\binary.txt", IO.FileMode.Create))
    23.  
    24. 'I have to write the Count and store that info too?
    25. 'Do I just add a loop here and output the binary data? Or is there a better way to output all the data?
    26. 'i.e. Cases(0).XCoordinates.Output All Data   (or something)
    27. myCountX = Cases(k).XCoordinates.Count
    Last edited by stimbo; Feb 7th, 2007 at 07:01 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [RESOLVED] [2005] BinaryWriter question

    try this. You will probably need to play around with it to get it to fit your needs, but you can get the idea.
    VB Code:
    1. Dim myBinary As New IO.BinaryWriter(System.IO.File.Open("D:\My Documents\binary.txt", IO.FileMode.Create))
    2.         Dim str As IO.Stream = myBinary.BaseStream
    3.         str.Write(Cases(0).XCoordinates.ToArray, 0, Cases(0).XCoordinates.Count - 1)
    4.         myBinary.Flush()
    5.         myBinary.Close()
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

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