PDA

View Full Version : Code Check


abnrange
02-17-2009, 09:51 AM
Hello,

I have an image in my project that I want to change out depending on user name. I did not want to imput the full user name - just limit to the first 4 or 5 letters. Then, If not WELL or ITAD then use this image. Is there a better way to do this. The below code does not work with error; Line 5: Argument must be of type String. Any help would be great - Thanks


--Get user name
NAME = System.GetUserInfo();
NAME1 = (NAME.User);

-- (2) Narrow Result to the first 4 letters
NAME1 = String.Mid(NAME1, 1, 4);

-- (3) Compare and change image
if NAME1 == "well" then Image.Load("Image16", "AutoPlay\\Images\\User.png");

elseif NAME1 == "itad" then Image.Load("Image16", "AutoPlay\\Images\\Secuty-agent.png");

elseif NAME1 == "" then Image.Load("Image16", "AutoPlay\\Images\\People.png");
end

holtgrewe
02-17-2009, 10:28 AM
One way would be to set up your abbreviated name and images in a table where name one associates to images1 , etc.

tblNames={"well","itad"}
tblMax=Table.Count(tblNames)
tblImages={"User.png","Secuty-agent.png"}

for x = 1, tblMax do
if NAME1 == tblNames[x] then
Image.Load("Image16", "AutoPlay\\Images\\"..tblImages[x])
Image.SetVisible("Image16", true)
else
Image.Load("Image16", "AutoPlay\\Images\\default.png")
Image.SetVisible("Image16", true)
end
end

hth

PS:

NAME.User is not a valid return parameter from System.GetUserInfo maybe try .RegOwner...

abnrange
02-17-2009, 10:35 AM
Thanks for the quick reply - I tried your code but was not able to make it work. Is there something missing??? Thanks again.

holtgrewe
02-17-2009, 10:42 AM
Yeah, check the PS in my message - The code works, but not with NAME.User (Where did you find that?)...

abnrange
02-17-2009, 10:54 AM
Okay this is were I get confused. I tried modifying a code that I already have working (see code below). I seem to get confused on using the right syntax. I looked at AMS help - still confused. I guess the right question to ask is how would you do it? We use Novell Client . I was trying to get the username ie; ITADMIN (itad) if = itad then load this image etc.. I got the below code from Mina sometime back. Thanks again...

I have this code that currently works on a button

-- Get User and LAN info to dispaly in a dialog--
name = System.GetUserInfo();
name1 = (User.User);

LANINFO = System.GetLANInfo();
LAN = (LANINFO.Host);

name2 = name1.." and computer station "..LAN

Dialog.Message("Status", "Your user information is being logged for security purposes only.\r\n\r\nYou are being logged as user "..name2..".", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);


Thno On Preload I have this code

--------write to log file------
LANINFO = System.GetLANInfo();
TextFile.WriteFromString("AutoPlay\\Docs\\Logs\\HomeLog.dat", LANINFO.Host.."\r\n", true);

name = System.GetUserInfo();
TextFile.WriteFromString("AutoPlay\\Docs\\Logs\\HomeLog.dat", name.RegOwner.."\r\n", true);

IPinfo = System.GetLANInfo();
TextFile.WriteFromString("AutoPlay\\Docs\\Logs\\HomeLog.dat", IPinfo.IP.."\r\n", true);

User = System.GetLANInfo();
TextFile.WriteFromString("AutoPlay\\Docs\\Logs\\HomeLog.dat", User.User.."\r\n", true)

result = System.GetDate(DATE_FMT_US);
TextFile.WriteFromString("AutoPlay\\Docs\\Logs\\HomeLog.dat", result.."\r\n", true)

result1 = System.GetTime(TIME_FMT_MIL);
TextFile.WriteFromString("AutoPlay\\Docs\\Logs\\HomeLog.dat", result1.."\r\n", true)

--------------------------------------------------------------Display User info --------------------------

name1 = System.GetUserInfo();
Label.SetText("UserInfo1", User.User);

LANINFO = System.GetLANInfo();
Label.SetText("LanInfo", LANINFO.Host);

holtgrewe
02-17-2009, 11:23 AM
http://www.indigorose.com/forums/showthread.php?t=26217&highlight=User.User

If you can find out what User.User is and where it comes from in your project, the rest should be easy...

If it's possible to post that project I'm certain someone can help...

abnrange
02-17-2009, 12:15 PM
I attached a sample project with the code User.User.

Still unable to figure out how to change the image by username.

Thanks again!

holtgrewe
02-17-2009, 01:24 PM
I don't see how some of that is working. I would open a ticket with IR. The way User.User is being used, and appears to be working, it seems you have been using some undocumented resources.

Sorry I can't be of further assistance.

abnrange
02-17-2009, 01:52 PM
Thanks for your time.

Dermot
02-17-2009, 02:06 PM
We have gone through this with him just last week. User.User is defined else where.

Also you don't need to call System.GetLANInfo() over and over. Once is enough. Just access the different table values returned.

As I told you last week, name = System.GetUserInfo() is not being used at all. The whole thing is a mess and very confusing.

holtgrewe
02-17-2009, 02:26 PM
Without complicating things any further, if you place this on your (button/image) on-click, it should work with what you currently have.

Get User and LAN info to diaply in a dialog--
name = System.GetUserInfo();
name1 = (User.User);

LANINFO = System.GetLANInfo();
LAN = (LANINFO.Host);

name2 = name1.." and computer station "..LAN

Dialog.Message("Status", "Your user information is being logged for security purposes only.\r\n\r\nYou are being logged as user "..name2..".", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

if String.Left(name1,4) == 'abcd' then
Image.Load("Image16", "AutoPlay\\Images\\abcdefghi.PNG")
--elseif etc...
end