Question:
Visual Basic 10 Error. Simple code.. please help?
Devicon
2011-11-30 21:13:25 UTC
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim numa, numb As Integer

numa = InputBox("Enter a number", "Input value")
numb = InputBox("Enter one more number", "Input value")

Label1.Text = Switch (numa = numb , "Same numbers" _
numa > numb , "Number A is bigger" _
numa < numb, "Number B is bigger")


End Sub

End Class

=============================

Error is with switch command. It always giving me this error.
"Switch is a type and cannot be used as an expression."

I am using VB10 Ultimate

Please help.
Four answers:
2011-11-30 21:22:33 UTC
You're missing a couple commas in the switch statement.

After "Same numbers"

and "Number A is bigger"
Boolean
2011-11-30 21:20:13 UTC
I've never programmed in vb, but from what I know from other languages, you can't use a switch statement in an expression, just as the error is saying. So really it's saying you cant set something equal to a switch :p try something like this.



Label1.text = STRINGVARIABLE



then make a switch statement for what the string variable will be assigned to.
hisamuddin
2016-10-24 08:59:11 UTC
Dim num1 As Integer = TextBox1.text cloth cloth Dim num2 As Integer = TextBox2.text cloth cloth Dim num3 As Integer = TextBox3.text cloth cloth Dim numResult As single numResult = (num1 * num3) / num2 MsgBox (numResult)
2011-11-30 21:13:50 UTC
follow


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...