Constant values for Function arguments

classic Classic list List threaded Threaded
5 messages Options
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Constant values for Function arguments

Here's another delicate problem that's easy to work around, but still
very strange:

Module 2:
———Code starts below———
REM  *****  BASIC  *****

Option Explicit

Public Const VALUE=1
Public Const STRING=4
Public Const FORMULA=16
Public Const DATETIME=2

Sub HelloWorld
        Print "Hello world!"
End Sub
———End of code———


Module1:
———Code starts below———
REM  *****  BASIC  *****

Option Explicit

Sub Main
        Dim A
        A=VALUE+STRING+FORMULA
End Sub
———End of code———
Run Main and you will get an error message at ”A=VALUE+STRING+FORMULA”.
If you run step by step (Ctrl+F8 in the BASIC IDE) and stop at that
line and then hover your mouse pointer over VALUE or STRING or
FORMULA, you can clearly see its values, but obviously this doesn't
help. Dimensioning A as Variant, as I did, doesn't help either. If you
look at VALUE, STRING or FORMULA in the variable monitor (or whatever
it's called in English), the window at the bottom left, you can see
that they are Variant/Integer and you can see their correct values.

So now, let's move the constant definition to Module1:
Module 2:
———Code starts below———
REM  *****  BASIC  *****

Option Explicit

Sub HelloWorld
        Print "Hello world!"
End Sub
———End of code———


Module1:
———Code starts below———
REM  *****  BASIC  *****

Option Explicit

Public Const VALUE=1
Public Const STRING=4
Public Const FORMULA=16
Public Const DATETIME=2

Sub Main
        Dim A
        A=VALUE+STRING+FORMULA
End Sub
———End of code———

Now Main in Module1 works as expected, but take a look in the monitor
again. Those constants appears in exactly the same way this time as
before, the only exception is that this works.
I would be very grateful for an explanation about this. Is there
REALLY a logical reason for it to be this way or should I report this
as a bug as soon as possible?

Of course I can define those constants in every module, but isn't one
of the points by declaring as Public that I can reach them in all my
modules? Well, in this case I can; I just can't use them, at least not
when adding them to each other.
”A=VALUE” works in both my examples, but obviously not
”A=VALUE+STRING+FORMULA” for some reason I am sure absolutely nobody
can explain, so please prove me wrong here…!

:D


Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Niklas Johansson Niklas Johansson
Reply | Threaded
Open this post in threaded view
|

Re: Constant values for Function arguments

The problem here is that this...

Public Const STRING=4

… should not be possible. String is a reserved word and it should not be possible to use as a name for variable. Exchange it with Public Const sSTRING=4 and both situations you described will work just fine.
Andreas Säger Andreas Säger
Reply | Threaded
Open this post in threaded view
|

Re: Constant values for Function arguments

In reply to this post by Johnny Rosenberg
Do yourself a favour and switch to some mature programming language. It is a shame that this office suite is one of the last reservations for this clunky underdog language called "Basic".
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Re: Constant values for Function arguments

2011/8/20 Andreas Säger <[hidden email]>:
> Do yourself a favour and switch to some mature programming language. It is a
> shame that this office suite is one of the last reservations for this clunky
> underdog language called "Basic".

I think that would be more like doing you a favour, but that would on
the other hand be a good enough reason…
I'm working with another project in C but that project has nothing to
do with LibreOffice…


Regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

> --
> View this message in context: http://nabble.documentfoundation.org/Constant-values-for-Function-arguments-tp3264516p3270981.html
> Sent from the Users mailing list archive at Nabble.com.
>
> --
> For unsubscribe instructions e-mail to: [hidden email]
> Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
> Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
> List archive: http://listarchives.libreoffice.org/global/users/
> All messages sent to this list will be publicly archived and cannot be deleted
>
>

--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Re: Constant values for Function arguments

In reply to this post by Niklas Johansson
2011/8/19 Niklas Johansson <[hidden email]>:
> The problem here is that this...
>
> Public Const STRING=4
>
> … should not be possible. String is a reserved word and it should not be
> possible to use as a name for variable. Exchange it with Public Const
> sSTRING=4 and both situations you described will work just fine.

Well, this thread is maybe a bit old by now, but if I didn't mention
it before, that's the solution I finally adopted, just that I didn't
put an ”s” there, but it's the same idea.

Thanks, everyone!


Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

>
> --
> View this message in context: http://nabble.documentfoundation.org/Constant-values-for-Function-arguments-tp3264516p3267650.html
> Sent from the Users mailing list archive at Nabble.com.
>
> --
> For unsubscribe instructions e-mail to: [hidden email]
> Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
> Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
> List archive: http://listarchives.libreoffice.org/global/users/
> All messages sent to this list will be publicly archived and cannot be deleted
>

--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted