+ Reply to Thread
Results 1 to 5 of 5

msgbox for negative answer and how to determine the number of significant digits

Hybrid View

bmr8002 msgbox for negative answer... 03-06-2012, 05:32 PM
Leith Ross Re: msgbox for negative... 03-06-2012, 05:54 PM
bmr8002 Re: msgbox for negative... 03-06-2012, 07:58 PM
Leith Ross Re: msgbox for negative... 03-06-2012, 08:39 PM
bmr8002 Re: msgbox for negative... 03-06-2012, 08:56 PM
  1. #1
    Registered User
    Join Date
    02-22-2012
    Location
    wv
    MS-Off Ver
    Excel 2007
    Posts
    22

    msgbox for negative answer and how to determine the number of significant digits

    I have done this whole VBA project for several weeks(If you read my previous posts) and for some reason when I get a negative answer for my "re" when re=((4 * rate) / (pi * d * u)), I don't get a msgbox to appear telling the user there is an error. Also I was told to Format the Reynolds number to display a proper number of significant digits (see the VBA Format function). The VBA code does not need to decide how many digits to display; you should pick a reasonable number based on the data given and have the code implement that formatting. Any help I get will be very much appreciated.
    Brandon


    Private Sub reynolds_number_Click()
    Dim flow As String, rate As Single, re As Single, p As Single, d As Single, u As Single, pi As Single
    
    flow = InputBox("Select which flow rate is being used", "Flow Rate", "kg/sec, m/sec, m³/sec")
    Select Case flow
        Case "kg/sec", "m/sec", "m³/sec"
            'Do nothing
        Case Else
            MsgBox "Invalid flow rate specified!", 16, "Invalid Units"
        Exit Sub
    End Select
    
    If flow = "kg/sec" Then
        rate = InputBox("Input a numeric value for the flow rate", "Flow Rate", "number")
        u = InputBox("What is the viscosity?", "Viscosity", "kg/m·sec")
        d = InputBox("What is the diameter of the inside of the tube?", "Diameter", " in meters")
    Else
        rate = InputBox("Input a numeric value for the flow rate", "Flow Rate", "number")
        u = InputBox("What is the viscosity?", "Viscosity", "kg/m·sec")
        p = InputBox("What is the density?", "Density", "kg/m³")
        d = InputBox("What is the diameter of the inside of the tube?", "Diameter", " in meters")
    End If
    
    
    pi = 4 * Atn(1)
    re = ((4 * rate) / (pi * d * u))
    re = ((d * rate * p) / u)
    re = ((4 * rate * p) / (pi * d * u))
    Select Case (re)
    Case Is < 0
        MsgBox "You have inputed a incorrect number causing the answer to be negative", 16, "Error"
        Exit Sub
    Case Is < 2100
        MsgBox "The flow is laminar", , "Fluid Flow"
    Case Is > 2100
        MsgBox "The flow is in transition", , "Fluid Flow"
    Case Is < 6000
        MsgBox "The flow is in transition", , "Fluid Flow"
    Case Else
        MsgBox "The flow is turbulent", , "Fluid Flow"
    End Select
        
    
    If flow = "kg/sec" Then
        MsgBox "The Reynolds Number is " & ((4 * rate) / (pi * d * u)), , "Reynolds number if volumetric flow rate was specified"
    ElseIf flow = "m/sec" Then
        MsgBox "The Reynolds Number is " & ((d * rate * p) / u), , "Reynolds number if velocity specified"
    ElseIf flow = "m³/sec" Then
        MsgBox "The Reynolds Number is " & ((4 * rate * p) / (pi * d * u)), , "Reynolds number using volumetric flow rate"
    End If
    
    
    
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: msgbox for negative answer and how to determine the number of significant digits

    Hello bmr8002,

    I have run a few trials. Whenever I have entered a negative value (single value only), the message box appears. If you enter 2 negative numbers and they are multiplied, the result will be a positive number. What numbers did you enter?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-22-2012
    Location
    wv
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: msgbox for negative answer and how to determine the number of significant digits

    My professor has told me this:1)No error message for negative Re and 2)The Re values are not formatted to a proper number of significant digits. For the re = ((4 * rate) / (pi * d * u)), I make "rate" and "d" positive while i make "u" negative and no error message comes up. Can you take a look at the significant figures portion of my last post too? I put the data that he has assigned us to check our answers down below. Use the flow from to determine which set of numbers you want to use when the input box prompts you.








    flow 4.25 kg/sec
    [td]2.37 m/sec
    0.0000523 m3/sec
    diameter .300 .950 .0300
    density 1000 1540 850
    viscosity 0.0155 0.00556 0.000782
    Last edited by bmr8002; 03-06-2012 at 08:05 PM. Reason: table messed up

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: msgbox for negative answer and how to determine the number of significant digits

    Hello bmr8002,

    The results are the same as before. Making the viscosity negative displays the error message.

  5. #5
    Registered User
    Join Date
    02-22-2012
    Location
    wv
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: msgbox for negative answer and how to determine the number of significant digits

    Thank you very much. You do not know how much this means to me. I have been straining for a long time. Do you have any idea what I should do for the sig fig part?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1