Sign in to follow this  
Followers 0
Logman

Include with variable

39 posts in this topic

Hi, how including file defined in a variable?

This is't working:

#include <GUIConstants.au3>

; select language
...
$lang = "en"
...

$langfile = "lang_" & $lang &  ".au3"

#include $lngfile ; <- this didn't work

...
...
...

Sorry for my bad english

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can do it like this:

$lang = InputBox('', '')

If $lang = 'en' Then
    #include <lang_en.au3>
ElseIf $lang = 'other' Then
    #include <lang_other.au3>
EndIf

;etc

edit - btw, this is from the helpfile regarding the #include filename: "The filename of the current script to include. Path is optional. This must be a string--it cannot be a variable."

Edited by xcal

Share this post


Link to post
Share on other sites

... this must be a string--it cannot be a variable."

Thanks, xcal, for fast reply! I'll observe the terms in help file...

Share this post


Link to post
Share on other sites

You can do it like this:

$lang = InputBox('', '')

If $lang = 'en' Then
    #include <lang_en.au3>
ElseIf $lang = 'other' Then
    #include <lang_other.au3>
EndIf

;etc

edit - btw, this is from the helpfile regarding the #include filename: "The filename of the current script to include. Path is optional. This must be a string--it cannot be a variable."

Did you put any more thought into this answer than the OP did the question? Do you expect that to work how it's written when compiled and run on a different computer?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Did you put any more thought into this answer than the OP did the question? Do you expect that to work how it's written when compiled and run on a different computer?

I was only answering the question - nothing more. I know about as much of what he's actually doing as you do. That would be nothing. Maybe it'll work for him. Do you know if he'll be running it compiled? Or even on other computers? It's implied by the multi-language setup, but you don't really know. Maybe it won't work and he'll have learned something himself in the process? Who knows? We don't. But you want to see his 4 line non-functioning example to fruition?

So, how much thought did you put in to your post? :P

edit

And you know what... Out of my 365 posts I've only asked maybe 5 questions. I'm not the best coder/scripter, but I spend a lot of my free time trying to help people or give them a push in the right direction because I want to support Autoit in the small way I can. So don't go directing your shitty attitude towards people who don't deserve it.

Edited by xcal

Share this post


Link to post
Share on other sites

Answering the question would be something like, "What you're trying to do makes no sense and is not possible." What you did was write some code that makes no sense and give false hope to an already mis-guided user.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Answering the question would be something like, "What you're trying to do makes no sense and is not possible."

No, that's speculation and commentary, and it is actually possible. I was just answering the question. If you want to do some hand-holding, direct it towards him - I wasn't asking for it.

Edited by xcal

Share this post


Link to post
Share on other sites

I assume you can use the

#include

in an included file right?

.. which means - you could dynamically include includes by making the initial include file on the fly which includes the include files actually wanted.

Share this post


Link to post
Share on other sites

No, that's speculation and commentary, and it is actually possible. I was just answering the question. If you want to do some hand-holding, direct it towards him - I wasn't asking for it.

Oh, it's possible? Well, what do I know? It's not like I wrote the code that handles #include or anything.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I don't post stuff without trying it first. It works in uncompiled form as long as the files exist.

I wrote the code that...

Why do I get the feeling that's tattooed backwards on your forehead so you can see it every time you come across a mirror...

edit - unclosed tag

Edited by xcal

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Stop being an idiot for a bit, xcal. All files are included. Period. No run-time If...Then logic is going to conditionally include - or not - a file. If you happen to be including a file that is "pure code", then it will kind-of work. But if there is a single function declaration, the script won't even run. But the file will be included, regardless. It may just be that the code isn't reached.

What the OP asked for and the code you showed is stupid, ill-thought-out, not-possible and the wrong way to approach the problem.

Feel free to continue to make yourself look like a jackass if you wish. Arguing with the person who knows the feature best and knows it's capabilities and limitations isn't exactly the smartest thing you can do. Snide comments about my ego aside, quite simply, I wrote the feature, I know how it works, it's not rocket science. It doesn't work like you want to think it does and trying to tell me otherwise is just plain foolish.

Edit: Minor correction.

Edited by Valik

Share this post


Link to post
Share on other sites

Well, I see you're an idiot. I didn't think you were, but it seems that you are. You're so worried about defending your shitty code that you won't acknowledge that it's shitty code that only an idiot would write. Oh well. Looks like we have another person to add to the list of people who are too right to be wrong.

Share this post


Link to post
Share on other sites

So even you say it kind of works with limitations.

So, will those limitations affect him? Did they affect my test?

What Valik is trying to get at, is that you cannot determine whether or not you include a file in an If...Then statement.

The files will be included whether the If statement calls for them or not.

