The following text section in the help for "Using variables" for Basic (the URL on my computer is file:///C:/Program%20Files/LibreOffice/help/en-GB/text/sbasic/shared/01020100.html?DbPAR=BASIC#bm_id3149346 ) seems to be wrong: It is very important when declaring variables that you use the type-declaration character each time, even if it was used in the declaration instead of a keyword. Thus the following statements are invalid: Dim a$ Declares "a" as a String a="TestString" Type-declaration missing: "a$=" I tested it, it works without a$ in the second statement. The text is probably outdated for a long time. The sentence, by the way, seems to me badly constructed, "even" is misplaced, and the meaning is not very clear. I understand that the meaning is: "if you use the type-declaration character in the declaration, then you must use it in all statements using this variable". I add this for the case that my test was incomplete, and a suitable help text is still necessary.
I also tested and confirmed. It looks that if you declare A$ then you should use A$ in the code for the sake of readability and maintainability. However I am not sure if this is a documentation issue or a bug in the implementation of LO Basic.
(In reply to Olivier Hallot from comment #1) > I also tested and confirmed. It looks that if you declare A$ then you should > use A$ in the code for the sake of readability and maintainability. > > However I am not sure if this is a documentation issue or a bug in the > implementation of LO Basic. I don't consider this as a bug in the implementation, it works as well with a$ as with simply a, as is optimal for compatibility sake. But I understood that we have to report documentation issues in bugzilla. And the main implication of the text in consideration is that you have to use the $ extension (in the example) every time you use the variable, which is obviously wrong; therefore the text section should be corrected. As "for the sake of readability and maintainability": if one would understand a$ as a name for a variable to be always used, that would astonish me.
How about -----8<----- It is recommended to declare variable either by the type-declaration character or by the variable type keyword. Thus the following statements are good programming practice: Dim A$ Dim A as String -----8<-----
(In reply to Olivier Hallot from comment #3) > How about > > > -----8<----- > It is recommended to declare variable either by the type-declaration > character or by the variable type keyword. Thus the following statements are > good programming practice: > > Dim A$ > Dim A as String > > -----8<----- Never mind. Actually I am removing the whole paragraph and example. The example just above says all on variable declaration, no need for confusion.
(In reply to Olivier Hallot from comment #4) > (In reply to Olivier Hallot from comment #3) > > How about > > > > > > -----8<----- > > It is recommended to declare variable either by the type-declaration > > character or by the variable type keyword. Thus the following statements are > > good programming practice: > > > > Dim A$ > > Dim A as String > > > > -----8<----- > > Never mind. Actually I am removing the whole paragraph and example. The > example just above says all on variable declaration, no need for confusion. Yes, that's OK. I could have suggested that myself! I set the status to RESOLVED.
Olivier Hallot committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/help/+/d884a65408c8d477292c8dab2d17258f25f1322b%5E%21 tdf#125763 Remove confusing remark on Variable declarations