Solved

Correct My code

Posted on 2009-07-03
13
244 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now