Solved

Correct My code

Posted on 2009-07-03
13
245 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 56
VBA error replacing data 6 37
String manipulation in Visual Basic 7 60
MS Date Picker 64 bit 32 bit issue 12 49
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

896 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

18 Experts available now in Live!

Get 1:1 Help Now