Click here to Skip to main content
16,006,006 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 7:34
riced30-Apr-09 7:34 
GeneralMessage Closed Pin
30-Apr-09 11:27
vijay248230-Apr-09 11:27 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 12:58
riced30-Apr-09 12:58 
GeneralRe: IF ELSE or LOOP Pin
vijay24821-May-09 1:06
vijay24821-May-09 1:06 
GeneralRe: IF ELSE or LOOP Pin
riced1-May-09 1:23
riced1-May-09 1:23 
GeneralRe: IF ELSE or LOOP Pin
vijay24821-May-09 7:27
vijay24821-May-09 7:27 
GeneralRe: IF ELSE or LOOP Pin
riced2-May-09 3:32
riced2-May-09 3:32 
GeneralRe: IF ELSE or LOOP Pin
riced2-May-09 11:50
riced2-May-09 11:50 
Just struck me that I'd put the hack in the wrong place, and I'd not set the dictionary entry for the new spaces. D'Oh! | :doh:
It only needs to be done if an exception is thrown.
Here's the version that might work. Smile | :)
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

   Try
      GetGeneration = genDict(spaceCount)
   Catch
      'START Hack that might deal with example file
         '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
      'Now add the entry for the 3 space indented line
      genDict.Add(spaceCount, lastGen)
      maxSpaces = spaceCount
      GetGeneration = genDict(spaceCount)
      'END of Hack
   End Try
End Function


Regards
David R

GeneralRe: IF ELSE or LOOP Pin
vijay24822-May-09 21:57
vijay24822-May-09 21:57 
GeneralMessage Closed Pin
3-May-09 21:17
vijay24823-May-09 21:17 
GeneralRe: IF ELSE or LOOP [modified] Pin
riced3-May-09 23:02
riced3-May-09 23:02 
GeneralMessage Closed Pin
3-May-09 23:32
vijay24823-May-09 23:32 
GeneralRe: IF ELSE or LOOP Pin
vijay24823-May-09 23:42
vijay24823-May-09 23:42 
GeneralRe: IF ELSE or LOOP Pin
riced3-May-09 23:45
riced3-May-09 23:45 
GeneralMessage Closed Pin
3-May-09 23:53
vijay24823-May-09 23:53 
GeneralRe: IF ELSE or LOOP Pin
riced4-May-09 0:45
riced4-May-09 0:45 
GeneralRe: IF ELSE or LOOP [SOLVED] Pin
vijay24824-May-09 1:33
vijay24824-May-09 1:33 
QuestionThe operation could not be completed. Not enough storage is available to complete this operation. Pin
nishkarsh_k28-Apr-09 23:14
nishkarsh_k28-Apr-09 23:14 
AnswerRe: The operation could not be completed. Not enough storage is available to complete this operation. Pin
Henry Minute28-Apr-09 23:51
Henry Minute28-Apr-09 23:51 
QuestionGetScreenResolution of client Pin
p_196028-Apr-09 22:44
p_196028-Apr-09 22:44 
AnswerRe: GetScreenResolution of client Pin
Jay Royall28-Apr-09 22:55
Jay Royall28-Apr-09 22:55 
GeneralRe: GetScreenResolution of client Pin
p_196028-Apr-09 23:44
p_196028-Apr-09 23:44 
GeneralRe: GetScreenResolution of client Pin
Jay Royall28-Apr-09 23:48
Jay Royall28-Apr-09 23:48 
QuestionProject ideas in vb Pin
innocent mwila28-Apr-09 21:54
innocent mwila28-Apr-09 21:54 
AnswerRe: Project ideas in vb Pin
Zaegra28-Apr-09 22:08
Zaegra28-Apr-09 22:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.