Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Correct My code

Posted on 2009-07-03
13
248 Views
Last Modified: 2013-11-25
How do I correct the code below wherein i want to add somthing on the data?
 If s.Tag_Qty(x.Index) + 12 <= s.reOrder_tag(x.Index) + 30 Then
        x.ForeColor = vbRed
        Else
        x.BackColor = &H80FF80
            End If
If i did this an error message says "Type Mismatch"
I want to add 12 of this data "s.Tag_Qty(x.Index)" and
30 of this data  "s.reOrder_tag(x.Index)"
Public Sub Tag1()
Dim D As Kitchen
Dim s As Labeler
Set s = New Labeler
Set D = New Kitchen
s.OPEN_CON "mydb", ""
D.OPEN_CON "KitchenData", ""
Dim x As SSCommand
For Each x In cmd1
    x.ToolTipText = s.Tag_Name(x.Index)
    x.Caption = s.Tag_Name(x.Index) & vbNewLine & s.Tag_Qty(x.Index) & _
    " \ " & D.Tag_2Qty(x.Index )
    
    If s.Tag_Qty(x.Index) + 12 <= s.reOrder_tag(x.Index) + 30 Then
        x.ForeColor = vbRed
        Else
        x.BackColor = &H80FF80
            End If
            
    If s.Tag_Qty(x.Index) = "" And D.Tag_2Qty(x.Index) = "" Then
        x.BackColor = &H80FF80
            End If
Next
s.CLOSE_CON
Set s = Nothing
End Sub

Open in new window

0
Comment
Question by:Whing Dela Cruz
  • 7
  • 6
13 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24774260
From your statement in line 20 it seems that your Tag_Qty and reOrder_tag contain strings, is that correct? If so, you cannot simply add a number to a string (and strings comparing may yield other results then you expect when you actually wanted numeric compare):

If Cint(s.Tag_Qty(x.Index)) + 12 <= Cint(s.reOrder_tag(x.Index)) + 30 Then

this is a bit of a gamble, because I do not know what's in there. I'm assuming integer data. Note that you'll have to change the order of statements now, becasue the CInt will give an error when your Tag_Qty etc returns "".

-- Abel --

0
 
LVL 39

Expert Comment

by:abel
ID: 24774269
To make that complete, try this to have the correct order of evaluation and to prevent new errors to pop in:

If s.Tag_Qty(x.Index) = "" And D.Tag_2Qty(x.Index) = "" Then
    x.BackColor = &H80FF80
ElseIf Cint(s.Tag_Qty(x.Index)) + 12 <= Cint(s.reOrder_tag(x.Index)) + 30 Then
    x.ForeColor = vbRed
Else
    x.BackColor = &H80FF80
End If

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24774274
And just for the sake of the discussion, consider that this:

If X + 12 <= Y + 30 Then

is the same as the following:

If X <= Y + 18 Then
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Whing Dela Cruz
ID: 24774319
Thanks so much!
I'll do my trial rigth now...
0
 

Author Comment

by:Whing Dela Cruz
ID: 24774429
Hi!  The reason why I need to add something number in s.tag_qty(x.index)  because in s.reorder_Tab(x.Index)  would not determine the correct figure of s.tag_qty(x.index) example : if the number s.tag_qty(x.index) within the data is 177 the s.reorder_Tab(x.Index) will only indentify number 17 so when i put number 18 on the s.reorder_Tab(x.Index) will activate x.forecolod = red which is not suppose..
Do I need to add more details of this problem? I hope you got my problem.
I've got more idea from the code you had given. I hope you will add more...
Thanks!
0
 
LVL 39

Expert Comment

by:abel
ID: 24774560
I'm sorry, I really don't understand what your additional requirements are about. The code above should work according to your original request. If it doesn't, I'm afraid you'd have to be very precise about what you're after. The tags and what's in doesn't mean anything for me, and I have no idea about your functionality, simply because I cannot see your system and your requirements. I probably / hopefully don't need to, but what I do need is a clear "if this then do that, if those then do thus etc" so I can translate the English into VB for you.
0
 

Author Comment

by:Whing Dela Cruz
ID: 24774608
Its okey, no problem! Can I ask more? with regards of the code below as you had given to me when the alert as <= will not anymore fuction. Is there anything that need to adjust on it?
Thanks!

If s.Tag_Qty(x.Index) = "" And D.Tag_2Qty(x.Index) = "" Then
    x.BackColor = &H80FF80
ElseIf Cint(s.Tag_Qty(x.Index)) + 12 <= Cint(s.reOrder_tag(x.Index)) + 30 Then
    x.ForeColor = vbRed
Else
    x.BackColor = &H80FF80
End If

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24774685
>  will not anymore fuction

do you mean it never get red, or do you mean it raises an exception? If an exception, which one? What is the range of values that Tag_Qty and reOrder_tag should have when it should make the forecolor red? Perhaps the difference is always larger then 18?
0
 

Author Comment

by:Whing Dela Cruz
ID: 24774716
It never get red, I need to get red  once the tag_qty is <= reOder_Tag
Thanks!
0
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24774722
That's what it does when you do not add the amounts 12 and 30. Change your code like this:

If s.Tag_Qty(x.Index) = "" And D.Tag_2Qty(x.Index) = "" Then
    x.BackColor = &H80FF80
ElseIf Cint(s.Tag_Qty(x.Index)) <= Cint(s.reOrder_tag(x.Index)) Then
    x.ForeColor = vbRed
Else
    x.BackColor = &H80FF80
End If

Open in new window

0
 

Author Comment

by:Whing Dela Cruz
ID: 24774768
Hi! this code was asnwered of all questions that I submitted to you...Thank you so much to you...God Bless!
0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 31599663
Thanks you so much!
0
 
LVL 39

Expert Comment

by:abel
ID: 24774778
You're welcome, this is what we do it for! Thanks for the compliment.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spell Check in VB6 13 126
Prevent user closing word document opened with VB6 6 78
VBA: Insert New column with specific format type 12 38
Set WorkSheet  not Working 9 38
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question