Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any idea how to deal with blank spaces? 1

Filip Brnic

Programmer
Joined
Dec 25, 2023
Messages
74
Location
RS
Basically simple code
thisform.label1.caption = 'example'
If i write
-||- = 'example'+'x'
that is gonna come out as
example x
I don't know if its something to do with the label property. Maybe its so simple but at the moment i don't know.
 
I get examplex not what you are suggesting
Thats weird, ill send you the exact code i have, and the picture so you can see.
COMBO2.INTERACTIVECHANGE
thisform.label10.Caption='['+this.Value+'/'

I selected NORMAL from the combo box, and it shouldve displayed itself down right as NORMAL/ but for me it has space.
image_2025-06-30_123530084.png
 
Hi Filip,

Try

Code:
thisform.label10.Caption='['+ALLTRIM(this.Value)+'/'

hth

MarK
 
Hi Filip,

Try

Code:
thisform.label10.Caption='['+ALLTRIM(this.Value)+'/'

hth

MarK
Oh i see, i tried using alltrim as well but differently, i have another combobox that adds something after / so i thought that i could do something like
alltrim(thisform.label10.caption).

I don't use alltrim alot so i thought it just removes the blank spaces, hence why i was confused why they were still there, naive mistake by me, thanks for helping though!!!
 
Proof of how you're wrong:
Code:
Clear
?
_screen.addobject("label1")
_screen.label1.visible = .T.
_screen.label1.caption = 'example'+'x'
_screen.caption = 'example'+'x'
? 'example'+'x'
? len('example'+'x')
? ' ' $ 'example'+'x'
? Occurs(' ','example'+'x')

This is what you end up with:
1751280314425.png
All concatenations of 'example'+'x' won't contain a space. Not on a form caption, not on a label caption, nor if printed. The expression 'example'+'x' concatenates an x to example, making it examplex. Straight forward, nothing surprising happening here, no bug, no special behavior of labels or anything else. What do you see here on the result screenshot? 1. The _screen caption has become examplex, no space. 2. The label caption (that's the first line after the toolbar icons) is examplex, no space, directly printing with ? shows examplex, no space, the length of the expression is 8 (7 from 'example', 1 from 'x', 7+1=8), no space. The $ operator (to explain it: a $ b means asking the quesstion "is a contained in b?") results in .F. (false), means there is no space. The Occurs() functions returns 0, meaning there are 0 spaces in 'example'+'x' (the first parameter is searched in the second and the number of occurrances is returned).

So there is no space when doing what you posted. But you saw a space. When you see a space, there has been a space. Likely after 'example', maybe even two or three. Maybe before x.

You didn't literally put in two strings, did you? (Rhethorical question, the answer is no, of course. The way you use in your example is not what you really did. You got the first and maybe also the second part of the caption from fields of tables. And those are likely char fields. Am I guessing right? See what happens in such a case:

Code:
Create Cursor captionparts (part1 c(10), part2 c(10))
Insert into captionparts values ('example','x')
? part1+part2
Of course you're not having exactly this but when you get part of a caption from a field, think about what happens: How does the space come in here? That's the quiz question, now. Can you answer it?

And regarding your problem: Don't make assumptions and guesses, don't oversimplify your question, we can only answer it, if you honestly tell us how the caption is put together. General rule: There is nothing about a label that automatically adds to what you put into its caption property, you can see the caption property as if it was a string variable, so any string operations like string concatenation with the + operator work in the same manner as if you'd directly output the expression with ? or put it into a normal variable or any other caption like a form caption, or also a textbox.value or whatever else you pick that can store a string. String operations just work the way they work, no bug, no magic, no automatism. You're not seeing the woods for the tree, here. Open your eyes.

And if you want an answer, tell us what's actually put together to a label caption, don't give an example which you can easily test for yourself does not have the effect you saw. How can we answer what to change if what you post is not even remotely what you do? Once you would just check your own example, see that it doesn't show the effect, then also don't post it. Post closer to what you do, really. As this doesn't fail, the reason has to be something else. We can't tell you what's wrong with your actual code, if you don't post it. And it's obvious you didn't post your actual code.

I demonstrated one way you get spaces into an expression without having spaces in the strings that make up the code. Again, can you answer the quiz question? It's fun, once you find out yourself. I think you've already been told to look out for all the details including how data types work. If you find the basics of these things too boring to learn, you can't even do a string concatenation without being surprised about the result. You lack just a tiny bit of information, but you see how this puzzles you. Just because this is too boring for you to first learn how things work. Find something that is interesting for you and learn that, you're not able to learn programming, if you already fail on such low levels of analyzing what happens and why.

Tip: You can solve the "issue" without alltrim, too, just chooseing the right datatype for the job.
 
