Dim Weights As Integer() = New Integer() {20, 30, 40, 50, 60} Dim Heights() As Integer = New Integer() {20, 30, 40, 50, 60} 'Both methods are valid in VB. |
private void btn5_Click(object sender, EventArgs e) { int lv; int[] weights = new int[] {10, 30, 70, 60, 20}; // Arrays use brackets (square brackets) and placing [] after weights gives you an error. }// End of btn 5's click procedure. |
Dim Weights As Integer() = New Integer(5) {} |
int[] weights = new int[5]; |
private void btn5_Click(object sender, EventArgs e) { int lv, tot = 0; int[] weights = new int[] {20, 40, 60, 70, 30}; // Arrays use brackets (square brackets) and placing [] after weights gives you an error. for (lv = 0 ; lv <= weights.GetUpperBound(0) ; lv++) { tot += weights[lv]; // Add value of item in array to total. } // End of for loop using lv. }// End of btn 5's click procedure. |
Dim Weights As Integer() = New Integer() {10, 20, 30, 70, 60} Dim LV As Integer, Tot As Integer = 0 For LV = 0 To Weights.GetUpperBound(0) Tot += Weights(LV) 'Add value of item in array to total Next |
for (lv = weights.GetUpperBound(0) ; lv >= 0 ; lv--) { tot += weights[lv]; // Add value of item in array to total. } // End of for loop using lv. |
private void btn6_Click(object sender, EventArgs e) { string S = tb2.Text; int lv = 0; while (lv < S.Length) { if (S[lv] >= 'a' && S[lv] <= 'z') { S = S.Insert(lv, ":"); ++lv; // Incrementing lv prevents checking a letter already checked. } // End of if block ++lv; } // End of while loop tb2.Text = S; } // End of btn 6's click procedure. |
private void btn6_Click(object sender, EventArgs e) { string S = tb2.Text; int lv = 0; while (lv < S.Length && S[lv] != ' ') { ++lv; } // Loops through string to find a space. if (lv < S.Length) { S = S.Remove(lv, 1); // Remove the space we found. } else { MessageBox.Show("No space bar found in second textbox."); } // End of the if statement tb2.Text = S; // Return the string to the textbox. } // End of btn 6's click procedure. |
private void btn6_Click(object sender, EventArgs e) { string S = tb2.Text; int lv = tb2.TextLength; do { lv--; } while (lv >= 0 && S[lv] != ' '); if (lv >= 0) { S = S.Remove(lv, 1); // Remove the space we found. } else { MessageBox.Show("No space bar found in second textbox."); } // End of the if statement tb2.Text = S; // Return the string to the textbox. } // End of btn 6's click procedure. |
private void btn6_Click(object sender, EventArgs e) { string S = tb2.Text; int lv = tb2.TextLength; do { lv--; } while (!(lv < 0 || S[lv] == ' ')); if (lv >= 0) { S = S.Remove(lv, 1); // Remove the space we found. } else { MessageBox.Show("No space bar found in second textbox."); } // End of the if statement tb2.Text = S; // Return the string to the textbox. } // End of btn 6's click procedure. |
private void btn7_Click(object sender, EventArgs e) { foreach (Control ctl in this.Controls) { ctl.Text = "Test"; } // End of foreach loop } // End of btn 7's click procedure. |
private float thrownheight(float verticalspeed, float g) { // Calculates the maximum height reached by an object thrown at a specified speed using the // specified acceleration due to gravity. // Vf - Vo = g * t => t = -Vo/g => d = vo*t + 0.5*g*t*t => d = -vo*vo/g + 0.5*vo*vo/g // d = vo*vo/2*g return verticalspeed * verticalspeed / g / 2f; } // End of thrownheight function. |
private void btn8_Click(object sender, EventArgs e) { float high; high = thrownheight(45f, 9.8f); MessageBox.Show(high.ToString()); } // End of btn 8's click procedure. |
private void setmytext(float setting) { this.Text = setting.ToString(); // This does nothing more than puts a float's value into the form's text. } // End of setmytext subroutine. |
private void btn8_Click(object sender, EventArgs e) { float high; high = thrownheight(45f, 9.8f); setmytext(high); } // End of btn 8's click procedure. |
private void clearmytext() { this.Text = ""; } // End of clearmytext subroutine. |
private void btn7_Click(object sender, EventArgs e) { clearmytext(); } // End of btn 7's click procedure. |