Results 1 to 17 of 17

Thread: [RESOLVED] Select case with this

  1. #1

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Resolved [RESOLVED] Select case with this

    How to use select case with this data then.
    Code:
    @dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetH
    Is that right
    Code:
    Select case
    Case = "%@"
    
    End select

  2. #2
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    728

    Re: Select case with this

    What are you trying to achieve?

    Select Case is just a replacement for lots of chained elsif statements:

    Code:
    If ( UCase$( letter ) = "A" ) Then 
        Do_A
    ElsIf ( UCase$( letter ) = "C" ) Then 
        Do_C
    ElsIf ( UCase$( letter ) = "B" ) Then
        Doo_B_doo_B_doo 
    End If
    becomes

    Code:
    Select Case UCase$( letter ) 
    case "A" 
        Do_A
    case "C"
       Do_C
    Case "B"
        Doo_B_doo_B_doo 
    End Select
    Regards, Phill W.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    8,156

    Re: Select case with this

    To my eyes, it's wildly unclear what you want.

    However, here's a wild guess:

    Code:
    Select Case True
    Case Instr(sMyString, "%@")
        ' "%@" is in string, so do work.
    
    
    End select
    Any software I post in these forums written by me is provided AS IS without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that Ive been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a VB6 random code folder that is overflowing. Ive been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: Select case with this

    Thanks guys will test it when I get home

    Yes so I want to send the first string data which is
    Code:
    @dE%GetHost#@%@
    Then what ever is after that use case statement to extract each strings

    Code:
    @dE%GetHost#@%@ & "@###@" & string1 & "@%/=#%" & string2
    Select case to extract string1
    Select case to extract string2
    And so on ?
    Last edited by jenniger9; Aug 12th, 2022 at 08:43 AM.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2019
    Posts
    316

    Re: Select case with this

    No Select Case does not extract strings

    It does this:

    Code:
    Dim theString as string
    
    theString = "andrew"
    
    select case theString
    
            case "andrew"
    
                   ' process andrews stuff
    
           case "fred"
    
                  ' process freds stuff
    
    end select
    And so on for longs etc. Its a way of writing large if then else code that is more readable and maintainable

  6. #6
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    728

    Re: Select case with this

    To manipulate String data, forget Select.>Case.
    You need to use functions like this:

    Instr() - Find a string within a larger string.

    Code:
     
    ? Instr( "Big string", "str" ) 
    5
    Left$() - Get the leading part of a String.

    Code:
    ? Left$( "Big string", 7 ) 
    Big str
    Right$() - Get the end part of a String.

    Code:
    ? Right$( "Big string", 5 ) 
    tring
    Mid$() - Get a subsection of a String.

    Code:
    ? Mid$( "Big string", 2, 5 ) 
    ig st
    Split() - Break a string into an array of String using a fixed delimiter.
    Join() - Creates a single string from an array of String, putting a fixed delimiter between each element.

    Regards, Phill W.

  7. #7

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: Select case with this

    how do i do it like this


    Code:
    @dE%GetHost#@%@ & "@###@" & string1 & "@%/=#%" & string2
    main code for the select case to detect and the rest break the string up for each string with
    Code:
     "@###@"
    return value string1 in select case. and
    Code:
    "@%/=#%"
    in select case to return value string2

    Code:
    select case "@dE%GetHost#@%@ & "@###@" & string1 & "@%/=#%" & string2"
    
    case  "@###@"
    'return string1
    
    case "@%/=#%"
    
     return string2
    
    end select

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,095

    Re: Select case with this

    You don't use select case for this. You would need to use instr() and Mid$() to parse out the string or at least that is the way it appears. Your example is not very clear. Normally what you would do is have a string with a set delimiter character and use Split() to break the long string into an array of strings that you can then process one by one but if you string identifier is different for every string that doesn't work and you need to parse them one by one using instr() and Mid$()

  9. #9
    Hyperactive Member
    Join Date
    Mar 2019
    Posts
    316

    Re: Select case with this

    s
    Code:
    elect case "@dE%GetHost#@%@ & "@###@" & string1 & "@%/=#%" & string2"
    
    case  "@###@"
    'return string1
    
    case "@%/=#%"
    
     return string2
    
    end select
    To help you understand the code you posted does this:

    Creates a temporary string and assigns it to @dE%GetHost#@%@ & "@###@" & string1 & "@%/=#%" & string2


    Then tests the value of the temporary string as below

    Code:
    Dim temporaryString as string
    
    temporaryString = "@dE%GetHost#@%@ & "@###@" & string1 & "@%/=#%" & string2
    
    
    If temporaryString = "@###@" then
    
       ' return string1
    
    else
    
       if temporaryString = "@%/=#%" then
    
         ' return string2
    
       end if
    
    end if
    So you can see that this will never actually return anything.

    As others have mentioned you need to include in your string array a fixed delimiter then use by way of example:

    Code:
    Dim temporaryString as string
    
    dim strArray() as string
    
    const myDelim as string = "andrew"
    
    temporaryString = "value1" & myDelim & "value2" & mydelim & "value3"
    
    strArray() = split(temporaryString,myDelim)
    After the split strArray will contain

    strArray(0) will equal "value1"
    strArray(1) will equal "value2"
    strArray(3) will equal "value3"


    So in this simple example you need to build the string you want to extract stuff from with a fixed delimiter.

  10. #10
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    728

    Re: Select case with this

    Quote Originally Posted by jenniger9 View Post
    main code for the select case to detect and the rest break the string up ...
    And, again, FORGET ABOUT Select Case for this task.

    Quote Originally Posted by jenniger9 View Post
    ... for each string with "@###@", return value string1 ... and "@%/=#%" in select case to return value string2
    OK, with the string as given, you have some stuff, then "@###@", then the first field you want, then "@%/=#%", then the second string you want, and that's it.

    Something like this, perhaps?

    Code:
    Dim sData as String : sData = "@dE%GetHost#@%@@###@ABC123@%/=#%DEF456"
    Dim iPos1 as Long : iPos1 = Instr( sData, "@###@" )
    Dim iPos2 as Long : iPos2 = Instr( sData, "@%/=#%" )
    
    Dim sFirst as String : sFirst = Mid$( sData, ( iPos1 + 5 ), ( iPos2 + 6 ) - ( iPos1 + 5 ) -12 )
    Dim sSecond as String : sSecond = Mid$( sData, iPos2 + 6 )
    The main difficulty with this is that your delimiters are different lengths - that makes "finding" them more difficult.

    Another way to do this might be to replace the delimiters with different ones that are all the same length - that means you can use more "generic" code that is (and I apologise for this) actually a lot more like what you had originally ...

    Code:
    Dim sData as String : sData = "@dE%GetHost#@%@@###@ABC123@%/=#%DEF456"
    
    sData = Replace$( sData, "@###@", "洌1}" ) ' Make sure these don't appear in the data itself, obviously
    sData = Replace$( sData, "@%/=#%", "洌2}" )
    
    ' Now: sData = "@dE%GetHost#@%@洌1}ABC123洌2}DEF456"
    
    Dim sElements() as String : sElements = Split( sData, "" ) 
    
    ' Each element we want is now prefixed with the curly-braced numbers, so ... 
    ' sElements( 0 ) = "@dE%GetHost#@%@"
    ' sElements( 1 ) = "{1}ABC123"
    ' sElements( 2 ) = "{2}DEF456"
    
    
    Dim iSub as Long
    For iSub = 1 to UBound( sElements )
       Select Case Left$( sElements( iSub ), 3 )
       Case "{1}"
          Debug.Print Mid$( sElements( iSub ), 4 )
       Case "{2}"
          Debug.Print Mid$( sElements( iSub ), 4 )
       End Select 
    Next
    Regards, Phill W.

  11. #11
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,335

    Re: Select case with this

    The OP does realize, that i gave him a working solution to "break up" strings like that in my post in his other thread?
    https://www.vbforums.com/showthread....=1#post5577058
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  12. #12
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    3,460

    Re: Select case with this

    Why is there even a string like this with "Text1.Text" in it? I can't even imagine what he's doing to get that.

    @dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetH and then what looks like a truncated GetHost at the end?

    OP wants to write a program without learning how to program.

  13. #13
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    728

    Re: Select case with this

    Quote Originally Posted by fafalone View Post
    Why is there even a string like this with "Text1.Text" in it? I can't even imagine what he's doing to get that.
    It looks to me like they're trying to "dissect" compiled code, possibly .Net stuff.

    I recall seeing similar strangeness trying to Reverse Engineer data files that were written by a [very] old C++ program that just serialised the memory image of an object to a disk file. Sure, it was "quick and easy" for the programmer at the time, but it was an absolute nightmare for those that came after them and wanted to reuse all those data files!

    Quote Originally Posted by fafalone View Post
    OP wants to write a program without learning how to program.
    They certainly seem to have some very "odd" ideas of how VB works.

    Sadly, we may never know their actual intention.
    I do seem to recall asking for that, a while back ...

    Regards, Phill W.

  14. #14

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: Select case with this

    Quote Originally Posted by fafalone View Post
    Why is there even a string like this with "Text1.Text" in it? I can't even imagine what he's doing to get that.

    @dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetH and then what looks like a truncated GetHost at the end?

    OP wants to write a program without learning how to program.
    dont worry about it brother.
    if a new person was doing this,he will not come to this level yet working with these sort of data.
    Code:
     @dE%GetHost#@%@harris fna%@men of war%@Text1.Text%@3/8%@e2d1ef98-61d9@dE%GetH
     @dE%GetHost#@%@harris fna%@men of war%@aaaaaaaaaaaaaaaaaaaaaaa%@3/8%@e2d1ef98-61d9@dE%GetH and then what looks like a truncated GetHost at the end?
     @dE%GetHost#@%@harris fna%@men of war%@generation x rooms%@3/8%@e2d1ef98-61d9@dE%GetH and then what looks like a truncated GetHost at the end?
    its sample data only

    thanks
    Phill.W
    Zvoni
    vbwins
    Last edited by jenniger9; Aug 15th, 2022 at 10:39 AM.

  15. #15
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,085

    Re: Select case with this

    Quote Originally Posted by jenniger9 View Post
    dont worry about it brother.
    if a new person was doing this,he will not come to this level yet working with these sort of data.
    Right, because obviously you're suddenly a VB6 expert.

    Or, are you a 58 year old with memory loss issues?

    Or a 76 year old with no time to learn how to program?

    Your evolution is fascinating.

  16. #16
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    728

    Re: Select case with this

    Or, perhaps, he shares the same "illness" as the character in The Time Traveller's Wife, who finds himself unexpectedly and randomly "bouncing" around in time? That would mess up anybody's development ethos.
    Can you imagine suddenly finding yourself, say, in the 1980's armed [only] with your current software development skills! Fish out of water, or what?

    Regards, Phill W.

  17. #17

    Thread Starter
    Banned
    Join Date
    Jun 2022
    Posts
    149

    Re: Select case with this

    Quote Originally Posted by OptionBase1 View Post
    Right, because obviously you're suddenly a VB6 expert.

    Or, are you a 58 year old with memory loss issues?

    Or a 76 year old with no time to learn how to program?

    Your evolution is fascinating.
    there is a glitch in the system this is why there is an age difference.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width