InStr / Right function

Author Message
alpizzle

  • Total Posts : 6
  • Scores: 0
  • Reward points : 0
  • Joined: 4/16/2008
  • Status: offline
InStr / Right function Wednesday, April 16, 2008 12:47 AM (permalink)
0
Hi Guys, I'm kind of new to programming and have a question about an asp page that uses vbscript that I need to alter.
 
What happens now is   I have a user upoad a file, my program looks for certain things using InStr, for example If Instr(1, strline, "Label="), it then copies the next line to a numbered line in a destination file. 
 
Now I have a new set of files being uploaded that aren't as uniformly formatted as above.  So I need to look for ":" in a string, which could be at any position and copy everything after the colon to the numbered line.  I am unsure how to approah this and could use any advice that could point me in the right direction.
 
Thanks
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: InStr / Right function Wednesday, April 16, 2008 1:48 AM (permalink)
    0
    There are a couple of ways to do this. The way I would do it is this:
     
    'strLine is the line you want to look for the data in
    If InStr(strLine, ":") Then
        strData = Split(strLine, ":")(1)
    End If
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      alpizzle

      • Total Posts : 6
      • Scores: 0
      • Reward points : 0
      • Joined: 4/16/2008
      • Status: offline
      RE: InStr / Right function Wednesday, April 16, 2008 2:08 AM (permalink)
      0
      wow, thanks ebgreen, I was making that waaaay more dificult than it needed to be.  I appreciate the help
       
      #3
        alpizzle

        • Total Posts : 6
        • Scores: 0
        • Reward points : 0
        • Joined: 4/16/2008
        • Status: offline
        RE: InStr / Right function Wednesday, April 16, 2008 3:19 AM (permalink)
        0
        Sorry to ask but one more question if you could help.  It appears way down the file there are some lines that have multiple colons on each line, any tips on that?

        I am using the code as you suggested and it's fantastic for 99% of the lines

        If InStr(strLine, ":") Then

        strData = Split(strLine, ":")(1)
        streamDestFile.WriteLine phNumber & " " & strData
        phNumber = phNumber + 1

        End If
         
        #4
          ebgreen

          • Total Posts : 8227
          • Scores: 98
          • Reward points : 0
          • Joined: 7/12/2005
          • Status: offline
          RE: InStr / Right function Wednesday, April 16, 2008 3:55 AM (permalink)
          0
          Could you show some of the problematic lines?
          "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
          Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
          http://www.visualbasicscript.com/m_47117/tm.htm
           
          #5
            alpizzle

            • Total Posts : 6
            • Scores: 0
            • Reward points : 0
            • Joined: 4/16/2008
            • Status: offline
            RE: InStr / Right function Wednesday, April 16, 2008 4:10 AM (permalink)
            0
            Sure thing, here are a couple of examples:
             
            CHANNEL_READING_STATS:%d readings on Chan %d: Avg: %s  Min: %d  Max:  %d  Alt: Avg: %s  Min: %d  Max %d
             
             
            FSC_NEXT_LOOP_6_STR5:    Note:  Lateral channel tare replaces offset in normal operation.
             
            Basically I need everything left of the first colon removed, which would write line numbers and the remainder of the string to the destination file. Like the following:
             
            1 Note:  Lateral channel tare replaces offset in normal operation.
             
            Thanks ebgreen
             
            #6
              ebgreen

              • Total Posts : 8227
              • Scores: 98
              • Reward points : 0
              • Joined: 7/12/2005
              • Status: offline
              RE: InStr / Right function Wednesday, April 16, 2008 4:16 AM (permalink)
              0
              Oh, so would this statement apply to all lines?
               
              "If a colon is present then the data of interest is everything after the first colon"
              "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
              Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
              http://www.visualbasicscript.com/m_47117/tm.htm
               
              #7
                alpizzle

                • Total Posts : 6
                • Scores: 0
                • Reward points : 0
                • Joined: 4/16/2008
                • Status: offline
                RE: InStr / Right function Wednesday, April 16, 2008 4:19 AM (permalink)
                0
                that's correct.
                 
                #8
                  ebgreen

                  • Total Posts : 8227
                  • Scores: 98
                  • Reward points : 0
                  • Joined: 7/12/2005
                  • Status: offline
                  RE: InStr / Right function Wednesday, April 16, 2008 4:40 AM (permalink)
                  0
                  Remeber that "There are a couple of ways..." statement? Well we are going to go a different way


                  'strLine is the line you want to look for the data in
                  strData = Mid(strLine, InStr(strLine, ":")+1)
                  "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                  Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                  http://www.visualbasicscript.com/m_47117/tm.htm
                   
                  #9
                    alpizzle

                    • Total Posts : 6
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 4/16/2008
                    • Status: offline
                    RE: InStr / Right function Wednesday, April 16, 2008 5:55 AM (permalink)
                    0
                    Thanks so much for the help ebgreen, I really appreciate it, that worked very well. 
                     
                    #10

                      Online Bookmarks Sharing: Share/Bookmark

                      Jump to:

                      Current active users

                      There are 0 members and 1 guests.

                      Icon Legend and Permission

                      • New Messages
                      • No New Messages
                      • Hot Topic w/ New Messages
                      • Hot Topic w/o New Messages
                      • Locked w/ New Messages
                      • Locked w/o New Messages
                      • Read Message
                      • Post New Thread
                      • Reply to message
                      • Post New Poll
                      • Submit Vote
                      • Post reward post
                      • Delete my own posts
                      • Delete my own threads
                      • Rate post

                      2000-2012 ASPPlayground.NET Forum Version 3.9