Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. How to split a string the hard way (VB6)

How to split a string the hard way (VB6)

Scheduled Pinned Locked Moved The Weird and The Wonderful
data-structurestutorial
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AaronM_NZ
    wrote on last edited by
    #1

    It took me about 20 minutes to work out what the heck this For/Next loop was doing. The programmer must not have heard of .Split. It takes a key from an INI file (vkeys) and if it is formatted as such: SERVICES = Service1, Service2, Service3, Service4 ... it puts the list of services into an array for later use..

    If vkeys(lval, 0) = "services" Or vkeys(lval, 0) = "SERVICES" Then
    totallength = Len(vkeys(lval, 1))
    For searchstring = 1 To totallength
    tempcounter2 = tempcounter2 + 1
    If Mid(vkeys(lval, 1), searchstring, 1) = "," Then
    servicecount(X) = servicecount(X) + 1
    nodeservices(X, servicecount(X)) = Mid(vkeys(lval, 1), _
    tempcounter1, tempcounter2 - 1)
    If Right(nodeservices(X, servicecount(X)), 1) = "," Then
    ' This strips the comma of the end of the string.
    nodeservices(X, servicecount(X)) = _
    Left(nodeservices(X, servicecount(X)),_
    (Len(nodeservices(X, servicecount(X))) - 1))
    End If

            'Sets start of service name within string
            tempcounter1 = searchstring + 1
            tempcounter2 = 1
        End If
        If searchstring = totallength Then
            nodeservices(X, (servicecount(X) + 1)) = Mid(vkeys(lval, 1),\_
                         tempcounter1, tempcounter2 - 1) ' Gets the last service.
        End If
    Next searchstring
    
    servicecount(X) = servicecount(X) + 1
    tempcounter2 = 1
    

    End If

    G 1 Reply Last reply
    0
    • A AaronM_NZ

      It took me about 20 minutes to work out what the heck this For/Next loop was doing. The programmer must not have heard of .Split. It takes a key from an INI file (vkeys) and if it is formatted as such: SERVICES = Service1, Service2, Service3, Service4 ... it puts the list of services into an array for later use..

      If vkeys(lval, 0) = "services" Or vkeys(lval, 0) = "SERVICES" Then
      totallength = Len(vkeys(lval, 1))
      For searchstring = 1 To totallength
      tempcounter2 = tempcounter2 + 1
      If Mid(vkeys(lval, 1), searchstring, 1) = "," Then
      servicecount(X) = servicecount(X) + 1
      nodeservices(X, servicecount(X)) = Mid(vkeys(lval, 1), _
      tempcounter1, tempcounter2 - 1)
      If Right(nodeservices(X, servicecount(X)), 1) = "," Then
      ' This strips the comma of the end of the string.
      nodeservices(X, servicecount(X)) = _
      Left(nodeservices(X, servicecount(X)),_
      (Len(nodeservices(X, servicecount(X))) - 1))
      End If

              'Sets start of service name within string
              tempcounter1 = searchstring + 1
              tempcounter2 = 1
          End If
          If searchstring = totallength Then
              nodeservices(X, (servicecount(X) + 1)) = Mid(vkeys(lval, 1),\_
                           tempcounter1, tempcounter2 - 1) ' Gets the last service.
          End If
      Next searchstring
      
      servicecount(X) = servicecount(X) + 1
      tempcounter2 = 1
      

      End If

      G Offline
      G Offline
      GibbleCH
      wrote on last edited by
      #2

      It's a horror right from the first line

      If vkeys(lval, 0) = "services" Or vkeys(lval, 0) = "SERVICES" Then

      ...what about "Services"

      P 1 Reply Last reply
      0
      • G GibbleCH

        It's a horror right from the first line

        If vkeys(lval, 0) = "services" Or vkeys(lval, 0) = "SERVICES" Then

        ...what about "Services"

        P Offline
        P Offline
        peterchen
        wrote on last edited by
        #3

        Release 1.01: Added support for "Services".

        Agh! Reality! My Archnemesis![^]
        | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server.

        OriginalGriffO 1 Reply Last reply
        0
        • P peterchen

          Release 1.01: Added support for "Services".

          Agh! Reality! My Archnemesis![^]
          | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Bug report: it fails with "serviceS". :laugh:

          You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          S P 2 Replies Last reply
          0
          • OriginalGriffO OriginalGriff

            Bug report: it fails with "serviceS". :laugh:

            You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

            S Offline
            S Offline
            Stanciu Vlad
            wrote on last edited by
            #5

            OriginalGriff wrote:

            Bug report: it fails with "serviceS".

            Dear Mr./Ms. User, We are currently offering support for "services", "Services", "SERVICES" (based on user skill - does not know about text formatting rules, knows about text formatting rules, does not know about CAPS LOCK key) and we plan to support "sERVICES" (for users who know formatting rules but forgot about CAPS LOCK key) in future releases. As far as we see, "serviceS" is an anomaly and it should not be considered a bug. Yours trully, Programming Team Leader.

            I have no smart signature yet...

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Bug report: it fails with "serviceS". :laugh:

              You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

              P Offline
              P Offline
              Paulo Zemek
              wrote on last edited by
              #6

              Development team answer: This is not a bug. All key values must be uppercase. We are simplifying the application so services and Services are no more supported, avoiding further errors. In fact, the check is now: If len(vkeys[lval, 0]) = 8 and Mid(lvkeys[lval, 0], 0, 1) = "S" and Mid(lvkeys[lval, 0], 1, 1) = "E" ... and so on. :laugh: (Note, I started to write this at the same time of the last post... I think our development team is having problems of communication... who the hell tought we must support other keywords?? :doh: ).

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups