By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,027 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,027 IT Pros & Developers. It's quick & easy.

question on coding a reset button

P: n/a
I am trying to figure out how to code a button labeled reset which will
clear the user input as well as clear out the two read-only text boxes. Here
is the program code that I have.

'declaring variables

Dim totalLiters As Double = Convert.ToDouble(txtLiters.Text)

Dim totalPints As Double = Convert.ToDouble(txtPints.Text)

Dim totalGallons As Double = Convert.ToDouble(txtGallons.Text)

'assigning text box values to variables

totalLiters = txtLiters.Text

totalPints = txtPints.Text

totalGallons = txtGallons.Text

'performing calculations

txtPints.Text = totalLiters * 2.1133

txtGallons.Text = totalLiters * 0.26
Feb 7 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Is it just me or are homework exercises getting simpler as time passes?

Whatever happened to a nice postfix expression evaluator?

Feb 7 '06 #2

P: n/a
What do you mean by that?

<al*******@users.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Is it just me or are homework exercises getting simpler as time passes?

Whatever happened to a nice postfix expression evaluator?

Feb 7 '06 #3

P: n/a

I meant that this group is not really intended to provide a homework
service.
The question title was about a reset button and the first line of the
question re-iterates that but then the remaining sample code has
nothing whatsoever to do with it.

The repeated

Dim totalLiters As Double = Convert.ToDouble(txtLiters.Text)
...
totalLiters = txtLiters.Text

shows either a lack of care in formulating the question or a lack of
understanding of what the code does.
I am having a not fun day, I admit it, and you just happened to come up
(un)lucky.

But... it does behoove posters to have actually attempted to solve
their problem before posting (maybe have read a programming book,
searched through previous posts or even read the class notes). People
here are generally pretty generous with their time and if you are lucky
someone may handhold you through this. Or maybe not.
Alan.

Feb 7 '06 #4

P: n/a
It may or may not intrest you that I have absolutely no programming
experience at all, and I am having to learn VB from a book instead of in a
classroom environment where more time can be spent actually covering the
topics. The code I provided is what I wrote on my own and did not come from
anywhere else.
It also just so happens that I did look in a programming book. In fact, I
looked in at least three different books and I also looked through the index
file for the MSDN library. I came across the topic reset method and I looked
at that, but it did not seem that the example provided was the correct
procedure to use.
I'm sure that you could probably find a more efficient way to write the
code, but as long as the program works, what difference does it make?
Just because you may not be having a fun day doesn't mean that you can't
provide a meaningful reply. How else do you learn if you don't ask a
question?
<al*******@users.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...

I meant that this group is not really intended to provide a homework
service.
The question title was about a reset button and the first line of the
question re-iterates that but then the remaining sample code has
nothing whatsoever to do with it.

The repeated

Dim totalLiters As Double = Convert.ToDouble(txtLiters.Text)
...
totalLiters = txtLiters.Text

shows either a lack of care in formulating the question or a lack of
understanding of what the code does.
I am having a not fun day, I admit it, and you just happened to come up
(un)lucky.

But... it does behoove posters to have actually attempted to solve
their problem before posting (maybe have read a programming book,
searched through previous posts or even read the class notes). People
here are generally pretty generous with their time and if you are lucky
someone may handhold you through this. Or maybe not.
Alan.

Feb 7 '06 #5

P: n/a
Charlie Brookhart wrote:
I am trying to figure out how to code a button labeled reset which
will clear the user input as well as clear out the two read-only text
boxes.


The way you'd (well, I would, anyway) do that is to have a separate section
of your program which initiliases everything, for example:

Sub init()
txtLiters.Text=""
txtPints.Text=""
txtGallons.Text=""
End Sub

So that in the code for your reset button (called ResetButton in this
example) you'd use:

Sub ResetButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ResetButton.Click
init()
End Sub

(watch for line-wrap)

That way, if you need to clear the text boxes for any other reason, you can
simply call init().
I suspect you're rushing through your book a bit quickly, or perhaps it is
aimed at people who already have some programming experience. Maybe some
tutorials which start a bit sooner in the learning process would help you,
for example http://www.vbip.com/books/1861007612...er_7612_01.asp looks
ok at a quick glance. It's quite important to know a little about the
fundamentals of how computers work too:
http://computer.howstuffworks.com/microprocessor.htm (use a popup blocker to
preserve your sanity) might be of use to you.

HTH

Andrew
Feb 8 '06 #6

P: n/a
There is just one programming class which happens to be part of the overall
degree program that I am enrolled in. I think that this class could very
well be aimed towards those that have prior programming experience. Any
additional resources that I can find would be helpful in this learning
process.
"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
Charlie Brookhart wrote:
I am trying to figure out how to code a button labeled reset which
will clear the user input as well as clear out the two read-only text
boxes.
The way you'd (well, I would, anyway) do that is to have a separate

section of your program which initiliases everything, for example:

Sub init()
txtLiters.Text=""
txtPints.Text=""
txtGallons.Text=""
End Sub

So that in the code for your reset button (called ResetButton in this
example) you'd use:

Sub ResetButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ResetButton.Click
init()
End Sub

(watch for line-wrap)

That way, if you need to clear the text boxes for any other reason, you can simply call init().
I suspect you're rushing through your book a bit quickly, or perhaps it is
aimed at people who already have some programming experience. Maybe some
tutorials which start a bit sooner in the learning process would help you,
for example http://www.vbip.com/books/1861007612...er_7612_01.asp looks
ok at a quick glance. It's quite important to know a little about the
fundamentals of how computers work too:
http://computer.howstuffworks.com/microprocessor.htm (use a popup blocker to preserve your sanity) might be of use to you.

HTH

Andrew

Feb 8 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.