Entry Level classes: Cases

  • Thread starter Thread starter Taishi
  • Start date Start date
T

Taishi

Visual Studio.Net
Windows 2000 Server
also on Windows XP Professional

I am a new user. I am not a programmer. Trying to learn. This actually
is a question on a quiz. I created something in VS.NET but had no luck.
Decided to ask any Professionals or experienced programmers out there what
to do.

How can I write the following in Visual Studio.NET and see the answer?

-Or- Is there some other way to see the answer?

Const intNumber As Integer = 10
Select Case intNumber
Case 1, 3, 5, 7, 9
intMystery = intNumber
Case 2, 4, 6, 8, 10
intMystery = intNumber + 1 * 2
Case Else
intMystery = intNumber * 2 + 1
End Select

Thanks for your help,
T


--
Warm Regards,

McRubin Bevil
(e-mail address removed)
972-329-3469
 
Hi... there are a number of ways to choose from. Try them and see which is
appropriate under different circumstances.

* Perhaps the first was is (if you have a form) you can drop a label on it
and set the text property as in label1.text = intMystery.ToString

* You can output the value to the output window while the program runs with
debug.writeline( intMystery )

* You can set a watch variable in the watch window (while it is running.)

* You can place a breakpoint before that code and step into the code or
place it after that code and if you place the cursor over the variable the
value will display.

* While the program is at the breakpoint (if the value has been computed
already and is in scope) you can type the following into the command window

? intMystery (and press enter)

* You can add a messagebox and have it display it.

You might test each one out just for kicks... best of luck,
Tom
 
Tom,

I don't understand. I placed responses below. How do I do the first
option?

Tai


Tom Leylan said:
Hi... there are a number of ways to choose from. Try them and see which is
appropriate under different circumstances.

* Perhaps the first was is (if you have a form) you can drop a label on it
and set the text property as in label1.text = intMystery.ToString

I tried this way first. Maybe my coding is wrong. After I ran it, it
didn't display in the box I created on the form.
* You can output the value to the output window while the program runs with
debug.writeline( intMystery )

I have no clue how to code this option.
 
Taishi said:
I tried this way first. Maybe my coding is wrong. After I ran it, it
didn't display in the box I created on the form.

You are going to have to solve this one... all form-based development uses
things like this. Keep in mind that the value must be assigned "after" it
has been computed. Clearly if you assign the value of the variable before
it exists or before it has been computed it won't display properly. And of
course if you never assign the value of the variable that wouldn't work
either.

Keep in mind also that you can test the assigning of text to a label control
outside of your routine just to test it. Get it to say "Hello Taishi"
before you get it to do anything else.
I have no clue how to code this option.

I'm going to suggest you look up writeline in the help system. Again... you
can test it by having it output your name. If you post all of your code we
can point to the spot where you need to add this stuff.

Tom
 
Here is my code.

On my design form I have 2 text boxes labeled lblMystery and lblNumber.
Then I have a calculate button.

code:

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalc.Click

Dim intMystery As Integer

Dim lblMystery As Decimal

Const intNumber As Integer = 10

intMystery = lblMystery

Select Case intNumber

Case 1, 3, 5, 7, 9

intMystery = intNumber

Case 2, 4, 6, 8, 10

intMystery = intNumber + 1 * 2

Case Else

intMystery = intNumber * 2 + 1

End Select

lblMystery = intMystery

End Sub

End Class


Thanks for all of help,
Tai
 
Taishi said:
Here is my code.

Notice how your code was double spaced? In the future try to paste it into
Notepad first, then cut again and drop it into your message. That will
eliminate the double spacing.
On my design form I have 2 text boxes labeled lblMystery and lblNumber.
Then I have a calculate button.
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalc.Click

Dim intMystery As Integer

This is a variable of type Decimal that you have chosen to name lblMystery
it isn't a label control.
Dim lblMystery As Decimal

Const intNumber As Integer = 10

This isn't doing much just assigning the zero in lblMystery (a Decimal) to
intMystery (an Integer)
and it indicates that you should Set Option Strict to "On" because it didn't
generate an error
intMystery = lblMystery
Select Case intNumber

Case 1, 3, 5, 7, 9

intMystery = intNumber

Since intNumber is a constant and equal to 10 it is a safe bet that the code
here will execute
Case 2, 4, 6, 8, 10

intMystery = intNumber + 1 * 2

Case Else

intMystery = intNumber * 2 + 1

End Select

And here you have simply assigned the Integer to the Decimal variable
lblMystery = intMystery

End Sub

End Class

Note the code in my original example. You may have dropped a label onto the
form but you aren't assigning the value of intMystery to it or the code
would read as follows: lblMystery.Text = intMystery.ToString

I'd suggest that you remove the references to the lblMystery variable, check
the name of your label and try again. And go to the project setup and
change the Option Strict (in the "build" area) to "On" it will trap and
point out silly errors for you. Let the computer help you out in these
cases.

Tom
 
Back
Top