-
Jul 30th, 2021, 01:59 AM
#1
Thread Starter
New Member
user enters % sign in search form. wildcard.
Code:
Dim searchText = txbBILL_NR.Text
Dim cleanSearchText = searchText.Replace("%", String.Empty)
If cleanSearchText.Length = 0 OrElse cleanSearchText.Length >= 4 Then
If searchText = cleanSearchText Then
searchText &= "%"
End If
Search()
Else
MessageBox.Show("enter at least 4 numbers")
End If
I have this method for search button in my app.
So, I already have the If condition where user enters a minimum number 4 of characters to select entries.
I need to re-make validation for percent sign. I figured out, that is kinda wildcard, but I do not understand how I can get those situations:
Could anyone please give me some advice where to look at.
1. user adds "%" sign after txbBILL_NR - the system does not add additional "%" in the background, txbBILL_NR with identical part number are found and reflected in the list.
2. the user has not added the "%" sign after the txbBILL_NR - the system adds an additional "%" in the background, txbBILL_NR with identical no. parts are found and listed. The "%" character does not need to be represented by the user;
3.user added"%" sign at the beginning or middle of txbBILL_NR - the system does not add an additional "%" in the background, txbBILL_NR with identical part number are found and reflected in the list (no changes required);
4. The "%" system only needs to be marked if the user has entered at least 4 characters in the txbBILL_NR field (assuming that the invoice number cannot be shorter than 4 characters.
If the user has entered at least 4 characters (whether they are starting characters or from the middle) and "%" is added to the beginning or middle of these symbols, the system does not add an additional "%" in the background the invoice (s) with the identical part (symbol) part are found and reflected in the list.
There are some criteria about % sign, like:
1234%
%1234
12%34
1234
and so on. I would like to understand that implementation into code, how I. can use that wildcard if user enters it, and when not. I understand that I need to use if...else conditions for this, but how correctly solve % sign stuff, no idea.
Maybe some advice from you will help me.
-
Jul 30th, 2021, 02:44 AM
#2
Re: user enters % sign in search form. wildcard.
The code, which I provided at Stack Overflow, already does what you describe. If the user includes a wildcard anywhere then no changes are made to the search text and if they don't include a wildcard then one is appended to the text they did enter. Did you bother to run the code and look at the result with your eyes, like I told you at SO? It would appear not.
The obvious issue here is that, as I already explained, the text you want to use to search is in searchText once that code executes. It should, therefore, be obvious that you need to use the contents of searchText in your Search method. As it stands, you're obviously not doing that because you're not passing it into Search as an argument and you're also not assigning it to a field where Search can get it. That's what you need to fix, i.e. you need to actually do what I already told you to do: use the value of searchText in Search.
That said, you haven;t bothered to show or explain what Search does, either here or at SO. I'm assuming that it queries a database, in which case the % wildcard will work as is. If that's not the case then you'll need to process it somehow but we shouldn't have to guess either way.
-
Jul 30th, 2021, 02:58 AM
#3
Thread Starter
New Member
Re: user enters % sign in search form. wildcard.
Thank you, I already that, run the code, followed what happens on one or other situation, but in my search method Bill_NR is defined as textlike. and textlike is as a string private prop.
Attachment 181947Attachment 181948
If Bill_NR would be as textlike, then I got that system adds % in background and the "%" char does not need to be represented by the user;
In your code how I understand user enters that sign manually, it works, yes, thanks. But how I can blend it together - manually when user enters and default when system adds % sign.
-
Jul 30th, 2021, 03:03 AM
#4
Thread Starter
New Member
Re: user enters % sign in search form. wildcard.
I just found your courses https://www.homeandlearn.co.uk/NET/vbNet.html these are great! Really great resource.
-
Jul 30th, 2021, 03:12 AM
#5
Re: user enters % sign in search form. wildcard.
Originally Posted by EliLT
how I can blend it together
The code already does that. I'm done here.
Tags for this Thread
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
|