I can't figured out how do I properly place the code block of “IF statement”
All I want is to have the If statement code block properly be executed. Supposedly the idea was very simple.
On the quantity portion:
if it is not a number, it returns an error
else if it is a number which is above 0, message box "accepted"
else if the number is zero, then message box "quantity is 0"
else if the number is below zero, then message box "Error: quantity below zero"
However, when I try to run the program, when I try to input a number equals to RequestQuantity3TxtBx or below 0, it doesn't do anything at all.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num1 = RequestQuantity2TxtBx.Text
num2 = RequestQuantityTxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
If RequestQuantity3TxtBx.Text > 0 Then
If RequestQuantity3TxtBx.Text < 0 Then
If RequestQuantity3TxtBx.Text = 0 Then
MessageBox.Show("Quantity = 0")
Else
'------if quantity below 0
MessageBox.Show("Error: Quantity below 0")
End If
Else
'------if quantity is equals to 1
MessageBox.Show("Accepted")
End If
End If
Else
MessageBox.Show("ERROR")
End If
vb.net
add a comment |
All I want is to have the If statement code block properly be executed. Supposedly the idea was very simple.
On the quantity portion:
if it is not a number, it returns an error
else if it is a number which is above 0, message box "accepted"
else if the number is zero, then message box "quantity is 0"
else if the number is below zero, then message box "Error: quantity below zero"
However, when I try to run the program, when I try to input a number equals to RequestQuantity3TxtBx or below 0, it doesn't do anything at all.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num1 = RequestQuantity2TxtBx.Text
num2 = RequestQuantityTxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
If RequestQuantity3TxtBx.Text > 0 Then
If RequestQuantity3TxtBx.Text < 0 Then
If RequestQuantity3TxtBx.Text = 0 Then
MessageBox.Show("Quantity = 0")
Else
'------if quantity below 0
MessageBox.Show("Error: Quantity below 0")
End If
Else
'------if quantity is equals to 1
MessageBox.Show("Accepted")
End If
End If
Else
MessageBox.Show("ERROR")
End If
vb.net
If you we're just commenting on my post just to insult me, that's totally fine, cause that code block is just a partial, That code block is not just a test for a Textbox thing, I've intentionally omitted the true function as to why I have three options(0, <0, >0). I understand your point however, you have the worst attitude so far. I post that one cause I seek some help.
– Rael
Nov 21 '18 at 21:14
To all answer posters,.IsNumericis left over from vb6. With .net we haveInteger.TryParseUsing the .net methods will allow you to move to other .net languages with understanding. So many examples are now written in C# that it is good to know the .net way. Also, I read that the .TryParse methods have speed improvements.
– Mary
Nov 21 '18 at 22:13
2
@Rael Please don't confuse instruction with insults. Usually the best teachers are concise and to the point. On another note, please turn on Option Strict. A TextBox's Text property is a String. A user can type anything into a text box and trying to do numerical comparisons with strings can lead to trouble.
– Mary
Nov 21 '18 at 22:22
add a comment |
All I want is to have the If statement code block properly be executed. Supposedly the idea was very simple.
On the quantity portion:
if it is not a number, it returns an error
else if it is a number which is above 0, message box "accepted"
else if the number is zero, then message box "quantity is 0"
else if the number is below zero, then message box "Error: quantity below zero"
However, when I try to run the program, when I try to input a number equals to RequestQuantity3TxtBx or below 0, it doesn't do anything at all.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num1 = RequestQuantity2TxtBx.Text
num2 = RequestQuantityTxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
If RequestQuantity3TxtBx.Text > 0 Then
If RequestQuantity3TxtBx.Text < 0 Then
If RequestQuantity3TxtBx.Text = 0 Then
MessageBox.Show("Quantity = 0")
Else
'------if quantity below 0
MessageBox.Show("Error: Quantity below 0")
End If
Else
'------if quantity is equals to 1
MessageBox.Show("Accepted")
End If
End If
Else
MessageBox.Show("ERROR")
End If
vb.net
All I want is to have the If statement code block properly be executed. Supposedly the idea was very simple.
On the quantity portion:
if it is not a number, it returns an error
else if it is a number which is above 0, message box "accepted"
else if the number is zero, then message box "quantity is 0"
else if the number is below zero, then message box "Error: quantity below zero"
However, when I try to run the program, when I try to input a number equals to RequestQuantity3TxtBx or below 0, it doesn't do anything at all.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num1 = RequestQuantity2TxtBx.Text
num2 = RequestQuantityTxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
If RequestQuantity3TxtBx.Text > 0 Then
If RequestQuantity3TxtBx.Text < 0 Then
If RequestQuantity3TxtBx.Text = 0 Then
MessageBox.Show("Quantity = 0")
Else
'------if quantity below 0
MessageBox.Show("Error: Quantity below 0")
End If
Else
'------if quantity is equals to 1
MessageBox.Show("Accepted")
End If
End If
Else
MessageBox.Show("ERROR")
End If
vb.net
vb.net
edited Nov 21 '18 at 12:42
Blackwood
4,042122238
4,042122238
asked Nov 21 '18 at 7:08
Rael
74
74
If you we're just commenting on my post just to insult me, that's totally fine, cause that code block is just a partial, That code block is not just a test for a Textbox thing, I've intentionally omitted the true function as to why I have three options(0, <0, >0). I understand your point however, you have the worst attitude so far. I post that one cause I seek some help.
– Rael
Nov 21 '18 at 21:14
To all answer posters,.IsNumericis left over from vb6. With .net we haveInteger.TryParseUsing the .net methods will allow you to move to other .net languages with understanding. So many examples are now written in C# that it is good to know the .net way. Also, I read that the .TryParse methods have speed improvements.
– Mary
Nov 21 '18 at 22:13
2
@Rael Please don't confuse instruction with insults. Usually the best teachers are concise and to the point. On another note, please turn on Option Strict. A TextBox's Text property is a String. A user can type anything into a text box and trying to do numerical comparisons with strings can lead to trouble.
– Mary
Nov 21 '18 at 22:22
add a comment |
If you we're just commenting on my post just to insult me, that's totally fine, cause that code block is just a partial, That code block is not just a test for a Textbox thing, I've intentionally omitted the true function as to why I have three options(0, <0, >0). I understand your point however, you have the worst attitude so far. I post that one cause I seek some help.
– Rael
Nov 21 '18 at 21:14
To all answer posters,.IsNumericis left over from vb6. With .net we haveInteger.TryParseUsing the .net methods will allow you to move to other .net languages with understanding. So many examples are now written in C# that it is good to know the .net way. Also, I read that the .TryParse methods have speed improvements.
– Mary
Nov 21 '18 at 22:13
2
@Rael Please don't confuse instruction with insults. Usually the best teachers are concise and to the point. On another note, please turn on Option Strict. A TextBox's Text property is a String. A user can type anything into a text box and trying to do numerical comparisons with strings can lead to trouble.
– Mary
Nov 21 '18 at 22:22
If you we're just commenting on my post just to insult me, that's totally fine, cause that code block is just a partial, That code block is not just a test for a Textbox thing, I've intentionally omitted the true function as to why I have three options(0, <0, >0). I understand your point however, you have the worst attitude so far. I post that one cause I seek some help.
– Rael
Nov 21 '18 at 21:14
If you we're just commenting on my post just to insult me, that's totally fine, cause that code block is just a partial, That code block is not just a test for a Textbox thing, I've intentionally omitted the true function as to why I have three options(0, <0, >0). I understand your point however, you have the worst attitude so far. I post that one cause I seek some help.
– Rael
Nov 21 '18 at 21:14
To all answer posters,
.IsNumeric is left over from vb6. With .net we have Integer.TryParse Using the .net methods will allow you to move to other .net languages with understanding. So many examples are now written in C# that it is good to know the .net way. Also, I read that the .TryParse methods have speed improvements.– Mary
Nov 21 '18 at 22:13
To all answer posters,
.IsNumeric is left over from vb6. With .net we have Integer.TryParse Using the .net methods will allow you to move to other .net languages with understanding. So many examples are now written in C# that it is good to know the .net way. Also, I read that the .TryParse methods have speed improvements.– Mary
Nov 21 '18 at 22:13
2
2
@Rael Please don't confuse instruction with insults. Usually the best teachers are concise and to the point. On another note, please turn on Option Strict. A TextBox's Text property is a String. A user can type anything into a text box and trying to do numerical comparisons with strings can lead to trouble.
– Mary
Nov 21 '18 at 22:22
@Rael Please don't confuse instruction with insults. Usually the best teachers are concise and to the point. On another note, please turn on Option Strict. A TextBox's Text property is a String. A user can type anything into a text box and trying to do numerical comparisons with strings can lead to trouble.
– Mary
Nov 21 '18 at 22:22
add a comment |
2 Answers
2
active
oldest
votes
You could put some Validation in the TextBox to make sure that the user will enter a number instead of a character.
Private Sub RequestQuantityTxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantityTxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Private Sub RequestQuantity2TxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantity2TxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Then you can put the IF ELSE statement.
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSIF RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
ELSE
MsgBox("ERROR: It's not a number")
END IF
OR you can just replace your code with this.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num2 = RequestQuantityTxtBx.Text
IF IsNumeric(RequestQuantity2TxtBx.Text)
num1 = RequestQuantity2TxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSE RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
Thanks. This is the right syntax that I'm looking for
– Rael
Nov 21 '18 at 21:19
add a comment |
This code might be another option to full fill your requirement.
' Validate if the inputs are numeric
If IsNumeric(RequestQuantityTxtBx.Text) AndAlso IsNumeric(RequestQuantityTxtBx2.Text) Then
' Cast the input to double to accomodate decimal input
Dim num1 As Double = CType(RequestQuantityTxtBx.Text, Double)
Dim num2 As Double = CType(RequestQuantityTxtBx2.Text, Double)
' Sum the input and assign the resul to the RequestQuantityTxtBx3
Dim num3 As Double = num1 + num2
RequestQuantityTxtBx3.Text = num3
' Perform validation to show appropriate message in the messagebox
If num3 > 0 Then
MsgBox("Accepted")
ElseIf num3 = 0 Then
MsgBox("Quantity is 0")
ElseIf num3 < 0 Then
MsgBox("Quantity below 0")
End If
Else
' Display error if the needed input is not numeric
MsgBox("Error")
End If
Hopefully it helps. Thanks.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406886%2fi-cant-figured-out-how-do-i-properly-place-the-code-block-of-if-statement%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could put some Validation in the TextBox to make sure that the user will enter a number instead of a character.
Private Sub RequestQuantityTxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantityTxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Private Sub RequestQuantity2TxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantity2TxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Then you can put the IF ELSE statement.
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSIF RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
ELSE
MsgBox("ERROR: It's not a number")
END IF
OR you can just replace your code with this.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num2 = RequestQuantityTxtBx.Text
IF IsNumeric(RequestQuantity2TxtBx.Text)
num1 = RequestQuantity2TxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSE RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
Thanks. This is the right syntax that I'm looking for
– Rael
Nov 21 '18 at 21:19
add a comment |
You could put some Validation in the TextBox to make sure that the user will enter a number instead of a character.
Private Sub RequestQuantityTxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantityTxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Private Sub RequestQuantity2TxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantity2TxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Then you can put the IF ELSE statement.
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSIF RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
ELSE
MsgBox("ERROR: It's not a number")
END IF
OR you can just replace your code with this.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num2 = RequestQuantityTxtBx.Text
IF IsNumeric(RequestQuantity2TxtBx.Text)
num1 = RequestQuantity2TxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSE RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
Thanks. This is the right syntax that I'm looking for
– Rael
Nov 21 '18 at 21:19
add a comment |
You could put some Validation in the TextBox to make sure that the user will enter a number instead of a character.
Private Sub RequestQuantityTxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantityTxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Private Sub RequestQuantity2TxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantity2TxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Then you can put the IF ELSE statement.
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSIF RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
ELSE
MsgBox("ERROR: It's not a number")
END IF
OR you can just replace your code with this.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num2 = RequestQuantityTxtBx.Text
IF IsNumeric(RequestQuantity2TxtBx.Text)
num1 = RequestQuantity2TxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSE RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
You could put some Validation in the TextBox to make sure that the user will enter a number instead of a character.
Private Sub RequestQuantityTxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantityTxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Private Sub RequestQuantity2TxtBx_TextChanged(sender As Object, e As EventArgs) Handles RequestQuantity2TxtBx.TextChanged
If Not IsNumeric(RequestQuantityTxtBx.Text) Then
MsgBox("This is not a number, please enter a number!")
End Sub
Then you can put the IF ELSE statement.
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSIF RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
ELSE
MsgBox("ERROR: It's not a number")
END IF
OR you can just replace your code with this.
If IsNumeric(RequestQuantityTxtBx.Text) Then
num2 = RequestQuantityTxtBx.Text
IF IsNumeric(RequestQuantity2TxtBx.Text)
num1 = RequestQuantity2TxtBx.Text
total = num1 - num2
RequestQuantity3TxtBx.Text = total
IF RequestQuantity3TxtBx.Text > 0 THEN
MsgBox("Accepted")
ELSEIF RequestQuantity3TxtBx.Text = 0 THEN
MsgBox("Quantity is 0")
ELSE RequestQuantity3TxtBx.Text < 0 THEN
MsgBox("ERROR: Quantity below zero")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
ELSE
MsgBox("ERROR: It's not a number")
END IF
edited Nov 21 '18 at 8:14
answered Nov 21 '18 at 7:57
Unknown
639
639
Thanks. This is the right syntax that I'm looking for
– Rael
Nov 21 '18 at 21:19
add a comment |
Thanks. This is the right syntax that I'm looking for
– Rael
Nov 21 '18 at 21:19
Thanks. This is the right syntax that I'm looking for
– Rael
Nov 21 '18 at 21:19
Thanks. This is the right syntax that I'm looking for
– Rael
Nov 21 '18 at 21:19
add a comment |
This code might be another option to full fill your requirement.
' Validate if the inputs are numeric
If IsNumeric(RequestQuantityTxtBx.Text) AndAlso IsNumeric(RequestQuantityTxtBx2.Text) Then
' Cast the input to double to accomodate decimal input
Dim num1 As Double = CType(RequestQuantityTxtBx.Text, Double)
Dim num2 As Double = CType(RequestQuantityTxtBx2.Text, Double)
' Sum the input and assign the resul to the RequestQuantityTxtBx3
Dim num3 As Double = num1 + num2
RequestQuantityTxtBx3.Text = num3
' Perform validation to show appropriate message in the messagebox
If num3 > 0 Then
MsgBox("Accepted")
ElseIf num3 = 0 Then
MsgBox("Quantity is 0")
ElseIf num3 < 0 Then
MsgBox("Quantity below 0")
End If
Else
' Display error if the needed input is not numeric
MsgBox("Error")
End If
Hopefully it helps. Thanks.
add a comment |
This code might be another option to full fill your requirement.
' Validate if the inputs are numeric
If IsNumeric(RequestQuantityTxtBx.Text) AndAlso IsNumeric(RequestQuantityTxtBx2.Text) Then
' Cast the input to double to accomodate decimal input
Dim num1 As Double = CType(RequestQuantityTxtBx.Text, Double)
Dim num2 As Double = CType(RequestQuantityTxtBx2.Text, Double)
' Sum the input and assign the resul to the RequestQuantityTxtBx3
Dim num3 As Double = num1 + num2
RequestQuantityTxtBx3.Text = num3
' Perform validation to show appropriate message in the messagebox
If num3 > 0 Then
MsgBox("Accepted")
ElseIf num3 = 0 Then
MsgBox("Quantity is 0")
ElseIf num3 < 0 Then
MsgBox("Quantity below 0")
End If
Else
' Display error if the needed input is not numeric
MsgBox("Error")
End If
Hopefully it helps. Thanks.
add a comment |
This code might be another option to full fill your requirement.
' Validate if the inputs are numeric
If IsNumeric(RequestQuantityTxtBx.Text) AndAlso IsNumeric(RequestQuantityTxtBx2.Text) Then
' Cast the input to double to accomodate decimal input
Dim num1 As Double = CType(RequestQuantityTxtBx.Text, Double)
Dim num2 As Double = CType(RequestQuantityTxtBx2.Text, Double)
' Sum the input and assign the resul to the RequestQuantityTxtBx3
Dim num3 As Double = num1 + num2
RequestQuantityTxtBx3.Text = num3
' Perform validation to show appropriate message in the messagebox
If num3 > 0 Then
MsgBox("Accepted")
ElseIf num3 = 0 Then
MsgBox("Quantity is 0")
ElseIf num3 < 0 Then
MsgBox("Quantity below 0")
End If
Else
' Display error if the needed input is not numeric
MsgBox("Error")
End If
Hopefully it helps. Thanks.
This code might be another option to full fill your requirement.
' Validate if the inputs are numeric
If IsNumeric(RequestQuantityTxtBx.Text) AndAlso IsNumeric(RequestQuantityTxtBx2.Text) Then
' Cast the input to double to accomodate decimal input
Dim num1 As Double = CType(RequestQuantityTxtBx.Text, Double)
Dim num2 As Double = CType(RequestQuantityTxtBx2.Text, Double)
' Sum the input and assign the resul to the RequestQuantityTxtBx3
Dim num3 As Double = num1 + num2
RequestQuantityTxtBx3.Text = num3
' Perform validation to show appropriate message in the messagebox
If num3 > 0 Then
MsgBox("Accepted")
ElseIf num3 = 0 Then
MsgBox("Quantity is 0")
ElseIf num3 < 0 Then
MsgBox("Quantity below 0")
End If
Else
' Display error if the needed input is not numeric
MsgBox("Error")
End If
Hopefully it helps. Thanks.
answered Nov 21 '18 at 18:28
Dode
62
62
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406886%2fi-cant-figured-out-how-do-i-properly-place-the-code-block-of-if-statement%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you we're just commenting on my post just to insult me, that's totally fine, cause that code block is just a partial, That code block is not just a test for a Textbox thing, I've intentionally omitted the true function as to why I have three options(0, <0, >0). I understand your point however, you have the worst attitude so far. I post that one cause I seek some help.
– Rael
Nov 21 '18 at 21:14
To all answer posters,
.IsNumericis left over from vb6. With .net we haveInteger.TryParseUsing the .net methods will allow you to move to other .net languages with understanding. So many examples are now written in C# that it is good to know the .net way. Also, I read that the .TryParse methods have speed improvements.– Mary
Nov 21 '18 at 22:13
2
@Rael Please don't confuse instruction with insults. Usually the best teachers are concise and to the point. On another note, please turn on Option Strict. A TextBox's Text property is a String. A user can type anything into a text box and trying to do numerical comparisons with strings can lead to trouble.
– Mary
Nov 21 '18 at 22:22