0

I can't seem to get a simple line of code to work.

lblTotalPts.Caption = CStr(x)

This is a powerpoint label and x is an accumulator. X is declared as Long. X is holding the correct value when I hover but won't cast to a string.

thanks.

6
  • 1
    What does "won't cast to a string" mean specifically? What does the caption actually become? Or is there an error? More detail would be helpful. Commented Nov 16, 2021 at 2:22
  • sorry about my shortcomings., Casting is converting one variable from one format to another such as converting an integer to a string which is what I am trying to do. I have a jeopardy game and accumulate points for correct answers in the variable x. after every question, i want to display the total points earned on the main page using a label. So the problem is to take the variable x, an integer and cast it as a string so I can put it into a label using the caption property. I have tried using the str() and cstr() functions and x.string but these tries are not necessarily VBS syntax. Commented Nov 16, 2021 at 3:48
  • CStr(x) (see here) is how one would convert x to a String so it's unclear what the issue is. Commented Nov 16, 2021 at 3:49
  • 3
    I think what @BigBen is saying is what happens to your label? Does it show anything at all? Does it throw an error, and if so, what error? Does it get updated but with a value you're not expecting? I think you'll need to edit your question and provide more information. Commented Nov 16, 2021 at 3:58
  • 2
    The ActiveX Caption doesn't require the contents to specifically be an integer or a string. What occurs when your code is Label1.Caption = x? Why are you converting it to a string? Commented Nov 16, 2021 at 7:23

1 Answer 1

1

You access the properties of ActiveX shapes a bit differently than normal PPT shapes.

Change this:

lblTotalPts.Caption = CStr(x)

To this:

lblTotalPts.OLEFormat.Object.Caption = CStr(x)
Sign up to request clarification or add additional context in comments.

2 Comments

I spent hours and I got it 1/2 way figured it out. I am updating a variable "x" that I think I declared globally, but want to display the updated value of x (in a vba label) on a different slide. I get a value now if I write Slide3.lblTotalpts.caption = x. Previously I was not including the slide3. Now the problem is that the label increments by one no matter what value I assign to x on the other slides. I don't know how you guys/gals do it. I teach college accounting (undergrads and grads) and coding is way more difficult than accounting.
Give me variables and objects over debits and credits ANY day, @terrym! ;-) You'd want to either declare x globally (ie, before any other code in the module) and also make sure that you don't also declare it within a specific routine. Suggestion: post enough of your code to enable us to test it or at least read it all. That should get you some good suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.