-
May 20th, 2023, 04:40 AM
#1
Thread Starter
Addicted Member
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.
-
May 20th, 2023, 11:33 AM
#2
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)))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 21st, 2023, 06:05 PM
#3
Thread Starter
Addicted Member
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
-
May 21st, 2023, 06:28 PM
#4
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 21st, 2023, 11:11 PM
#5
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 24th, 2023, 06:39 AM
#6
Thread Starter
Addicted Member
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
-
May 24th, 2023, 10:29 AM
#7
Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text
 Originally Posted by SamDsouza
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.
-
May 25th, 2023, 07:18 AM
#8
Thread Starter
Addicted Member
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.
-
May 25th, 2023, 08:53 AM
#9
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
-
May 25th, 2023, 11:20 AM
#10
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 25th, 2023, 11:24 AM
#11
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
-
May 25th, 2023, 12:02 PM
#12
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.
-
May 26th, 2023, 03:52 AM
#13
Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text
 Originally Posted by SamDsouza
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.
-
May 30th, 2023, 01:07 AM
#14
Thread Starter
Addicted Member
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
-
May 30th, 2023, 08:19 AM
#15
Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text
 Originally Posted by SamDsouza
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.
-
May 31st, 2023, 12:51 AM
#16
Thread Starter
Addicted Member
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.
-
May 31st, 2023, 05:11 AM
#17
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.
-
May 31st, 2023, 09:37 AM
#18
Thread Starter
Addicted Member
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
-
May 31st, 2023, 09:44 AM
#19
Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text
 Originally Posted by SamDsouza
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.
-
May 31st, 2023, 10:52 PM
#20
Thread Starter
Addicted Member
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
-
Jun 1st, 2023, 08:35 AM
#21
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.
-
Jun 2nd, 2023, 12:36 AM
#22
Thread Starter
Addicted Member
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
-
Jun 2nd, 2023, 03:12 AM
#23
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 3rd, 2023, 01:12 AM
#24
Thread Starter
Addicted Member
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
-
Jun 3rd, 2023, 04:09 AM
#25
Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text
 Originally Posted by SamDsouza
... 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.
 Originally Posted by SamDsouza
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.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 3rd, 2023, 07:22 AM
#26
Re: How to Only Extract Arrays with no addtional String in the Line of Multiline Text
 Originally Posted by SamDsouza
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.
 Originally Posted by SamDsouza
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|