|
|
As I thought the file has inconsistent spacing.
This extract is where the problem begins.
4282023M91.ASM ENS. VOLANT MOTEUR
4282024M1.PRT VOLANT D'INERTIE
1619032M1.PRT COURONNE DEMARREUR
4282010M1.PRT --
3786094M93.ASM ENS DEMARREUR ISKRA
3823621M94.PRT DEMARREUR ISKRA
Both 4282023M91.ASM and 4282010M1.PRT are at Child level (generation 1) but the number of spaces is 5 and 3.
When the dictionary is populated in GetGeneration() the assumption is that all Child level names will have the same number of spaces in front, and their children will have more spaces. So there is no entry corresponding to 3 spaces.
Also, 3823621M94.PRT is a Grand-Child (generation 2), but has 5 spaces i.e. same as Child so if a look up is done in the dictionary it gets the wrong parent (01260709.ASM instead of 3786094M93.ASM).
I can't think of an easy way to fix this.
How are the files created? Is it possible to ensure that the creation processes produce files with consistent spacing? They don't have to have the same spacing in every file but each file must have consistent spacing for my code to work. Failing that it's back to the drawing board.
Regards
David R
|
|
|
|
|
|
If the spacing is inconsistent within a file there is no solution. At least none that I can see.
Without consistent spacing you cannot tell which line is the parent of the current line.
If there were only parent and child lines it would not be a problem, but you have grand-child and great-grand-child lines (and even great-great-grand-child lines).
The problem is that, if you read a line that has less spaces than the previous line, you don't know if the line just read has the same parent as the previous one; it could have the same grand-parent (or great-grand-parent) without having the same parent. Unless the spacing is consistent there is no way to decide whether the two lines have the same parent or just the same grand-parent. I thought you might be able to decide based on whether it is a .ASM or .PRT line but even that's not possible (based on the full file in a previous post).
That's the bad news! Here's the good news. You can remove the spaces by doing something like this in Parent_Child1.
If (generation > 0) Then
outputLine = parentStack(generation - 1).Trim()
outputLine = outputLine & Space(40 - outputLine.Length()) & name.Trim()
sw.WriteLine(outputLine)
'sw.WriteLine(parentStack(generation - 1) & name) 'ORIGINAL LINE
Else
'Do you need to do this for lines that have no parent?
sw.WriteLine(parentStack(generation))
End If
You need to declare outputLine and perhaps adjust the 40 to suit (I used 40 because the longest name I saw in your file was 34 characters).
The only way to solve the problem that I can see is to ensure that the processes that generate the input files use consistent spacing. Alternatively, they use some marker that indicates which generation the line is i.e. parent or child or grand-child.
Regards
David R
|
|
|
|
|
Thanks for that piece of code...
It works perfectly...
I will check if anything can be done with the processes that generates the input file...
I will comeback to you, if there are any changes in the generated input file.
Thanks for all the support that you have given me..
I will post my message in the forum,Please reply to that..
Thanks once again for all your support and help...
|
|
|
|
|
Glad to be of help.
I did think of a possible way to deal with the file you posted (i.e. one that fails on 4282010M1.PRT). However, it would only handle that file and no others so not much good. And I've not tried it to see if it does work.
I also noticed these lines earlier in the file.
339168X1.PRT -- VIS H, M8x50, 8.8
339168X1.PRT -- VIS H, M8x50, 8.8
836322586.PRT -- --
837070289.PRT
The way my code works it would make 339168X1.PRT the parent of 836322586.PRT. If the data is what I think it is this would be wrong - if I'm right about this, the inconsistent spacing starts earlier in the file and so the output is wrong.
Best wishes with the project.
Regards
David R
|
|
|
|
|
Thanks a lot for taking time to check my input file.
Will keep you posting and update you on the future results of the file..
If you don't mind,can you send the code that you think may work only for this particular file?
So that i can cross check and try to change the code if it suits the other files also...
Thanks once again!
|
|
|
|
|
Here's the hack that might work - as I said I've not tested it.
Private Function GetGeneration(ByVal s As String, ByVal resetDict As Boolean) As Integer
Dim spaceCount As Integer
Static maxSpaces As Integer = -1
Static lastGen As Integer = -1
Static genDict As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)
If (resetDict) Then
genDict.Clear()
maxSpaces = -1
lastGen = -1
End If
spaceCount = NbOfCar(s, " ")
'START Hack that might deal with example file
If (Not genDict.ContainsKey(spaceCount)) Then
'Find the number of spaces for top level parent
Dim gen0Spaces As Integer
For Each k As Integer In genDict.Keys()
If genDict(k) = 0 Then
gen0Spaces = k
End If
Next k
'Clear the dictionary and add gen 0 back since we need to keep it
genDict.Clear()
genDict.Add(gen0Spaces, 0)
maxSpaces = gen0Spaces
lastGen = 0
End If
'END of Hack
If (spaceCount > maxSpaces) Then
lastGen += 1
genDict.Add(spaceCount, lastGen)
maxSpaces = spaceCount
End If
GetGeneration = genDict(spaceCount)
End Function
It will stop the error message but I'm not certain that it will get the correct parent for each input line.
Regards
David R
|
|
|
|
|
|
Thanks a lot...
Will check out this code with my input file and let you know...
|
|
|
|
|
|
That's not unexpected.
The hack was to deal with the big file you sent in a previous post (and as I said I'm not certain it would actually work 100%, even for that file).
If you check the two input files I suspect you'll find that the one that worked has consistent spacing for each generation; the one that failed did not. Or the one that worked had spacing that the hack could deal with.
The problem is that for each file that fails you have to examine the file and find out how the spacing changes, then devise a hack that deals with it (and that may not be possible). That's why consistent spacing is so important.
The hack relies on the file being in two blocks as shown in this edited extract (^ represents space in Generation column).
Name etc Generation
01260709.ASM unité moteur ^Parent
4296458M91.ASM ENS MOTEUR 74 ^^^^^Child 'Start of first block
4296454M1.ASM MOTEUR 74 ^^^^^Child
BLOC_MOTEUR_SRT2.ASM -- ^^^^^^^Grand Child
832760664_SANS_SRT2.ASM -- ^^^^^^^^^Great Grand Child
--- removed lots of lines in file -------
4282023M91.ASM ENS. VOLANT MOTEUR ^^^^^Child
4282024M1.PRT VOLANT D'INERTIE ^^^^^^^Grand Child
1619032M1.PRT COURONNE DEMARREUR ^^^^^^^Grand Child
4282010M1.PRT -- ^^^Child 'Start of second block
3786094M93.ASM ENS DEMARREUR ISKR ^^^Child
3823621M94.PRT DEMARREUR ISKRA ^^^^^Grand Child
3786093M1.PRT -- ^^^^^Grand Child
3788193M1.PRT -- ^^^^^Grand Child
3786092M1.PRT -- ^^^^^Grand Child
4292572M1.PRT GARANT DE COLLECTE ^^^Child
--- removed lots of lines in file -------
The first block has 5 spaces for child lines; the second has 3 spaces. When the first line with 3 spaces is found it throws the error that is caught and used to reset the dictionary. If the two blocks had been in reverse order (i.e. 3 space child lines then 5 space child lines) there would be no possible hack.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
modified on Monday, May 4, 2009 5:09 AM
|
|
|
|
|
|
I found out the reason for the error..;
the error appeared because the of this
Dim parentStack(5) As String now i have changed to
Dim parentStack(10) As String because there may be generations more than 5...
Thank David for all your support and help...
Vijay
|
|
|
|
|
You beat me to it!
I'd just set it to 5 as being reasonable and meant to mention it before as a possible problem.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
I'd do something like this
outputLine = parentStack(generation - 1).Trim()
outputLine = outputLine & Space( 40 - outputLine.Length()) & name.Trim()
outputLine = outputLine & Space( 80 - outputLine.Length()) & desF.Trim()
outputLine = outputLine & Space(120 - outputLine.Length()) & desAF.Trim()
etc....
sw.WriteLine(outputLine)
Where you need to change the 80, 120 to suit your spacing.
The secret is to build the output line a bit at a time then write it out.
This way of doing it is inefficient because the outputLine variable is constantly being recreated (because strings are immutable).
If that proves a problem because of performance, take a look at StringBuilder in the help system or any VB.Net book.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
The code I used based on your suggestion...
Code:
parentStack(generation) = name
If (generation > 0) Then
outputLine = parentStack(generation - 1).Trim()
outputLine = outputLine & Space(40 - outputLine.Length()) & name.Trim()
outputLine = outputLine & Space(80 - outputLine.Length()) & desF
sw.WriteLine(outputLine & desAF & desA & desAA & ecn & dnf & baloon)
'sw.WriteLine(parentStack(generation - 1) & name) 'ORIGINAL LINE
Else
'Do you need to do this for lines that have no parent?
outputLine = parentStack(generation).Trim()
outputLine = outputLine & Space(40 - outputLine.Length()) & name.Trim()
outputLine = outputLine & Space(80 - outputLine.Length()) & desF
sw.WriteLine(outputLine & desAF & desA & desAA & ecn & dnf & baloon)
End If
Works fine now.
Thanks a lot
modified on Monday, May 4, 2009 7:43 AM
|
|
|
|
|
Hello every one,
I have a VB 2005 express application. I was changing the interface in IDE (VB 2005 Express By Microsoft). On compiling it gave an error
"The operation could not be completed. Not enough storage is available to complete this operation."
This error was shown on Msgbox(OK Only), on click of "Ok" it opened Save file dialog. I did not saved it. After trying 1-2 more times and googling a bit i decided to close (Without saving) and open the application again.
When i opened the application, the form i was working in is shown blank. I opened the .designer.vb file and resx file. Bot have data in it.
Any idea what has gone wrong and how can i get the thing up back again.
Regards
Nishkarsh
|
|
|
|
|
You could try closing the designer tab for the form, then reopening it, this sometimes works, although not if closing and opening the solution did not cure the problem.
Otherwise, it is a case of going through the .designer.vb code line by line, and fixing any problems manually.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
i have a html file in webserver and when client tries to invoke html thru url...
i need to display(message box) the screenresolution of client using vbscript....Pls help me out..
|
|
|
|
|
Why VBScript and not Java Script? Using Java Script you can use
screen.width
and
screen.height
VBScript will only work in IE.
|
|
|
|
|
Thanks for ur response ......
but im using only vbscript..pls let me know....
|
|
|
|
|
But why? Is the script running in a browser? If so then Java Script will run in any browser, VB Script will only run in Microsoft browsers.
Sorry but I don't how to do it in VB Script.
|
|
|
|
|
Im now doing final year of my studies and im required to come up with a project. pls help me to come up with a project and help me with some ideas that i can develop into a project in vb. Thanks
|
|
|
|