Weird behavior with streamreader. How do I fix?

I have a ~ 1 GB text file containing a line of text followed by 100 million lines each containing a prime number followed by a last line with a zero. I've used (read with streamreader) this file in several VB (2010) programs without problem.  This morning,
I tried writing a simple program which would tell me what the greatest gap is between any two of the primes in the file. After I debugged (due to some silly logic errors which shouldn't be relevant) the program's behavior changed. It was reading the file but
now all it does is find a single line, rather than 100 million lines AND the single line is the filename rather that what the first text line actually is.
I open the file in Form1_Load sub as follows:
Dim fr As System.IO.Streamreader
Dim s As string
fr = New System.IO.Streamreader("filename.txt")
s = fr.readline
and from that point I ran into problems when I used a RichTextBox to display (via .AppendText) the output using a While fr.peek >0 loop. I've previously run into the problem that writing to textboxes and richtextboxes take enormous amounts of time to
run (hours, if not days)  while the same logic but directed to an output file runs in a couple of minutes. So, I closed the program (forced closed) and rewrote output to a streamwriter to a new filename. Since then, I can't get any real output from the
file, even when I change output back to a textbox. The text file name is Primes1E9.txt and the first line is:> This file contains 102886524 primes, the largest is 2099999983 < and the second line is 2 then 3, 5, 7, etc up to 2099999983 followed by a
line containing a 0. Here is the problem: when I attempt to read past the first line, the program causes an error (I can catch error in catch try block) or if I don't use a catch block then I get an unhandled error. AND the first readline tells me that the
first line is Primes1e9.txt, which it is NOT. (again, that is the filename, not the first line of text). I've tried closing VS2010, shutting off my PC and rebooting, and deleting and replacing the copy of the text file, all to no avail: I continue to get the
erroneous behavior. Windows explorer confirms the first 20,000 or so lines are correct in the textfile, but my VB2010 program isn't seeing it correctly for some reason. Any ideas?
I use VS2010 on Win7 (64bit), files are on my E: drive (E:\<root> , specifically) with executables in the usual subdirectory (bin\debug).
David E. Nalepa

Hi
The code below took 144 seconds on my system to read and fill a similar amount of data to the RTB.
' Form1 with RichTextBox1
Option Strict On
Option Infer Off
Option Explicit On
Public Class Form1
Dim sw As New Stopwatch
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
' WriteDummyData()
sw.Start()
FillRTB()
sw.Stop()
Me.RichTextBox1.AppendText("Time: " & sw.ElapsedMilliseconds.ToString & "ms" & "(" & sw.ElapsedMilliseconds \ 1000 & "sec)")
' on my system it took 144 seconds to fill the RTB
End Sub
Private Sub FillRTB()
Me.RichTextBox1.LoadFile(Application.StartupPath & "\Data\MyFile.txt", RichTextBoxStreamType.PlainText)
End Sub
Public Sub WriteDummyData()
' this created approx 1GB data text file
Dim fn As String = Application.StartupPath & "\Data\MyFile.txt"
Dim pp As String = My.Computer.FileSystem.GetParentPath(fn)
If IO.Directory.Exists(pp) Then
Using sr As IO.StreamWriter = New IO.StreamWriter(fn, False)
For r As Integer = 1 To 100000000
sr.WriteLine(r.ToString)
Next
End Using
Else
My.Computer.FileSystem.CreateDirectory(pp)
WriteDummyData()
End If
End Sub
End Class
Regards Les, Livingston, Scotland

Similar Messages

  • During the io 5 update process, my iphone 3gs froze and now will shut off and turn on by itself, and will not allow me to unlock the phone or do anything with it. how do i fix this?

    during the io 5 update process, my iphone 3gs froze and now will shut off and turn on by itself, and will not allow me to unlock the phone or do anything with it. how do i fix this?

    Follow the instructions here > http://support.apple.com/kb/HT1808
    You may need to try a few times to get it to work

  • I have a ipod and it needs to be activated, but my brother used it and he gave it back to me and moved away i cant get in contact with him how do i fix it ?

    i have a ipod and it needs to be activated, but my brother used it and he gave it back to me and moved away i cant get in contact with him how do i fix it ?

    You are running into
    Find My iPhone Activation Lock
    Can yo get your brother to do this:
    Find My iPhone Activation Lock: Removing a device from a previous owner’s account
    Are you the original purchaser and have proof of purchase? If so them Apple can help.
    Apple - Support - iTunes - Contact Us

  • I suddenly cope with latency, how can I fix this?

    I suddenly cope with latency, how can I fix this?

    The Gift Card can only be Redeemed in the Country of issue...

  • When i restore my phone it comes up with error1015 how do i fix that?

    when i restore my phone it comes up with error1015 how do i fix that?

    Brand Thunder software isn't viewed very favorably around here, due to it including "extras" such as you are seeing.

  • When I open my itunes it shows me two sides one is iTunesU and the other side is Podcasts and I can't connect with iTunes.How can I fix it

    When I open my itunes it shows me two sides one is iTunesU and the other side is Podcasts and I can't connect with iTunes.How can I fix it?

    Hi emzigal,
    Thank you for using Apple Support Communities. 
    Take a look at the following article to make sure that you are not missing any steps necessary for downloading past purchases. 
    Download past purchases - Apple Support
    Cheers,
    Jeff D. 

  • TLF 2/2.1/3 Weird behavior with floating graphics?

    Hi guys,
    I'm working on a chat application running on RED5 / AS3 and I'm struggling to get my client "UI" working perfectly.
    My problem is related to the TL Framework, on every version available.
    Basicly, I want to display a picture ( for user messages ) and icons ( for notifications ) on the left side of my lines, like this :
    So, I'v been messing around with "float=start", "float=left" and such, but i'm always encountering weird behaviors whenever I scroll or resize my containerController. It's quite easy to reproduce with the following code :
    public class Main extends Sprite
              private var controller:ContainerController;
              public function Main():void
                        if (stage) init();
                        else addEventListener(Event.ADDED_TO_STAGE, init);
              private function init(e:Event = null):void
                        stage.scaleMode = StageScaleMode.NO_SCALE;
                        stage.align = StageAlign.TOP_LEFT;
                        removeEventListener(Event.ADDED_TO_STAGE, init);
                        var holder:Sprite = new Sprite();
                        addChild( holder );
                        var tFlow:TextFlow = new TextFlow();
                        for ( var i:int = 0; i < 50; i++ )
                             tFlow.addChild( createLine() );
                        controller = new ContainerController( holder, 400, stage.stageHeight  );
                        tFlow.flowComposer.addController( controller );
                        tFlow.flowComposer.updateAllControllers();
                        stage.addEventListener( Event.RESIZE, resizeController );
              private function resizeController( e:Event ):void
                        controller.setCompositionSize( 400, stage.stageHeight );
                        controller.textFlow.flowComposer.updateAllControllers();
              public function createLine( ):DivElement
                        var d:DivElement;
                        var p:ParagraphElement;
                        var im:InlineGraphicElement = new InlineGraphicElement();
                        im.source = new Bitmap( new BitmapData( 16, 16, true, 0x30FF0000 ) ); // 0x30 Alpha
                        im.float = "left";
                        d = new DivElement();
                        d.clearFloats = "both";
                        p = new ParagraphElement();
                        d.addChild( p );
                        p.addChild( im );
                        return d;
    Basicly, I'm stacking 50 transparent "floating" elements. It works fine most of time, but if I randomly resize my Flash Player Window, I can get the first "invisible" element to overlap the last "visible" :
    It seems to be happening right when the last "floating" element should disappear. Instead, it gets "over" the previous one. It happens upon container resize and scrolls. I'v encountered this issue on lastest 2, 2.1 and 3 TLF builds.
    Beside the visual "bug", it also screws up my container.getContentBounds().height calls - which can make scrolling "trembling", as the height gets reajusted.
    I'm running out of ideas about how to handle this. This bug appears whenever I use "floating" graphics and I can't think of any other way to display graphics on the left side of my chat-lines.
    Maybe someone ran into this very problem and figured out a way to make it work?
    Excuse my english, thanks in advance,
    Lionel.

    Thank you for your report. And I have found the root cause.
    In BaseCompose.as
    protected function composeFloat(elem:InlineGraphicElement, afterLine:Boolean):Boolean
    if (!floatFits && (_curParcel.fitAny || _curParcel.fitsInHeight(totalDepth, int(logicalFloatHeight))) && (!_curLine || _curLine.absoluteStart == floatPosition || afterLine))
                    floatFits = true;
    The condition of if is true, only when the weird behavior happens. We need to discuss about how to fix it.

  • I have been unable to sync my phone with itunes - how can I fix this?

    When I link into itunes, I am told that my phone is not registered.  I have had my phone for less than 6 months.  It worked through the itunes up until May and then I was unable to get it to connect to sync with itunes.  I am able to buy products but not share with my other devices.  How do I fix this?

    The actual error message reads :  This Iphone can non be used because the Apple mobile device sevice is not started.

  • My contact list does not always include a video icon so I can use FaceTime with wifi- how can i fix this

    my contact list does not always include a video icon so I can FaceTime with a contact- how can I fix this?

    Thanks so much for your reply but that won't help in my current situation. Maybe I didn't make it clear. The latest version of Quicktime as new as it sounds doesn't support screen recording on a powermac G5 Motorola chip with OS 10.5.8 which is the highest os I can go with that machine. If I can sync the two computers so I can get the application to record from my newer computer then I'm ok. I just don't have the recording application for audio that I'm using to demo for the website on the laptop as it's about 10,000 dollars. So, I have to use the older computer to do the audio presentation and try to get the newer computer synced to it so I can use the new version that works on snow leopard to record a screen shot that will hopefully appear on my laptop instead of the old machine. Hope that makes sense. It's a bit confusing but in a nutshell it's like this:
    1. I am a Pro Tools Instructor which is the state of the art application and recording device for audio and movie scoring and I have a new job where I make small snippets of tips using Pro Tools which I'd like to record with quicktime on screen as they happen
    2. the best version of Quicktime Pro available for the Power Mac, OS 10.5.8 will not do screen recording on it.
    3. I can use the Quicktime application from my newer laptop but I need to sync it to the old machine
    4. I'm hoping but I don't know, if I do this, that I can record Pro Tools in action from my new machine buy seeing it on this laptop screen and then recording it with the new quicktime.
    5. If I can sync the two computers, I'm hoping this can happen but I can't use my ethernet connection as I have it used to connect to my recording console and can't afford to buy anything new like an ethernet hub yo connect the two so I'm hoping that there's another way to connect them.
    I hope that makes sense and that possible you or someone else can help. Thanks so much! Scott

  • Weird behavior with Ctrl-Tab

    Dear members,
    (Forms 6i c/s)
    I have two tab canvases in one form. For each one, the first tab page is a master list, and the second one is a single-record detail block.
    I try to prevent the user from going to the second tab page if the list is empty, so I check the cursor-block in the When-Tab-Page-Changed trigger.
    It works fine when I use the mouse, but I get a different behavior with the Ctrl-Tab keys:
    In the first canvas, when WTPC trigger fires, the cursor-block is the list block, which is fine.
    But in the other canvas, the cursor-block is already the detail block as soon as the trigger fires.
    I don't understand where the difference comes from, and I don't really know where to search.
    Does anyone have a clue ?
    Thanks for your help.

    I don't, since my code has to be generic (it's the same for both canvases, and many more).
    And I can only get the name of a canvas from a block, not the name of a block from a canvas.
    That's why the cursor-block was the best solution.

  • Some weird behaviors with AD RMS

    I spotted some weird behaviors in my Windows 2012 RMS setup:
    1. When opening an expired encrypted document in Outlook 2011(Macbook), it shows "IRM cannot start because the system clock has been changed"
    2. Encrypted email can't be previewed if user uses Outlook in RDS server
    3. "Permission will expire within 60 days" although I set the expiration to tomorrow
    Can I know are they default behaviors? Or its due to my wrong configuration?
    Jason

    Hi lab77,
    As far as I know, Office 2010 can NOT use AD RMS client 2.x.
    http://msviennatechnoblog.wordpress.com/2013/08/22/ad-rms-1-0-2-0-2-1/
    http://blogs.technet.com/b/rms/archive/2013/06/06/office-2013-ad-rms-client-2-x-and-template-distribution.aspx
    More reference about AD RMS client 2.x deployment note:
    http://technet.microsoft.com/en-us/library/jj159267(v=ws.10)#BKMK_UsingTrustedServers
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Best regards,
    Greta Ge
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Weird Behavior with Macbook  pro and 30" screen

    When trying to iSync my phone via Bluetooth my Bluetooth mouse takes on strange sluggish behavior and makes it virtually unusable. At this point I’ll flip open the lid on the Mac book and use the track pad. When I shut the lid again I lose the picture on the big screen only for it to return some seconds later when I hit the Bluetooth keyboard the picture comes back then after 5-6 seconds disappears. It’s almost like it get’s stuck in some sort of hibernation cycle mode.. The only way to solve it , so far is to open the lid and restart then close the lid before it boots up again. The exact same thing happens if I unplug the power cord. Sometimes as happened today you open the lid and nothing , you actually have to flip the battery out for a moment then reboot as above.
    Providing I don’t open the lid or remove the power cord the computer and display work just fine
    I’m guessing there is something I can do in the settings, but I’m not sure what it is. But as you can imagine it’s a real pain
    Any pointers or ideas would be welcome and any explanation as to why the mouse goes nuts when I establish a connection between the computer and the phone( The sluggishness remains even after I’ve closed Bluetooth on the phone)
    Thanks
    Symon

    Dang, I assume correctly that it doesn't work as advertised for you? I have a MacBook 13.3-in with a Dell 20-in display attached as extended desktop and when I pan, I eventually can only zoom in to the bottom of the screen. I can only pan horizontally.
    Not as advertised at all I hope someone can fix that.

  • OBIEE Answers weird behavior with drilldown

    Hello,
    First and foremost, I apologize for my english, in case you have a hard time understanding my request. I'm also new to BI and OBIEE, to make things worse.
    So here's my problem: In OBIEE Answers/Criteria I make a simple request like :
    YEAR | QUARTER | MONTH_NAME | SALES_FACTS
    The result is working alright, but when I click on some MONTH_NAME, let's say April of 1998, it says :
    << The specified criteria didn't result in any data. This is often caused by applying filters that are too restrictive or that contain incorrect values. Please check your Request Filters and try again. The filters currently being applied are shown below. >>
    But that's impossible, because on the upper level there was data in SALES_FACTS. You could argue that something isn't right with my configuration etc.. but the weird thing is that not all months fail when i click to drilldown in it.
    For example, if I click on february of 1998, it works! But if I click on february of .. let's say 2006, it doesnt work !
    Another weird thing: If I make my request like this:
    YEAR | QUARTER | MONTH_NAME | DAY | SALES_FACTS
    It works for april 1998, and all the other requests that failed with drilldown. But there is one condition: I can't put a filter to show only april. For April's details to appear, there must be May and June
    Do you get it ....?

    I found the solution to my problem:
    1) First fix: There were blanks at the end of month names... That fixed the problem for several requests, but not all
    2) 2nd fix: In the time dimension I used month_number as the primary key, but it is month_name that is used for drilldown and is show to the user on the web interface...
    It was pretty simple, yes...

  • Lion: Weird behavior with two monitors.

    Intermittently, though very often, when a window is open in the secondary monitor (without menu bar), I cannot select items within the window — files (finder), emails (mail) or songs (iTunes). I cannot clear the problem except by moving the window to the primary monitor or  to another desktop.Then, everything is fine. The this behavior is isolated to the secondary monitor. Putting applications on separate desktops seems to avoid the problem.
    Here's the behavior in some detail. Clicking on the window header selects the window, but if I click inside it seems to deselect the window rather than select the item; the window appearance changes to the deselected appearance. Clicking on the header reselects the window; it can be moved, but it may not be possible to resize it and contents cannot be selected. Sometimes this happens in only part of the window. I can't select anything below half way down the window, or on the left side. In this mode, in list view, I can select an item in a list layout by clicking on the right side of the name entry line, but not on the icon. It is as if an invisible window is sitting in front. This is intermittent, soI am trying to figure out how precisely to reproduce it. It sometimes happens not while I am working but after ten minutes or so of non-use.
    Any ideas?

    I don't, since my code has to be generic (it's the same for both canvases, and many more).
    And I can only get the name of a canvas from a block, not the name of a block from a canvas.
    That's why the cursor-block was the best solution.

  • Iphone 4s Storage is full, Photo Stream is over full, cannot psynch with Itunes how do I fix this! Completely shutdown, apps on phone won't run correctly. HELP!!!!

    My Iphone 4S storage is full! Phone is not functioning correctly due to full storage.  Tried to backup and psych with Itunes, Back up worked (supposedly) but
    Itunes cannot psych due to being over capacity. Can't find how to edit files and delete stuff. 

    shut down "photo stream" , delete unused apps. export your photos from iPhone to PC and then delete all of your photos. But if you want to keep the photos on phone, maybe you will try some methods to compress the photo size in order to free up more storage.

