Solved

Correct My code

Posted on 2009-07-03
13
249 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 71
Determine Range to Select 5 56
Sending a email via excel using vba 6 109
Sub or Function is not defined 6 53
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

735 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