Announcement

Collapse
No announcement yet.

Visual Basic Help

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Visual Basic Help

    Code:
    Private Sub ToggleButton1_Click()
    
    
    model1 = Model1box.Text
    model2 = model2box.Text
    Weight1 = Weightbox1.Value
    hp1 = horsepower1.Value
    et1 = 5.825 * ((Weight1 / hp1) ^ (1 / 3))
    Et1box.Value = et1
    Weight2 = Weightbox2.Value
    hp2 = horsepower2.Value
    et2 = 5.825 * ((Weight2 / hp2) ^ (1 / 3))
    ET2box.Value = et2
    If (et1 < et2) Then
    Champion.Text = model1
    ElseIf (et1 > et2) Then
    Champion.Text = model2
    Else
    Champion.Text = "Tie"
    End If
    End Sub
    how do i dimension et1 and et2 to only go out to like 3 decimal places??

  • #2
    Man, I haven't worked with VB too much. I know the C# equivalent would be:
    float et1 = 5.825 * ((Weight1 / hp1) ^ (1 / 3));
    double elapsedTimeVal = Math.Round((double) et1,3);
    Et1box.Text = elapsedTimeVal.ToString();


    I've found on the net a function that you can just copy and paste...hopefully:

    Private Function RoundOff(ByVal value As Double, ByVal _
    digits As Integer) As Double
    Dim shift As Double

    shift = 10 ^ digits
    RoundOff = CInt(value * shift) / shift
    End Function

    So once your function is in, you'd just pass in:

    et1 = 5.825 * ((Weight1 / hp1) ^ (1 / 3))
    et1 = RoundOff( et1, 3 )
    Et1box.Value = et1
    I hope that works
    94 Black T/A GT, Advanced Induction 355, 3200 stall, built 4L60E, Moser 9", Baer Brakes, Shooting for 11s...

    Comment


    • #3
      I usually do it like that

      Field(6).Text = Format$(H2, "0.00")
      Field(7).Text = Format$(V2, "0.00")

      Not a VB pro though but it works.
      97 Trans Am A4 more or less stock (Mods: WS6 Ram Air with Fernco & K&N, 12 disc CD changer, power antenna, SLP Fan Switch, LS1 Aluminum DS, Borla Cat back, McCord power plate, Spohn tower brace, Sirius, HID fog lights)


      1and1 Web Hosting

      Comment

      Working...
      X