The simplest solution is to include all the files and, depending on user input, use the appropriate functions.


Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house.

Share this post


Link to post
Share on other sites

And you just ignored what I said, too.

Your post #11 was all about whether it works or not. That's what I was replying to. You are following the progression of the discussion, right?

If someone was creating a language file, it's just going to be vars and strings. What I posted does work for uncompiled scripts. You said "No run-time If...Then logic is going to conditionally include - or not - a file." You are wrong.

You're also assuming that I think it's good code? You're assuming way too much.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

What Valik is trying to get at, is that you cannot determine whether or not you include a file in an If...Then statement.

The files will be included whether the If statement calls for them or not.

The simplest solution is to include all the files and, depending on user input, use the appropriate functions.

I know what valik is getting it.

The files are not included if the 'If' statement doesn't call for them.

Yes, I agree, that is the best solution... user input.

edit -

Try this. See main.au3. Very simple test.

And just to clarify, this isn't about whether it's good code or not - it obviously isn't. I'm only addressing Valik saying it doesn't work. That's what things progressed to. It's all what Valik was talking about in his posts 6, 9, and 11.

Edited by xcal

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

You are assuming that it will only be vars and strings. However, even if they DO only include vars and strings, if they are named the same way in each include file, whichever file was included last will overwrite the previous vars. If they weren't named the same variables, there would be no need for different lang files.

You are the one that is wrong. Valik said if the include file is PURE code, it MIGHT work. You are reading the WHOLE post before you pass it off as nonsense I hope.

EDIT: Sorry for the witty sarcasm. Valik is starting to corrupt me in his evil genius ways. :P

Edited by hearurscream

Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I know for a fact that the file is included, you twit. I wrote the damn code, I know what it does. The file is included, compiled or not, as one of the very first things AutoIt does. Based on your foolish assumption, the following script will run and/or compile:

If True = False Then
    #include <NoFile>
EndIf
oÝ÷ Ø]¡ë'ßÛHµê뢻(ºØ¦çbj×¥ÈÚ-jȧW¥w¨~ë­Êz+Åç.µçpØm«lr¸©µ:ò¶¬ü¨ºËbWhmmébz÷¦y«­¢+Ø)5Í  ½à ÐÀäØ°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí5 ÅÕ½Ðì¤)%QÉÕô±ÍQ¡¸($¥¹±Õ±Ðí9½¥±Ðì)¹%oÝ÷ Øò¢ë-Y]¢}ý¶éÝz»-jwa£§r[{
+È­ßÛ/z¼¬jezéeX§u©âÉnuë-jצz{)b:§¶«y÷«zwuø¥{ùb ¨§+ayéí·¢{^Û(~ØZµø¥{ùb Þë^¶¢Énuë-jצz{)b=«-¶¢{^Û(~Ø^­çÞ­éÜy×â触Vzíè§r[zËZµéßåû¥N¡×¢²)ìz»^v)åw§¢Øb ¨­å¡jÛajÙj{"³*.q©Ý¢Ê&z·¬r·°yÛ©²Û}«%¢x²Ø^­ë.ÖµêÞƧv)àjYbÉnuíý²èvç²Ì§µ§-Æ¥+Ú'¡×'{¦¦W¨~ØZ¶)Úrب+-çèZ0x+"³k¥ªÚµçâë'jg­éqÊ+v)à¶ayÊ&éí±«­¢+Øì¹%¹ÔÌ)¹%oÝ÷ Ù«­¢+Ø(ìMÉ¥ÁйÔÌ)%QÉÕQ¡¸(%5Í    ½à ÐÀäØ°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(¥¹±ÕÅÕ½Ðí¹%¹ÔÌÅÕ½Ðì(oÝ÷ Ù

Just because a file is included doesn't mean it's executed at the point of inclusion.

I think you completely misunderstood about every single thing about how #include works.

Edited by Valik

Share this post


Link to post
Share on other sites

Valik, I'm just wondering here but, how many people have you thoroughly devoured on this forum?

I don't know about anyone else, but I've spent hours just looking for threads that you have posted in, just to get a good laugh at how you completely destroy people.

You are the God in my AutoIt Life, and that is no sarcasm! :">


Infinity is a floorless room without walls or ceiling.Anyone who cannot cope with mathematics is not fully human. At best he is a tolerable subhuman who has learned to wear shoes, bathe, and not make messes in the house.

Share this post


Link to post
Share on other sites

Valik, I'm just wondering here but, how many people have you thoroughly devoured on this forum?

I don't know about anyone else, but I've spent hours just looking for threads that you have posted in, just to get a good laugh at how you completely destroy people.

You are the God in my AutoIt Life, and that is no sarcasm! :">

How sad :P

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0