data written multiple times
data written multiple times
data written multiple times
data written multiple times
data written multiple times
data written multiple times data written multiple times data written multiple times data written multiple times data written multiple times data written multiple times data written multiple times data written multiple times
data written multiple times data written multiple times
data written multiple times
Go Back  Xtreme Visual Basic Talk > > > data written multiple times


Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2017, 01:35 PM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 289
Default data written multiple times


Hi,
I have decided to do without my previous idea of using a text database, and instead read from the .txt file, use the split function and then write to a DB table.
The process works wonderfully apart from one thing - each line of the text file does get written to the DB table, but several times, instead of just once!
Here's the relevant code with notes:
1) I had to put the 'on error' in because even though the data was getting written, I would get a 'subscript out of range' notice at the end.
2) To distinguish the testing routine (which is what this is) from the already-existing records in the DB I set the entry that gets sent to the 'star' field as "blah". Obviously if and when everything works properly this will be changed!
3) There are 16 members of the bits array.
4) longstring and bits have been previously dimmed, as well as the variables which get sent to the DB.
Code:
Open afile For Input As #1
Do While Not EOF(1)
On Error Resume Next
    Line Input #1, longstring
    bits = Split(longstring, "##")
    sname = bits(1)
    juldate = bits(3)
    ftr = bits(4)
    magni = bits(5)
    ccode = bits(6)
    If ccode = "  " Then ccode = "na"
    nts = bits(7)
    If nts = " 0 " Then nts = "na"
    comp1 = bits(10)
    comp2 = bits(12)
        If ftr = " 0 " Then
        estm = comp1 & ", " & comp2
        Else
        estm = "<" & comp1
        End If
    chartid = bits(14)
    Set dyn = thisDb.OpenRecordset("cumobs", dbOpenTable)
            dyn.AddNew
            dyn("star") = "blah"
            dyn("obsdate") = juldate
            dyn("magnitude") = magni
            dyn("obscode") = ccode
            dyn("notes") = nts
            dyn("estimate") = estm
            dyn("chart") = chartid
            dyn.Update
            
Loop
        Close #1
        Set Ws = Nothing
        Set thisDb = Nothing
        Set dyn = Nothing
So, why is the data indeed being written, but multiple times? Thanks for any assistance!
Reply With Quote
  #2  
Old 07-21-2017, 08:12 PM
Kluz's Avatar
Kluzdata written multiple times Kluz is offline
Sapience.Aquire

Super Moderator
* Expert *
 
Join Date: Oct 2003
Location: Lake Bluff, Ill., U.S.
Posts: 3,445
Default

I'm not sure that this is the cause, but the line:
Code:
Set dyn = thisDb.OpenRecordset("cumobs", dbOpenTable)
should not be within the loop. You should also close the recordset object after the end of the loop.
__________________
No the other right mouse click
Reply With Quote
  #3  
Old 07-22-2017, 11:08 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 289
Default

Hi,
As you say, the line should be outside. So I did that, but still everything is getting written twice. The weird thing is, if I comment out the 'on error resume next', everything works perfectly but I now get the error message saying (for the last record) 'subscript out of range'!
OK - update...
Sorted! I was unwittingly calling the same routine twice. Put in an error trap for the out-of-range and everything is now working properly - and also a lot less for any prospective user to worry about.
Thanks for your guidance.

Last edited by starmanMike; 07-22-2017 at 12:14 PM.
Reply With Quote
Reply

Tags
nts, written, bits, ccode, line, data, ftr, input, error, longstring, text, table, comp2, comp1, times, file, estm, blah, array, previously, properly, changed, bits3, bits12, juldate


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
data written multiple times
data written multiple times
data written multiple times data written multiple times
data written multiple times
data written multiple times
data written multiple times data written multiple times data written multiple times data written multiple times data written multiple times data written multiple times data written multiple times
data written multiple times
data written multiple times
 
data written multiple times
data written multiple times
 
-->