English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hello Everyone,

I keep getting a "Conversion from string "TrueTrueTrueTrueTrue" to type 'Boolean' is not valid." error....Why? and how do I fix?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim all As Double = 3
Dim love As Double = 5
Dim mid As Double = 2
Dim house As Double = 0
Dim vac As Double = 3
If (TextBox1.Text = CDbl(all))
& (TextBox2.Text = CDbl(love))
& (TextBox3.Text = CDbl(mid))
& (TextBox4.Text = CDbl(house))
& (TextBox5.Text = CDbl(vac))
Then Form3.Show()
Else MsgBox("Sorry, please try again")
End Sub

2007-02-13 05:55:27 · 5 answers · asked by relms2000 1 in Computers & Internet Programming & Design

5 answers

In your IF statement you are comparing a STRING to a DOUBLE.

textbox.text = CDBL(all)

You are trying to test for equality between two different data types.

I would add a test variable for each text box which will be used to hold the DOUBLE value of the converted textbox.text

DIM testText1 as Double
DIM ALL as Double = 3

testText1 = VAL(textbox1.text) ' this converts the text string into a number

The VAL function converts a string in to a DOUBLE based on the first numbers encountered in the string.


IF testText1 = All then
' do something
End IF

This IF statement is comparing two DOUBLE values for equality.


ALSO!!!!!

A Single ampersand (&) is used for concatenation. Basically sticking strings together. Use AND as your logic funtion.

IF (testText1 = all) AND ( testText2 = love) THEN

2007-02-13 08:54:36 · answer #1 · answered by MarkG 7 · 0 0

I'm not sure as I don't do much VB, but it looks like the & symbols are concatonating a string rather than serving as "ands" for your conditions. If I recall, you need to write out the word "AND" instead of using the &'s.

So the if statement would look like:
...
If (TextBox1.Text = CDbl(all))
AND (TextBox2.Text = CDbl(love))
AND (TextBox3.Text = CDbl(mid))
AND (TextBox4.Text = CDbl(house))
AND (TextBox5.Text = CDbl(vac))
...

2007-02-13 14:06:43 · answer #2 · answered by Tim 3 · 2 0

Use "and" instead of & . You're mixing languages.

Edit:
if scorillo is the poster, then you can either make the change we suggested OR you can make it:
If ((TextBox1.Text = CDbl(all))
& (TextBox2.Text = CDbl(love))
& (TextBox3.Text = CDbl(mid))
& (TextBox4.Text = CDbl(house))
& (TextBox5.Text = CDbl(vac)) = "TrueTrueTrueTrueTrue")
Then Form3.Show()

which is what the contatenated strings are. But the solution the 2nd responder & I wrote are correct and preferred.

2007-02-13 13:58:59 · answer #3 · answered by Meg W 5 · 3 0

You should reference a string intstead of a double value when working with textboxes. Or you can use the double.ToString() method.




Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim all As String = "3"
Dim love As String = "5"
Dim mid As String = "2"
Dim house As String= "0"
Dim vac As String = "3"
If textbox1.text = all AND textbox2.text = love AND textbox3.text = mid AND textbox4.text = house AND textbox5.text = vac THEN
Form3.Show()
Else MsgBox("Sorry, please try again")
End Sub
End if

2007-02-13 18:31:58 · answer #4 · answered by deccasoftware 3 · 0 0

The VB response is right from her part because neither you understand is i put to write this:
If (TextBox1.Text = CDbl(all))&(TextBox2.Text = CDbl(love))...

Get it?!?

2007-02-13 14:37:29 · answer #5 · answered by Scorillo 1 · 0 0

fedest.com, questions and answers