Maybe you are looking for

  • Help! Hyperion Planning Dimension formula no longer works after name change

    Hi, I am having an issue with Hyperion Planning. I recently changed an account's dimension name from ASales & Property Taxes (D) to AProperty Taxes (D). However, the original name was used in a formula of another account. When I ran my refresh I got

  • A22m with windows 7

    Hello, I know what your thinking, but it actually runs better windows xp, except for one thing, the display drivers. same thing happens in vista. the drivers install successfully, but in device manager I get this error: Windows has stopped this devic

  • Heirarchical menus with previlliages and rolls

    I have following three departments IT, HR and Marketing And Manager of every department should be able to add users from their department and should also be able to assign forms or a set of forms to a new user from their department only and these for

  • RELATED in Calculated Column or Calcualted Field?

    Dear Team, 1] If I use the REALTED function to lookup a price in a Calculated Column like: RetailPrice =RELATED(dProducts[RetailPrice]) and there are only 30 different prices (unique values) in a total of 39,000 rows, here are my questions: Because t

  • Data1.cab on Disc1 reported by Symantec as a High Risk threat- Recommendations?

    I just logged in to our church's A/V presentation PC, which has Premiere Elements 9 installed. A few moments later, Norton Internet Security reported: ===== Unresolved Threats: Risks in compressed file "Data1.cab" Type: Compressed Risk: High (High St