Hilal AlKhozaimi
Hilal AlKhozaimi

Reputation: 9

Simple calculation in VB.Net

I want to calculate Reynolds Number using VB.NET

This is my code:

Public Class Form1

Dim vis As Integer
Dim Den As Integer
Dim hd As Integer
Dim vl As Integer
Dim re As Integer

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    vis = Int(TextBox1.Text)
    Den = Int(TextBox2.Text)
    hd = Int(TextBox4.Text)
    vl = Int(TextBox5.Text)
    re = (Den * vl * hd) / vl
    TextBox3.Show(re)

End Sub

End Class

See my UI here.

Why I am still getting an error message "too many arguments" ?

Upvotes: 0

Views: 330

Answers (2)

Martin Soles
Martin Soles

Reputation: 559

The Int function does not do type conversion. It simply returns the integral portion of a value (14.8 would become 14). To do this conversion, you want to use CInt, if you guarantee that the incoming text really is a number.

Since you are using user supplied values, you might want to use some error correction.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    If Integer.TryParse(TextBox1.Text, vis) AndAlso _
       Integer.TryParse(TextBox2.Text, Den) AndAlso _
       Integer.TryParse(TextBox4.Text, hd) AndAlso _
       Integer.TryParse(TextBox5.Text, vl) Then

       'Do your calculation
    Else
       'There is some kind of error. Don't do the calculation
    End If
End Sub

I'm not going to address whether your formula is correct or not.

Upvotes: 0

Trevor
Trevor

Reputation: 8004

There are a few things wrong in the code you posted, firstly the calculation is wrong for Reynolds number. Second, please turn on Option Strict as with your current code it would not compile. Third please use conventional naming conventions it makes it difficult in the long run... There's more but not the point...

Suggested Solution

Variable Declaration Meaning:

  • d = Diameter of the pipe
  • v = Velocity of Liquid
  • u = Viscoscity of the Liquid
  • p = Density of the Liquid
  • tot = The Reynolds Number

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
     Dim d,v,u,p,tot As Single
    
     If Single.TryParse(TextBox1.Text,d) AndAlso Single.TryParse(TextBox2.Text,v) AndAlso Single.TryParse(TextBox3.Text,u) AndAlso Single.TryParse(TextBox1.Text,p) Then
       tot = (d * v * p) / (u * 0.001)
    
       MessageBox.Show(tot.ToString) 
       'OR
       TextBox3.Text = tot.ToString
     End If
    End Sub
    

Upvotes: 3

Related Questions