Click here to Skip to main content
16,021,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have three strings:

1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2 it can vary from 26 to 35 characters.

3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy it can vary from 26 to 35 characters.

bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq it can vary from 26 to 44 characters.

I want to check when I copy any of those string it says "true" when the lenght is between 26 and 36 (or 26-46 for the 3rd string for example).

It's not working, I don't know what's going on actually

What I have tried:

VB
TextBox1.Text = Clipboard.GetText 'It's using a timer to constantly get the clipboard text.

        If TextBox1.Text.StartsWith("1") Then
            If TextBox1.Text.Length = "26" Or "27" Or "28" Or "29" Or "30" Or "31" Or "32" Or "33" Or "34" Or "35" Then
                Label3.Text = "true"
            End If
        Else
            Label3.Text = "false"
        End If


        If TextBox1.Text.StartsWith("3") Then
            If Label2.Text = "26" Or "27" Or "28" Or "29" Or "30" Or "31" Or "32" Or "33" Or "34" Or "35" Then
                Label3.Text = "True"
            End If
        Else
            Label3.Text = "false"
        End If


        If TextBox1.Text.StartsWith("bc1") Then
            If TextBox1.Text.Length = "26" Or "27" Or "28" Or "29" Or "30" Or "31" Or "32" Or "33" Or "34" Or "35" Or "36" Or "37" Or "38" Or "39" Or "40" Or "41" Or "42" Or "43" Or "44" Then
                Label3.Text = "True"
            End If
        Else
            Label3.Text = "false"
        End If
Posted
Updated 20-Mar-20 8:40am
v2

I'd suggest to read about Select...Case Statement - Visual Basic | Microsoft Docs[^]

Usage:
VB.NET
Dim data As String() =
{
	"1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2", 'it can vary from 26 to 35 characters.
	"3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy", 'it can vary from 26 to 35 characters.
	"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq" 'it can vary from 26 to 44 characters.
}

Dim retVal As Boolean = False

For Each s As String In data
	Select Case s.Substring(0,1)
		Case "1", "3"
			retVal = (s.Length >=26 And s.Length<=35)

		Case "b"
			retVal = (s.Length >=26 And s.Length<=44)

	End Select
	Console.WriteLine(String.Format("{0} => {1}", s, retVal))
Next
 
Share this answer
 
Comments
Daniel André 20-Mar-20 15:02pm    
The strings I stated was just an example, it can vary.
Maciej Los 20-Mar-20 16:30pm    
So, what?
Firstly make sure all this has finished before the timer event fires again and restarts your function.

TextBox.Text.Length does not return a string so If TextBox1.Text.Length = "26" is the wrong thing to do.

When you say "not working" do you mean it won't compile? If I was writing those If-statements they would look something like
VB
If TextBox1.Text.Length = 26 Or TextBox1.Text.Length = 27 Or TextBox1.Text.Length = 28 Or TextBox1.Text.Length = 29 Or TextBox1.Text.Length = 30 Or TextBox1.Text.Length = 31 Or TextBox1.Text.Length = 32 Or TextBox1.Text.Length = 33 Or TextBox1.Text.Length = 34 Or TextBox1.Text.Length = 35 Then
Well actually, it wouldn't, it would look more like
VB
If TextBox1.Text.Length >= 26 and TextBox1.Text.Length <= 35

One final point - don't tag your question as C# if it's VB.NET!
 
Share this answer
 
VB
Dim length, value As Integer

If TextBox1.Text.StartsWith("1") Then
   length = TextBox1.Text.Length
   If length >= 26 And length <= 35 Then
      Label3.Text = "true"
   End If
Else
   Label3.Text = "false"
End If


If TextBox1.Text.StartsWith("3") Then
   If (Integer.TryParse(Label2.Text, value)) Then
      If value >= 26 And value <= 35 Then
         Label3.Text = "True"
      End If
   End If
Else
   Label3.Text = "false"
End If

If TextBox1.Text.StartsWith("bc1") Then
   length = TextBox1.Text.Length
   If length >= 26 And length <= 44 Then
      Label3.Text = "True"
   End If
Else
   Label3.Text = "false"
End If 

This could be further simplified (by using Else conditions for example), but since the logic does not appear quiteclear to me I did not optimize it.

Important thing is to compare integer values to integer values (not to strings), and to avoid writing the conditions by skipping the variable name (value >= 26 And value <= 44 instead of value >= 26 And <= 44.
 
Share this answer
 
v2
Comments
Daniel André 20-Mar-20 14:14pm    
Well, the bc1 string works but the rest gives me the "false" statement.
Any suggestion?
phil.o 20-Mar-20 15:01pm    
Yes, put a breakpoint and start debugging. Then correct the code to suit proper logic :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900