|
Hi,
i have an authorised SSL certificate in the web server and when client invokes the html which is present inthe server...IE should display certificate like..
Security Alert box with yes ,no and view certificate buttons.....
and what are tags i need to add in html so that client client views it when trying to access the html.....
|
|
|
|
|
And this has what to do with VB.NET??
You still haven't picked up that book, haven't you??
|
|
|
|
|
Hi all,
I have an input file that has a field named "NAME".
I have to split this Name field into PARENT and CHILD fields.
The alignement of the CHILD field is not proper, kindly bare with it...
Code I have Done:
Iam not sure whether to use IF ELSE or While Loop
I think i have to read the next line with in the If statement that i have used...
But Im not sure..;
Thanks in Advance.....
modified 28-Nov-12 8:30am.
|
|
|
|
|
I think it's a bit more complicated than deciding whether or not to use IF..ELSE or LOOP. You have more than two generations in the data i.e. ASMs contain ASMs that contain PRTs (parent-child-grandchild).
Here's some code that I've been playing with.
There is at least one bug in it but the general idea is sound (I think ).
Imports System.IO
Module Module1
Sub Main()
Call Parent_Child1("C:\PlayPen\Names.txt", "C:\PlayPen\Names_OUT.txt")
End Sub
Private Sub Parent_Child1(ByVal iFile As String, ByVal oFile As String)
Dim previousSpaces As Integer
Dim currentSpaces As Integer
Dim pF(10) As Integer
Dim parentStack(5) As String
Dim generation As Integer = 0
Dim name As String
Dim inputLine As String
Using sw As StreamWriter = New StreamWriter(oFile)
Using sa As StreamReader = New StreamReader(iFile)
inputLine = sa.ReadLine()
Call FillPF(pF, inputLine)
Call WriteHeader(sa, sw, inputLine, pF)
'Assume first data record is a parent
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
previousSpaces = NbOfCar(name, " ")
parentStack(generation) = name
'generation += 1
While sa.Peek() >= 0
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
currentSpaces = NbOfCar(name, " ")
If currentSpaces = previousSpaces Then
sw.WriteLine(parentStack(generation - 1) & name)
Else
If currentSpaces > previousSpaces Then
sw.WriteLine(parentStack(generation) & name)
previousSpaces = currentSpaces
generation += 1
parentStack(generation) = name
Else
' currentSpaces < previousSpaces
generation -= 1
previousSpaces = currentSpaces
sw.WriteLine(parentStack(generation) & name)
End If
End If
End While
End Using
End Using
End Sub
Private Function NbOfCar(ByVal s As String, ByVal c As String) As Integer
Dim i As Integer = 0
While (i < s.Length) And (s.Substring(i, 1) = c)
i += 1
End While
NbOfCar = i
End Function
Private Sub FillPF(ByVal p() As Integer, ByVal t As String)
p(0) = t.IndexOf("Nom du Modele")
p(1) = t.IndexOf("AEC_STANDARD_DESCRIPTION_FRENCH")
p(2) = t.IndexOf("AEC_FREE_DESCRIPTION_FRENCH")
p(3) = t.IndexOf("AWW_STANDARD_DESCRIPTION")
p(4) = t.IndexOf("AEC_FREE_DESCRIPTION_ENGLISH")
p(5) = t.IndexOf("AEC_ECN")
p(6) = t.IndexOf("DNF")
p(7) = t.IndexOf("BALOON")
End Sub
Private Sub WriteHeader(ByVal sr As StreamReader, ByVal sw As StreamWriter, ByVal t As String, ByVal p() As Integer)
Dim s As String = ""
s = t.Substring(p(1), p(2) - p(1)) ' desF
s = s & t.Substring(p(2), p(3) - p(2)) ' desAF
s = s & t.Substring(p(3), p(4) - p(3)) ' desA
s = s & t.Substring(p(4), p(5) - p(4)) ' desAA
s = s & t.Substring(p(5), p(6) - p(5)) ' ecn
s = s & t.Substring(p(6), p(7) - p(6)) ' dnf
s = s & t.Substring(p(7), t.Length - p(7)) ' baloon
sw.WriteLine("PARENT" & Space(10) & "CHILD" & Space(10) & s)
sw.WriteLine(sr.ReadLine()) 'The line of underscores
End Sub
End Module
It fails on the last record in this test file (and there may be other bugs.)
Nom du Modele AEC_STANDARD_DESCRIPTION_FRENCH AEC_FREE_DESCRIPTION_FRENCH AWW_STANDARD_DESCRIPTION AEC_FREE_DESCRIPTION_ENGLISH AEC_ECN DNF BALOON
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
01530501.ASM
4281484M1.PRT
3009508X1.PRT
3009508X1.PRT
3009506X1.PRT
3009506X1.PRT
3583428M1.PRT
3583428M1.PRT
3583428M1.PRT
4282884M92.ASM
4282885M2.PRT
4281478M1.PRT
4281479M1.PRT
390734X1.PRT
390734X1.PRT
390734X1.PRT
3009495X1.PRT
3009495X1.PRT
3009495X1.PRT
3385604M2.PRT
3385604M2.PRT
391039X1.PRT
4287200M3.ASM
391176X1.PRT
4281283M93.ASM
4284820M94.ASM
4282976M2.ASM
4282971M2.ASM
4285693M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4281283XXX.ASM
You'll notice that I've dropped all the fields you were not outputting but they should be ewasy to put back in.
Hope this helps
Regards
David R
|
|
|
|
|
Here's a version that fixes the bug in previous one.
Private Sub Parent_Child1(ByVal iFile As String, ByVal oFile As String)
Dim pF(10) As Integer
Dim parentStack(5) As String
Dim generation As Integer = 0
Dim name As String
Dim inputLine As String
Using sw As StreamWriter = New StreamWriter(oFile)
Using sa As StreamReader = New StreamReader(iFile)
inputLine = sa.ReadLine()
Call FillPF(pF, inputLine)
Call WriteHeader(sa, sw, inputLine, pF)
'Assume first data record is a parent
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
parentStack(generation) = name
'Write out first record here if need to
While sa.Peek() >= 0
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
generation = GetGeneration(name)
parentStack(generation) = name
If (generation > 0) Then
sw.WriteLine(parentStack(generation - 1) & name)
Else
'Do you need to do this for lines that have no parent?
sw.WriteLine(parentStack(generation))
End If
End While
End Using
End Using
End Sub
Private Function GetGeneration(ByVal s As String) As Integer
Dim g As Integer
g = NbOfCar(s, " ")
If (g > 1) Then
g = (g - 1) / 2
End If
GetGeneration = g
End Function
It assumes that the first child generation has 3 spaces; the second has 5 spaces,; the third has 7 spaces and so on. If that's not the case then GetGeneration() might have to be modified.
You'll notice it is a bit different from my original effort. That's because I put my thinking head on and realised that the number of spaces tells you the generation and the parent must be the previous generation!
Regards
David R
|
|
|
|
|
|
I thought this might be the case. As I said this means modifying GetGeneration().
Here's a version that should work.
Private Function GetGeneration(ByVal s As String) 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)
spaceCount = NbOfCar(s, " ")
If (spaceCount > maxSpaces) Then
lastGen += 1
genDict.Add(spaceCount, lastGen)
maxSpaces = spaceCount
End If
GetGeneration = genDict(spaceCount)
End Function
You also need to modify the Parent_Child1 sub to add the line in bold as below.
'Assume first data record is a parent
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
generation = GetGeneration(name)
parentStack(generation) = name
'Write out first record here if need to
I've not fully tested this but it seems ok on a modified version of the test file I sent in previous post.
Regards
David R
|
|
|
|
|
The code reads the input file and writes to the output file.
But not for the entire file.
Giving error message after few lines written..;
I'm getting this error message "The key data were missing from the dictionary." in the line below:
GetGeneration = genDict(spaceCount)
|
|
|
|
|
I suspect this means the spacing in the data file is inconsistent.
My solution assumes that in a file all children have same number of spaces; all grand-children have same number of spaces; all great-grand-children have same number of spaces and so on. With number of spaces increasing for younger generations.
If the spacing is inconsistent then the dictionary approach will fail and the problem is more complex.
Off the top of my head I don't have a solution but think it probably means constructing some sort of tree to hold the data.
Regards
David R
|
|
|
|
|
I just had a thought about my last version of GetGeneration(). It works if the spacing in a file is consistent but if you call Parent_Child1 multiple times in a program (with different input files) it will fail unless the files have the same spacing.
So here's a version that should fix that potential bug.
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, " ")
If (spaceCount > maxSpaces) Then
lastGen += 1
genDict.Add(spaceCount, lastGen)
maxSpaces = spaceCount
End If
GetGeneration = genDict(spaceCount)
End Function
In ParentChild1 set the second parameter to True on the first call (before the While loop) and to False for the call in the While loop.
Regards
David R
|
|
|
|
|
There are 2 parameters in genDict
Static genDict As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)
But while calling genDict there is only on parameter...
GetGeneration = genDict(spaceCount)
I think there is some problem here, if im not wrong...
suggest your comment about this case..;
Thanks in advance
|
|
|
|
|
Not a problem. Have a look at the Dictionary(Of Tkey, Tvalue) class in help.
What I'm doing is storing the number of spaces (as key) and the generation (as value) so given the number of spaces I can look up the generation.
I tried running my program using the data in your last reply and cannot recreate the problem.
(Edited out the commented lines.
Here's the output I got.
PARENT CHILD AEC_STANDARD_DESCRIPTION_FRENCH AEC_FREE_DESCRIPTION_FRENCH AWW_STANDARD_DESCRIPTION AEC_FREE_DESCRIPTION_ENGLISH AEC_ECN DNF BALOON
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
01260709.ASM 4296458M91.ASM
01260709.ASM 4296454M1.ASM
4296454M1.ASM COVER_DISTRIB_74L_SRT2_2.ASM
COVER_DISTRIB_74L_SRT2_2.ASM 837070162_LRT.PRT
COVER_DISTRIB_74L_SRT2_2.ASM BRACKETPLATEWITHOUTAIRB.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 836667411_32_4DEG_ASM_2XXX.ASM
836667411_32_4DEG_ASM_2XXX.ASM DAYCO_BELTTENSIONER_BASE_2XXX.PRT
836667411_32_4DEG_ASM_2XXX.ASM DAYCO_BELTTENSIONER_ARM_3XXX.PRT
836667411_32_4DEG_ASM_2XXX.ASM DAYCO_BELTTENSIONER_RING_2XXX.PRT
836667411_32_4DEG_ASM_2XXX.ASM 836866321_2XXX.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529801470_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529801540_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529801540_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
01260709.ASM 4282023M91.ASM
4282023M91.ASM 4282024M1.PRT
4282023M91.ASM 1619032M1.PRT
Regards
David R
|
|
|
|
|
|
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
|
|
|
|
|
|