Results 1 to 26 of 26

Thread: How to Only Extract Arrays with no addtional String in the Line of Multiline Textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    How to Only Extract Arrays with no addtional String in the Line of Multiline Textbox

    Hello

    This thread is Slightly different from my earlier thread from followinghttps://www.vbforums.com/showthread....lays-only-last

    Would Like to only extract Arrays with no addtional String in the Line of Multiline Textbox
    Reference No.:
    From Account.:
    Card No.: 6357262XXXXXX975
    Card Type: XXXX CARD
    Last Statement Bal: 32,069.00

    Result
    Reference No.:
    From Account.:
    Code:
    Dim mustContain() As String = {"Reference No.:", "From Account.:",  "Card No.:",  "Card Type:",  "Last Statement Bal:"}
    Dim lines As List(Of String) = txtBx3.Lines.ToList
    lines.RemoveAll(Function(l) mustContain.Any(Function(s) l.Contains(s)))
    txtBx4.Lines = lines.ToArray
    The above will Remove All Arrays with lines and txtBx4.Lines will Remain Blank

    any syntax you recommend as against lines.RemoveAll(Function(l) mustContain.Any(Function(s) l.Contains(s))) which reomved all.

    SamD
    133
    Last edited by SamDsouza; May 20th, 2023 at 04:47 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,199

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Change...

    Code:
    lines.RemoveAll(Function(l) mustContain.Any(Function(s) l.Contains(s)))
    To...

    Code:
    lines = lines.Where(Function(l) mustContain.Any(Function(s) l.Contains(s)))

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    .Paul
    Thanks for the input But
    Change...

    Code:
    lines.RemoveAll(Function(l) mustContain.Any(Function(s) l.Contains(s)))
    To...
    [CODE]
    lines = lines.Where(Function(l) mustContain.Any(Function(s) l.Contains(s)))
    [CODE]
    FYI it gave me the Error as
    Option Strict On disallows implicit conversions from 'IEnumerable(Of String)' to 'List(Of String)'
    So i changed the following to
    Code:
    Dim mustContain() As String = {"Reference No.:", "From Account.:",  "Card No.:",  "Card Type:",  "Last Statement Bal:"}
    Dim lines As List(Of String) = txtBx4.Lines.ToList
    lines.Where(Function(l) mustContain.Any(Function(s) l.Contains(s)))
    txtBx4.Lines = lines.ToArray
    The above modification takes the full List of txtbx4.

    What if the case was like
    Card No.: 6357262XXXXXX975
    Card Type: XXXX CARD
    Last Statement Bal: 32,069.00
    And displays the Result as below
    Reference No.:
    From Account.:
    SamD
    134

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,199

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    lines = lines.Where(Function(l) mustContain.Any(Function(s) l.Contains(s))).ToList

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,199

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    BTW, your question doesn't make sense. An array is a collection of items. You want to extract a set of lines, which have a similarity with a set of strings stored in an array.

    You want to extract a set of lines (strings) from a TextBox's Lines array.

    Strings are single.
    An array of strings can contain one or many strings.

    Similarly the letters 'ABC' or 'DEF' are not alphabets. They are strings of alphabetical letters.
    The alphabet is the 26 letters from a-z...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    BTW, your question doesn't make sense. An array is a collection of items. You want to extract a set of lines, which have a similarity with a set of strings stored in an array.

    You want to extract a set of lines (strings) from a TextBox's Lines array.
    .Paul

    Sir, You are absolutely right. I completely missed the oppurtunity to frame the question in the right direction.
    I thougth may be my question would help me a bit. But now of no use.
    Inconvenince regretted.

    What i thought was with the question raised as per the thread would help me partly in resolving.
    In fact I wanted to achieve to Compare The lines of Textbox which contained the defined String Arrays with (Split String as List) not mentioned in any posts of this thread.

    With this I think I should post new thread.

    SamD
    135

  7. #7
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,980

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Quote Originally Posted by SamDsouza View Post

    With this I think I should post new thread.

    SamD
    135
    you have atleast 3-4 Threads with the same Topic, perhaps you want to think of a Plan B
    Last edited by ChrisE; May 24th, 2023 at 10:33 AM.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    ChrisE

    you have atleast 3-4 Threads with the same Topic, perhaps you want to think of a Plan B
    Thanks
    Unfortunately 3-4 Threads would not have been raised if had I had understood the difference between arrays and list and their respective syntaxes. Confusion led there. Then came the part of "Intersect" "Except" this also consumed time. It took me few days to absorb.
    As and when things started to clear. Threads were raised.

    Ok Then as per Plan B:
    I thought of creating Additional String which then is splitted
    Match the Lines of Textbox with splitted String with defined string arrays
    Get Msgbox to display of the Missing defined String arrays or Lines with String Arrays

    Hope my above logic is in right direction

    I partly coded as below:

    Code:
    Dim mustContain() As String = {"Reference No.:", "From Account.:",  "Card No.:",  "Card Type:",  "Last Statement Bal:"}
    Dim TosplitStr As String = "Reference No.:, From Account.:, Card No.:, Card Type:, Last Statement Bal:")
    Dim SplittedString = TosplitStr.Split(New Char() {","c}) 
    Dim lines As List(Of String) = txtBx4.Lines.ToList
    lines.Where(Function(l) mustContain.Any(Function(s) l.Contains(s)))
    txtBx4.Lines = lines.ToArray
    So therefore

    Splitted String or with defined in mustContain
    Reference No.:
    From Account.:
    Card No.:
    Card Type:
    Last Statement Bal:
    Values in Textbox
    Card No.: 6357262XXXXXX975
    Card Type: XXXX CARD
    Last Statement Bal: 32,069.00
    Desired Result in Msgbox of Missing Values or Lines
    Reference No.:
    From Account.:
    SamD
    136
    Last edited by SamDsouza; May 25th, 2023 at 07:23 AM.

  9. #9
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,173

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    You don't need these two lines:
    Code:
    Dim TosplitStr As String = "Reference No.:, From Account.:, Card No.:, Card Type:, Last Statement Bal:")
    Dim SplittedString = TosplitStr.Split(New Char() {","c})
    You never use SplittedString; it ends up containing exactly what's in mustContain... both are an array of String with the same contents.

    Your .where line should work ... although I'd use .BeginsWith and not .Contains, but that's just me.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,199

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    lines.Where won’t work…
    It has to be lines = lines.Where

  11. #11
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,173

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    True, true, true... I was mostly focusing on what came after and the mental acrobats that come with it, that I didn't realize it wasn't being re-assigned to a variable.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,540

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    At this point, I'm genuinely curious what, exactly, the end goal of all of these threads are for. Like, what is the actual use case of this quasi-nonsensical input string matching?

    If this is for real code that is actually going to be used by real people potentially typing in real things in a real TextBox, then the code is going to blow up pretty quickly once your rigid capitalization, abbreviation, punctuation, etc. rules are strayed from.

    I mean, any entry level VB.NET Programming 101 class is going to teach you that, if you have 5 distinct pieces of input you want from the user, you have 5 separate input fields (usually TextBoxes) for them to enter them. You don't have a single multiline TextBox where they blast in a bunch of lines of information, and then you struggle to parse out each line and populate the values on the back end by identifying where they were entered by the user.

  13. #13
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,980

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Quote Originally Posted by SamDsouza View Post

    Hope my above logic is in right direction

    SamD
    136
    this is the 5th Thread on this Topic, do you think you are heading in the right direction ? to try and validate a multiline Textbox or
    Richtextbox with xx possibilities is the wrong way to go.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Dear All

    It is pertaining to Multiline Textbox
    Code:
    Dim mustContain() As String = {"Reference No.:", "From Account.:",  "Card No.:",  "Card Type:",  "Last Statement Bal:"}
    Dim lines As List(Of String) = txtBx3.Lines.ToList
    lines = lines.Where(Function(l) mustContain.Any(Function(s) l.Contains(s))).ToList
    
    Dim resultRemaining = mustContain.Except(lines)
    
    Msgbox(String.Join(Enviornment.NewLine, resultRemaining.ToArray)
    Also used below before the Line of 'Except'
    Code:
    lines = lines.Where(Function(l) Not mustContain.Any(Function(s) l.Contains(s))).ToList
    Unfortunately Result is same

    Therefor Before implementing the For Each item in......Loop Wanted to check if Array values Matches in the lines of Textbox
    The above Code Displays the msg of mustContain Values Only and it does not match any mustContain Array values in the Lines of Textbox
    ie why did not implement For Each..... Loop

    Asking Generally Does This Match for eg. "Card No.:" with "Card No.: 6357262XXXXXX975"

    So therefore in short
    Reference No.:
    From Account.:
    Card No.: 6357262XXXXXX975
    Card Type: XXXX CARD
    Last Statement Bal: 32,069.00
    above lines of Textbox did not match below with Each Array Values
    Reference No.:
    From Account.:
    Card No.:
    Card Type:
    Last Statement Bal:
    If something concrete MATCH comes up then will be worthwhile using Instersect and Except and For Each...... Loop

    SamD
    137

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

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Quote Originally Posted by SamDsouza View Post
    Reference No.:
    From Account.:
    Card No.:
    Card Type:
    Last Statement Bal:
    Presumably you have a period after "No" because it is an abbreviation of Number. But then, you also have a period after "Account", for seemingly no reason, and then you don't have a period after "Bal", which is also an abbreviation. So your formatting is an inconsistent mess.

    After all of these similar threads of yours over the past several months, where you seem to be accomplishing nothing, you owe us all an explanation of what problem it is you are trying to solve. Stop telling is how you are trying to solve this mysterious problem, tell us what the the scenario is, and what the end goal is. Because I'm convinced that you are going about whatever it is you are trying to do in entirely the wrong way.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Option Base1
    tell us what the the scenario is, and what the end goal is. Because I'm convinced that you are going about whatever it is you are trying to do in entirely the wrong way
    Scenario 1:
    1. Against the Defined Array Strings / or Defined List of Strings
    Would like to check in the Lines of TextBox against Which Defined Array Strings / Defined List of Strings Exists in Lines with Addtional Text
    For Eg
    Card No.: 6357262XXXXXX975
    Card Type: XXXX CARD
    Last Statement Bal: 32,069.00

    Once Found ie Card No.: Card Type: and Last Statement Bal: with additional text like above
    Remove Them or Display the Balance with an Indication /MSG Like Below the Defined Array Strings/ Defined List of Strings WITHOUT additional Text in Lines
    Reference No.:
    From Account.:

    Scenario 2:
    If All Defined Array Strings / or Defined List of Strings in All Lines of Textbox Exists with Additional Text Then indication / msgbox Everything Exists

    Scenario 3:
    If Defined Array Strings / or Defined List of Strings in All Lines of Textbox DOES NOT Exists with Additional Text
    Then indication / msgbox Nothing Exists

    SamD
    138
    Last edited by SamDsouza; May 31st, 2023 at 12:56 AM.

  17. #17
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,540

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Nope.

    All along you've been essentially asking us to help you figure out the best way to connect popsicle sticks to hula hoops. It isn't until the end goal of "building a shed" is revealed that we could tell you that, you are doing it all wrong to begin with.

    Where is this String data coming from to begin with that you need to do this nonsense with? Because, I suspect it is coming from other code of yours.

    I suspect that you are creating this own issue yourself in your own code for no reason whatsoever. Like, imagine you have code that translates the number 19 to the English word "Nineteen". But then, further down your code, you need the value back to a numeric value 19. So you ask for help translating English words to numbers. But you neglect to tell us that, your code had access to the numeric value all along, and all you had to do was retain the original numeric value somewhere. But instead, you made it hard on yourself, by translating 19 to "Nineteen", discarding the numeric value and storing that String value, and then creating the artificial problem of translating "Nineteen" back to 19.

    So, when I say, you need to explain us what your end goal is, it has nothing to do with comparing an Array of Strings to the contents of the TextBox. Nothing. It is, you need to take one or several steps back and explain why you think that your program needs to do that in the first place, where this data is coming from, and what happens with it after this checking is taking place. Because I guarantee you that your approach to whatever mystery problem you are trying to solve is all wrong.

    I'm completely done trying to assist you any further with this. Good luck.

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Option Base1
    Where is this String data coming from to begin with that you need to do this nonsense with? Because, I suspect it is coming from other code of yours.
    String Data is being Copied and it is not coming from anywhere as earlier mentioned dont remember which thread of mine . FYI I've NOT CODED for the Same.
    just some Text copied with the defined String Arrays Values which are defined to Check the MATCH if Full exists or partly exists or no existence.
    It is your will to suspect or not to suspect.
    Its Perfectly Fine if you cannot assist further. I really appreciate your direct pointing on
    you are doing it all wrong to begin with.
    One observation many of your replies you are not able to help me further. BUT Still you Reply. Oh Dear I love that

    Thanks for your Comments and inputs
    Will Await if someone wants to correct me.

    SamD
    139

  19. #19
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,540

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Quote Originally Posted by SamDsouza View Post
    String Data is being Copied and it is not coming from anywhere as earlier mentioned dont remember which thread of mine.
    It can't be getting copied and at the same time not coming from anywhere. Where is it coming from?

    Edit: From the thread below, it seems that the data you are working with is from some sort of external file (original source of said file(s) not mentioned, whether you receive them as-is or if you are generating them with some other code).

    https://www.vbforums.com/showthread....nes&highlight=

    Good luck. Hope you get it sorted.
    Last edited by OptionBase1; May 31st, 2023 at 09:54 AM.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    OptionBase1

    Really appreciate your clarification
    You are absolutely right. and How Could I forget my own thread ?
    https://www.vbforums.com/showthread....nes&highlight=

    FYI so For all these days i've been copying the Formatted text from the Text file into the textbox for this particular part to be achieved. Hence I created new project. Struggling and Struggling and completely engrossed in the new project.

    SamD
    140

  21. #21
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,540

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    So, you have a text file that contains a number of "logs" of some sort of transaction history. Each individual transaction should occupy 5 lines in the file, looking something like this:

    Code:
    Reference No.: XXX
    From Account.: XXX
    Card No.: XXX
    Card Type: XXX CARD
    Last Statement Bal: XXX
    Is that correct so far? And, it seems like, the issue you have is that some of these transactions are "incomplete"? Meaning, perhaps one or more of the lines above are missing for a single transaction. And you are trying to flag where, in these files, these "partial" transactions exist, in order to perform some sort of additional follow-up or auditing on them? Is that correct?

    If so, then the above breakdown of the problem is exactly what I was trying to get you to explain earlier, and what you should have been explaining in your many threads about this problem from the beginning.

    Good luck.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Optionbase1
    Is that correct so far? And, it seems like, the issue you have is that some of these transactions are "incomplete"? Meaning, perhaps one or more of the lines above are missing for a single transaction. And you are trying to flag where, in these files, these "partial" transactions exist, in order to perform some sort of additional follow-up or auditing on them? Is that correct?
    Code:
    Reference No.: 
    From Account.: 
    Card No.: XXX
    Card Type: XXX CARD
    Last Statement Bal: XXX
    
    Yes, Trying to Flag out or MsgOut the Following ie to display lines without Lines Containing XXX for eg below
    Code:
    Reference No.: 
    From Account.: 
    
    SamD
    141

  23. #23
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,199

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Code:
    ' *****BE SURE TO USE THE CORRECT TEXTBOX NAME*****
    Dim theTextBoxToLookIn As TextBox = txtbx3
    
    Dim mustContain() As String = {"Reference No.:", "From Account.:", "Card No.:", "Card Type:", "Last Statement Bal:"}
    
    ' THIS COUNTS THE LINES THAT HAVE SOME TEXT IN THEM
    Dim filledLines As Integer = theTextBoxToLookIn.Lines.Where(Function(l) l.Trim <> "").Count
    
    ' THIS GETS THE HEADINGS FROM THE LINES THAT HAVE NO VALUES
    Dim NoValue() As String = theTextBoxToLookIn.Lines.Where(Function(l) mustContain.Any(Function(s) l.Trim = s)).ToArray
    
    If NoValue.Length = filledLines Then
        MsgBox("NONE of the lines have values")
    ElseIf NoValue.Length = 0 Then
        MsgBox("ALL of the lines have values")
    Else
        MsgBox(String.Join(Environment.NewLine, NoValue))
    End If

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    May 2021
    Posts
    142

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    .Paul

    Thank you so much for your always Short and Precise written Code.
    Only thing missing here was the MissingVaLue or Non Matched Value which i have been struggling over my last few Threads.
    Although i missed out to point in post #22. Agreeing to OptionBase1. No doubt that text is coming from TextFile which is being copied in TextBox.
    For Eg what if i missout to copy the Lines in Textbox with Defined Array String copying in textbox. Can Appropriate msgbox be displayed in your written code for the missing lines with Defined Array Strings either with additional text or no additional text
    For Eg
    Code:
    From Account.: 
    Card Type: XXX CARD
    
    Below Missing Lines with Values and No Values
    Code:
    Reference No.: 
    Card No.: XXX
    Last Statement Bal: XXX
    
    Also can you refer to some URL where i go through all One Line Syntaxes / LINQ etc

    Hope this is my Last Query for this Thread ?

    SamD
    142

  25. #25
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,199

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Quote Originally Posted by SamDsouza View Post
    ... For Eg what if i missout to copy the Lines in Textbox with Defined Array String copying in textbox. Can Appropriate msgbox be displayed in your written code for the missing lines with Defined Array Strings either with additional text or no additional text
    It's not clear what you're asking.

    Quote Originally Posted by SamDsouza View Post
    Also can you refer to some URL where i go through all One Line Syntaxes / LINQ etc
    There's no one site that teaches all varieties of LINQ/Lambda. Start with the easier queries. Practice makes perfect.

  26. #26
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,540

    Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text

    Quote Originally Posted by SamDsouza View Post
    Also can you refer to some URL where i go through all One Line Syntaxes / LINQ etc
    As I've pointed out before, and will continue to point out even if it goes unheeded, your goal should not be to try to one-line this code using syntax that you don't seem to completely grasp. It should be to write code that you understand, and can explain, line-by-line, command-by-command, exactly what it is doing.

    Quote Originally Posted by SamDsouza View Post
    Hope this is my Last Query for this Thread ?
    You can always start yet another one...

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