Solved

Correct My code

Posted on 2009-07-03
13
250 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
[X]
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
  • 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
Industry Leaders: 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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