0

Am building a VB project. I have two textboxes:

Textbox1
Textbox2

I want, if the value of textbox1 equals to numbers between 10-20, the textbox2 to automatically display the word "Thanks".

I thought the code will be something like this:

If Textbox1.text = integer("10-20") then
Textbox2.text = "Thanks"
End if

But its not working. Do you have any idea how to fix this?

NineBerry
  • 20,173
  • 3
  • 50
  • 78
  • Thanks for the edit and the answer..... The question is solved now. Your code works perfect. Thanks @YowE3K – CodexxxToo Jan 21 '17 at 22:03
  • Welcome to Stack Overflow! If YowE3K's answer worked you should mark it as accepted by pressing the check mark on the post. Please have a look at the [Tour](http://stackoverflow.com/tour) for a little introduction to how this site works. – Visual Vincent Jan 22 '17 at 09:39
  • Also, you can write the comment directly on his answer instead of on your question. – Visual Vincent Jan 22 '17 at 09:41
  • @VisualVincent - Just FYI - I originally had my answer as a comment, so the "thanks" was posted before I wrote the actual "answer". (And that's probably why I won't get an "accepted answer" tick too.) – YowE3K Jan 22 '17 at 18:30

1 Answers1

1

If you know that Textbox1 contains numbers, but you are just wanting to test whether the values are between 10 and 20, you could do

If CInt(Textbox1.Text) >= 10 AndAlso CInt(Textbox1.Text) <= 20 Then
    Textbox2.Text = "Thanks"
End If

If you first need to check for the presence of numbers, rather than garbage, it gets a little bit messier.

YowE3K
  • 23,437
  • 7
  • 24
  • 37
  • I recommend you use [**`AndAlso`**](https://msdn.microsoft.com/en-us/library/cb8x3kfz.aspx) instead of `And` since the former is [**short-circuited**](http://stackoverflow.com/a/302067/3740093). Other than that, this is a nice answer! – Visual Vincent Jan 22 '17 at 09:44
  • 1
    @VisualVincent - Thanks - I've been using VBA for so long now (my employer thinks Visual Studio is a security risk !?!?) that I had forgotten that `AndAlso` and `OrElse` even existed. – YowE3K Jan 22 '17 at 18:28
  • Haha, what?! VBA is a bigger security risk than VS. ;) – Visual Vincent Jan 23 '17 at 07:19
  • @VisualVincent - Supposedly I could hack into all the other company systems using VS. (They don't seem to realise that, if I wanted to, I could simply write .Net code using Notepad, and then compile it, with the only downside being no IDE.) – YowE3K Jan 23 '17 at 08:20
  • They'll never fully understand how capable a dedicated/passionate programmer can be... **--** Speaking of hacking: I found a flaw in my college's system which allowed me to gain access to every computer on the network. I could literally do anything I wanted with them, so for testing purposes I wrote a trojan which I silently installed on some of the computers. It was easy to remove and pretty harmless (unless the wrong person gets access to it). **--** I notified the IT department about the flaw and it has since been fixed. – Visual Vincent Jan 23 '17 at 14:49