Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    May 2005
    Location
    Wilcox, Saskatchewan
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vb crital icon and combined boolean (excel 00)

    Hello,
    I am looking for a little help in making a macro msgbox and code do exactly what I want
    heres the code and my comments explain what Iam trying to do. Anyhelp would be much appreciated Thanks

    Sub Calmixercheck()
    Dim oBlenderRate As Integer
    Dim Gelconc As Integer
    Dim RateCond
    Dim ConcCond

    Const oSlipstream = 12
    Const oCalmixerRate = 0.45

    oBlenderRate = Worksheets("INPUT").Range("BlenderRate").Value
    oGelConc = Range("Gelconc").Value

    RateCond = oCalmixerRate / oBlenderRate < oSlipstream
    ConcCond = oGelConc * oBlenderRate > 20


    ''I want this message box to show if either the conditions abouve rateCond or ConcCond = TRUE
    'if both are false then dont show

    'if the message box shows the i would liek the vbcritacl icon to be included in the message box.


    MsgBox vbCritical + "Slip Stream = " & (oCalmixerRate / oBlenderRate) * 100 & "%" & vbCrLf _
    & "Slip Stream must be >= 12%" & vbCrLf & vbCrLf _
    & "Gel Rate =" & oGelConc * oBlenderRate & vbCrLf _
    & "MAX = 20 lpm" & vbCrLf & vbCrLf _
    & "Please make changes to Program!"
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: vb crital icon and combined boolean (excel 00)

    Type the word MsgBox in a module or in the Immediate window and press F1 to get help about the syntax of MsgBox.

  3. #3
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: vb crital icon and combined boolean (excel 00)

    How about this?

    <pre> ConcCond = oGelconc * oBlenderRate > 20
    <font color=red> If RateCond Or ConcCond Then
    MsgBox "Slip Stream = " & (oCalmixerRate / oBlenderRate) * 100 & "%" & vbCrLf _
    & "Slip Stream must be >= 12%" & vbCrLf & vbCrLf _
    & "Gel Rate =" & oGelconc * oBlenderRate & vbCrLf _
    & "MAX = 20 lpm" & vbCrLf & vbCrLf _
    & "Please make changes to Program!", vbCritical
    End If</font color=red>
    End Sub</pre>


    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17> I think you also mean:
    Dim oGelconc As Integer
    Not
    Dim Gelconc As Integer

    since you DIM "Gelconc", but use "oGelConc". I suggest using "Option Explicit" and requiring variable declarations.

    As another aside, typically, I would have prefixed my integer variables with an "i" to indicate that they are integers. I would use an "o" prefix for an "object". This helps while debugging code to know what type of variable it is without having to look at the DIM statement

    The other variables I would have prefixed with "b" and declared them as Boolean.


    Steve

  4. #4
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: vb crital icon and combined boolean (excel 00)

    Excel 00 ? - Is this a new or an old version of Excel... <img src=/S/drop.gif border=0 alt=drop width=23 height=23>
    Regards,
    Rudi

  5. #5
    2 Star Lounger
    Join Date
    May 2005
    Location
    Wilcox, Saskatchewan
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vb crital icon and combined boolean (excel 00)

    Hi Steve, Thanks for the advice with the letter i o and b for the labling the varibles, I have seen the o lots and thought it was more organized, just never put it all together that in fact it defined what type of varible i was working with

    Thank you for your help <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

    Seaner

  6. #6
    2 Star Lounger
    Join Date
    May 2005
    Location
    Wilcox, Saskatchewan
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vb crital icon and combined boolean (excel 00)

    Excel 2000 is what I use. Its old
    <img src=/S/gramps.gif border=0 alt=gramps width=20 height=20>

  7. #7
    2 Star Lounger
    Join Date
    May 2005
    Location
    Wilcox, Saskatchewan
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vb crital icon and combined boolean (excel 00)

    Thanks

  8. #8
    2 Star Lounger
    Join Date
    May 2005
    Location
    Wilcox, Saskatchewan
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vb crital icon and combined boolean (excel 00)

    Any other good programming tips to organize my code?

  9. #9
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: vb crital icon and combined boolean (excel 00)

    Things come to mind, perhaps there will be other suggestions:
    Require variable declaration (option explicit)
    Give variables meaningful names
    I like prefixing them with the type to aid in debugging
    I like using upper and lower case in them to aid in debugging (I DIM it with the correct cases, and type in all lower case and VB will capitalize if typed correctly)
    Indent loops, if, etc for readability

    Code ideally should be general, do not hard code ranges, etc Let the code determine at runtime the limits or define it as a variable early in the code (it makes changing tthings easier).

    Use explicit sheet/workbook references unless you really need the code to just work on the activesheet.

    Steve

Posting Permissions

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