question on coding a reset button

  • Thread starter Thread starter Charlie Brookhart
  • Start date Start date
C

Charlie Brookhart

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
 
Is it just me or are homework exercises getting simpler as time passes?

Whatever happened to a nice postfix expression evaluator?
 
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.
 
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?
 
Charlie said:
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/chapter_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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top