-
Aug 17th, 2021, 03:10 PM
#1
Thread Starter
Lively Member
[RESOLVED] Convert text box to integer
I am trying to compare 2 text fields that contain only numbers.
When the try to compare the bypass the code.
I tried the convert.toint32 but it gave me an error.
I tried the CInt but it also gave me an error.
-
Aug 17th, 2021, 03:26 PM
#2
Re: Convert text box to integer
Please post the code that you tried and post the error(s) you received.
-
Aug 17th, 2021, 04:16 PM
#3
Thread Starter
Lively Member
Re: Convert text box to integer
Code:
Convert.ToInt32(P1_FIRST.Text) = C11.Text
OR
Code:
CInt(P1_FIRST.Text) = C11.Text
IF (Convert.ToInt32(P1_FIRST.Text) > Convert.ToInt32(P1_SECOND.Text)
MESSAGEBOX.SHOW ("P1_FIRST.Text > P1_SECOND.Text)
END IF
OR
Code:
IF (CINT(P1_FIRST.Text) > CINT(P1_SECOND.Text)
MESSAGEBOX.SHOW ("P1_FIRST.Text > P1_SECOND.Text)
END IF
Last edited by dday9; Aug 17th, 2021 at 04:39 PM.
-
Aug 17th, 2021, 04:18 PM
#4
Re: Convert text box to integer
Post the actual text data that was in your text fields, and the text of the error message(s) that you got.
-
Aug 17th, 2021, 04:33 PM
#5
Re: Convert text box to integer
If you are relying on user input from a TextBox then you should use the TryParse method (documentation):
Code:
Dim input1, input2 As Integer
If (Integer.TryParse(TextBox1.Text, input1) AndAlso Integer.TryParse(TextBox2.Text, input2)) Then
' input1 = TextBox1.Text converted to an Integer
' input2 = TextBox2.Text converted to an integer
' do something like: If (input1 = input2) Then
End If
-
Aug 18th, 2021, 12:42 AM
#6
Re: Convert text box to integer
Originally Posted by wideminnow6970
Code:
Convert.ToInt32(P1_FIRST.Text) = C11.Text
OR
Code:
CInt(P1_FIRST.Text) = C11.Text
IF (Convert.ToInt32(P1_FIRST.Text) > Convert.ToInt32(P1_SECOND.Text)
MESSAGEBOX.SHOW ("P1_FIRST.Text > P1_SECOND.Text)
END IF
OR
Code:
IF (CINT(P1_FIRST.Text) > CINT(P1_SECOND.Text)
MESSAGEBOX.SHOW ("P1_FIRST.Text > P1_SECOND.Text)
END IF
Is it just me or is all of that code invalid?
The first line looks to be an invalid assignment and both of the If blocks are missing the Then keyword.
The 1st If block also has a missing " so at least two syntax errors in that one
I would expect all of those to give an error though the first one would give a different error than the other two.
It would help if you also stated the error(s) that you recieve.
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
|