Thursday, October 28, 2010

Some useful feedback

The question:
Hello Professor ive been having trouble with # 50 on the 3.4 strings hw assignment #7
i got the first half but dont know what to do after....

Public Class Form1

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        TextBox2.Text = Int(TextBox1.Text)
        TextBox3.text = decimal?????(textbox1.Text)

    End Sub
End Class

My answer:
there are two approaches you could use for this:

strategy #1, which i think they wanted people to use:
1) use a string function, IndexOf, to find the POSITION of the period character, "."
2) use the string function, SubString, to take a slice of the string up to the period
3) use the string function, SubString, to take a slice of the string from after the period until the end.

this fits in quite well with the contents of the section, which is strings and string functions.

you could also employ strategy #2:
1) Put the entire number into a Double variable, x.
2) What you did, calling Int or CInt to get the portion before the decimal. But get it from the variable x, rather than directly from the Text property of your textbox. Assign this value to y.
3) x minus y will be just the stuff after the decimal point. assign it to a variable z.
4) then, output all these results.

of course, there are better variable names than x, y, z.

No comments:

Post a Comment