OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-04-2004, 10:03
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Label Caption Live Update

Below is a clip of my custom form from Draw 11. I want the "Total Shirts:" label to update everytime I enter a new qty in one of the sizes. Currently the code calculates the total shirts and enters it on the resulting document, but I want to add the functionality of a live Qty update.

The code is a little muddled but:
Code:
Dim sa As Integer
    Dim ma As Integer
    Dim la As Integer
    Dim xla As Integer
    Dim xxla As Integer
    Dim xxxla As Integer
    Dim yxs As Integer
    Dim ys As Integer
    Dim ym As Integer
    Dim yl As Integer
    Dim tc As Integer
            
    If ASmall1.Value = "" Then
        sa = 0
    Else
        sa = ASmall1.Value
    End If
    
    If AMedium1.Value = "" Then
        ma = 0
    Else
        ma = AMedium1.Value
    End If
    
    If ALarge1.Value = "" Then
        la = 0
    Else
        la = ALarge1.Value
    End If
    
    If AXLarge1.Value = "" Then
        xla = 0
    Else
        xla = AXLarge1.Value
    End If
    
    If ADoubleX1.Value = "" Then
        xxla = 0
    Else
        xxla = ADoubleX1.Value
    End If
    
    If YSmall1.Value = "" Then
        ys = 0
    Else
        ys = YSmall1.Value
    End If
    
    If YMedium1.Value = "" Then
        ym = 0
    Else
        ym = YMedium1.Value
    End If
    
    If YLarge1.Value = "" Then
        yl = 0
    Else
        yl = YLarge1.Value
    End If
    
    If A3X1.Value = "" Then
        xxxla = 0
    Else
        xxxla = A3X1.Value
    End If
        
    If YBaby1.Value = "" Then
        yxs = 0
    Else
        yxs = YBaby1.Value
    End If
    
    tc = sa + ma + la + xla + xxla + xxxla + yxs + ys + ym + yl
and in another area I am trying this:
Code:
If tc > 0 Then
        TCTotal.Caption = "Total Shirts: " & tc
        Else
        TCTotal.Caption = "Total Shirts: 0"
    End If
The code does not update the "tc" as I was hoping it would.

If it would make it any easier, I can provide the modules and form.
Attached Images
 
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 08-04-2004, 08:50
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Label Caption Live Update

You need to put event handlers for "Change" events for each of the text boxes and in the body of the handlers you need to call your function which calculates the number and updates the label.

Something like this:

Code:
Option Explicit

Private Sub AMedium1_Change()
    UpdateLabel
End Sub

Private Sub ASmall1_Change()
    UpdateLabel
End Sub

'-----------------
' Other event handlers go here
'-----------------

Private Function GetValue(ByVal sValue As String) As Integer
    If sValue = "" Then
        GetValue = 0
    Else
        GetValue = Val(sValue)
    End If
End Function

Private Sub UpdateLabel()
    Dim sa As Integer
    Dim ma As Integer
    Dim la As Integer
    Dim xla As Integer
    Dim xxla As Integer
    Dim xxxla As Integer
    Dim yxs As Integer
    Dim ys As Integer
    Dim ym As Integer
    Dim yl As Integer
    Dim tc As Integer
            
    sa = GetValue(ASmall1.Value)
    ma = GetValue(AMedium1.Value)
 
    '--------------
    ' The rest of initializations go here
    '--------------
    
    tc = sa + ma + la + xla + xxla + xxxla + yxs + ys + ym + yl
    
    If tc > 0 Then
        TCTotal.Caption = "Total Shirts: " & tc
    Else
        TCTotal.Caption = "Total Shirts: 0"
    End If
End Sub
Reply With Quote
  #3  
Old 08-04-2004, 11:55
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

I'm not sure I understand the...
Code:
Option Explicit
...line of code. What is that supposed to do for this macro?
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #4  
Old 08-04-2004, 12:40
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

Quote:
Originally Posted by ddonnahoe
I'm not sure I understand the...
Code:
Option Explicit
...line of code. What is that supposed to do for this macro?
Well, it's not specific for this macro. It's just a good practice to have this on the first line of your code module. It tells VBA to require explicit variable declaration. With Option Explicit specified, you can't use a variable before you declare it using DIM or similar statement.

This eliminates chances for typing error. For example:

Code:
Sub Test()
    Dim MyLongVariable As Long
    MyLongVariable = 2
    MyLongVariable = MyLogVariable + 1
    MsgBox "MyLongVariable = " & MyLongVariable
End Sub
You would think that this simple macro just show you a message "MyLongVariable = 3" but instead it will show the variable to be equal to 1. The reason is that I misspelled the third line (note the MyLogVariable instead of MyLongVariable). By default, if varible was not declared before and used, it is set to 0 or empty string and the result would be "MyLongVariable = 0 + 1" which is 1.

However if you specify Option Explicit, then the compiler will catch the error and won't even compile the code because you didn't declare MyLogVariable, which is considered a mistake.

I hope you got the point.
Reply With Quote
  #5  
Old 08-04-2004, 12:45
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

One more note, you can set VBA to automatically add "Option Explicit" to all new code modules. That's what I usually do so I don't forget to add the statement manually.

For this, go to VBA, then its Tools>Options dialog and on the Editor tab specify a checkmark next to "Require Variable Declaration".
Attached Images
 
Reply With Quote
  #6  
Old 08-04-2004, 12:51
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

That makes sense. I see things more clearly now. I'm starting to feel like Neo. LOL
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #7  
Old 08-04-2004, 14:18
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

After using Option Explicit, I came across this little snippet that wouldn't work any more and I don't fully understand it's function anyway, other than I know it calls the open dialog.
Code:
Sub ShowOpenFile()
Dim OFName As OPENFILENAME
Dim sPath As String

    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0&
    OFName.hInstance = 0&
    OFName.lpstrFilter = "Image Files" + Chr$(0) + "*.jpg;*.bmp;*.gif;*.jpeg;*.ai"
    OFName.lpstrFile = Space$(254)
    OFName.nMaxFile = 255
    OFName.lpstrFileTitle = Space$(254)
    OFName.nMaxFileTitle = 255
    sPath = GetBackEnd
    If sPath = vbNullString Then
        OFName.lpstrInitialDir = "c:\SharedImages\"
    Else
        sPath = Left(sPath, InStrRev(sPath, "\") - 1)
        If Len(Dir(sPath, vbDirectory)) > 0 Then
            OFName.lpstrInitialDir = sPath
        Else
            OFName.lpstrInitialDir = "c:\SharedImages\"
        End If
    End If
    OFName.lpstrTitle = "Select an image File (*.jpg), (*.bmp), (*.gif), (*.ai)"
    OFName.flags = 0
It's the line that says...
Code:
sPath = GetBackEnd
The GetBackEnd becomes undefined, but I don't know what kind of variable it should be.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #8  
Old 08-04-2004, 16:07
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

I guess you will need to find out where you got the original code. Because that GetBackEnd seems to be meant as a function but what it is supposed to do I have no idea. Clearly there is a mistake in the code.
Reply With Quote
  #9  
Old 08-04-2004, 18:29
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Option Explicit

Alex that is a wonderful tip about the option to get the Option Explicit, that will save me time.

Shelby
Reply With Quote
  #10  
Old 09-04-2004, 07:05
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Actually, I got the code from you and shelby. It was part of the "Browse Dialog" post that I made a while back. I figured it had something to do with Windows API, or maybe I'm talking out of my butt. LOL
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to update objects visibility faster NEHovis Corel Photo-Paint VBA 0 18-07-2003 07:54


All times are GMT -5. The time now is 07:12.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com