Last edited:
Proof of how you're wrong:
Code:
Clear
?
_screen.addobject("label1")
_screen.label1.visible = .T.
_screen.label1.caption = 'example'+'x'
_screen.caption = 'example'+'x'
? 'example'+'x'
? len('example'+'x')
? ' ' $ 'example'+'x'
? Occurs(' ','example'+'x')

This is what you end up with:
View attachment 2445
All concatenations of 'example'+'x' won't contain a space. Not on a form caption, not on a label caption, nor if printed. The expression 'example'+'x' concatenates an x to example, making it examplex. Straight forward, nothing surprising happening here, no bug, no special behavior of labels or anything else. What do you see here on the result screenshot? 1. The _screen caption has become examplex, no space. 2. The label caption (that's the first line after the toolbar icons) as examplex, no space, directly printing with ? shows examplex without space, the length of the expression is 8 (7 from 'example', 1 from 'x', 7+1=8), no space. The $ operator (to explain it: a $ b means asking the quesstion "is a contained in b?") results in .F. (false), there is no space. The Occurs() functions returns 0, meaning there are 0 spaces in 'example'+'x' (the first parameter is searched in the second and the number of occurrances is returned).

When you see a space, there has been a space. Likely after 'example', maybe even two or three.

You didn't literally put in two strings, did you? The way you use in your example is not what you really did. You got the first and maybe also the second part of the caption from fields of tables. And those are likely char fields? Am I guessing right? See what happens in such a case:

Code:
Create Cursor captionparts (part1 c(10), part2 c(10))
Insert into captionparts values ('example','x')
? part1+part2
Of course you're not having eactly this, but when you get part of a caption from a field, think about what happens. How does the space come in here? That's the quiz question, now. Can you answer it?

And regarding your problem: Don't make assumptions and guesses, don't oversimplify your question, we can only answer it, if you honestly tell us how the caption is put together. General rule: There is nothing about a label that automatically adds to what you put into its caption property, you can see the caption property as if it was a string variable, so any string operations like string concatenation with the + operator work in the same manner as if you'd directly output the expression with ? or put it into a normal variable or any other caption like a form caption, or also a textbox.value or whatever else you pick that can store a string. String operations just work the way they work, no bug, no magic, no automatism. You're not seeing the woods for the tree, here. Open your eyes.

And if you want an answer, tell us what's actually put together to a label caption, don't give an example which you can easily test for yourself does not have the effect you saw. How can we answer what to change if what you post is not even remotely what you do? Once you would just check your own example, see that it doesn't show the effect, then also don't post it. Post closer to what you do, really. As this doesn't fail, you have to wshow more. So the reason has to be something else. We can't tell you what's wrong with your actual code, if you don't post it. And it's obvious you didn't.

I demonstrated one way you get spaces into an expression without having spaces in the strings that make up the code. Again, can you answer the quiz question? It's fun, once you find out yourself. I think you've already been told too look out for all the details including how data types work. If you find the basics of these things too boring to learn, you can't even do a string concatenation without being surprised about the result. You lack just a tiny bit of information, but you see how this puzzles you. Just because this is too boring for you. Find something that is interesting for you and learn that, you're not able to learn programming, if you fail on such low levels of analyzing what happens and why.
I understand Chris, the thing is im really bad at learning stuff when i have to dig myself, im a visual learner, i learn as i go, but fox is so outdated. I followed a guy on youtube that had a cool guide for beginners and that got me started at least, but i wish i had someone to give me tasks in visual fox pro so i can practice creating stuff myself and fixing problems. Do you have anyone that would teach me further?
 
Hi Filip,
"but fox is so outdated"? Huh? Watch your words, young Paduan, at least in this forum! :)
It's stil one of the best desktop-centric object-oriented database development tools.

Did you realize, that the helpfile contains a whole training part as well as hundred of samples on HowToDo stuff?
 
Hi,

I don't use alltrim a lot so i thought it just removes the blank spaces, ...

Well, sometimes you have to think and sometimes you have to check. From the HELP FILE

ALLTRIM( ) Function

Removes all leading and trailing spaces or parsing characters from the specified character expression, or all leading and trailing zero (0) bytes from the specified binary expression.

ALLTRIM(Expression [, nFlags] [, cParseChar [, cParseChar2 [, ...]]

...


MarK
 
but fox is so outdated
The thing you have to deal with here is something that's happening to you in any other database, too. Other databases, so also more modern databases, will treat char fields the same as VFP.

See in MSSQL (T-SQL): https://sqlfiddle.com/sql-server/online-compiler?id=b6774621-12a0-4661-ac32-afee107f8962

So, are you still up for the challenge of the quiz question? Or do you simply take MarKs solution without the need to understand why it's necessary?
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top