quote:
Originally posted by Mattike
quote:
Originally posted by CookieRevised
Short answer: declare WndProfileInformation as a global variable.
And this should be done when you create the window, like in:code:
WndProfileInformation = MsgPlus.CreateWnd("thing.xml", "WndProfileInformation");
The difference here is the missing "var" prefix, without it it'll get declared as a global variable.
Note: when the window is destroyed, you should delete the variable too!
Personally I would not recommend declaring variables like that. It is bad practice and prone to errors/bugs if you're not carefull.
Always use
var and always declare your global variables outside functions first.
quote:
Originally posted by Yorick
I want to show some information, but I don't always have all the information....
Like this:
Profile:
Name
Country (optional)
Age (Optional)
But sometimes I don't have information to fill the country, and I do have information to fill the age. If I do it with static controls, you'll get a gap, because I can't fill country.. anyone a brilliant idea how to do this?
we need far more information to answer this question properly as there are billions of things which you can mean or want to do.
With the information given all I can say is if you don't have the info then don't display it and use a description prefix.
eg:
Profile
Name: John
Country:
Age: 25
EDIT: after seeing your
other thread, I understand what you mean.
hint: always provide enough details from the start
PS: a control is in that context always static... no control moves around on their own. Static means 'user can not interact with it' (eg: a text label), opposed to dynamic which is changeable by the user (eg: a combobox). Thus it doesn't have anything todo with moving.
Anyways,
Or you could simply move controls, but this will require the use of Windows APIs. This is possible, but certainly not elegant for this purpose.
Or you could instead of making 3 static labels, just make 1 static label and fill it with a string which is a concatenation from the individual variables seperated with a newline character (\n).
eg:
code:
var Name = "John";
var Country = "";
var Age = "25";
var ShoeSize = "5";
var Fingers = "10"
var State = "Married";
var Profile = ""; // String to display in first and only label control
If (Name !== "") Profile += "\n" + Name;
If (Country !== "") Profile += "\n" + Country;
if (Age !== "") Profile += "\n" + Age + (Age == 1 ? " year" : " years");
if (ShoeSize !== "") Profile += "\n" + ShoeSize;
if (Fingers !== "") Profile += "\n" + Fingers;
if (Sate !== "") Profile += "\n" + State;
// Remove first NewLine character
Profile = Profile.substr(1);
// Set control text
wndProfileWindow.SetControlText("lblProfile", Profile);
PS: Also notice what I've done with the age. That line adds either "years" or "year" according to what the age is (if age is 1 it will add "year"; thus without the s).
(Age == 1 ? " year" : " years") is called a
ternary operation. It is in fact an IF THEN ELSE but written as a single statement on one line. The shown ternary operation is the same as if you would write:
code:
if (Age == 1) {
return " year"
}
else {
return " years"
}