PDA

View Full Version : Reiteration Issue


azmanar
12-29-2005, 11:23 AM
Hi,

I am stuck with REITERATION. I can't find anything wrong with this set of codes but it won't work.



local tMyStringValue = {sEmail,sPhone1,sPhone2,sHomeAddress,sHomeCity};

-- step through fields table
for nMyValueIndex, sMyStringValue in tMyStringValue do
-- Check for blanks and change it to "-"
if sMyStringValue == "" or sMyStringValue==nil then
sMyStringValue = " - ";
end
end



When I used IF...END for each field, it works. I have about 20 fields to reiterate, hence not economical to apply IF END for every field.

What could possibly be wrong with the Code above?

Thanks

Brett
12-29-2005, 12:00 PM
You will need to assign the value back to the original table. I imagine that the iterator is by value, not reference. I have not tried it, but what about:


local tMyStringValue = {sEmail,sPhone1,sPhone2,sHomeAddress,sHomeCity};

-- step through fields table
for nMyValueIndex, sMyStringValue in tMyStringValue do
-- Check for blanks and change it to "-"
if sMyStringValue == "" or sMyStringValue==nil then
tMyStringValue[nMyValueIndex] = " - ";
end
end

azmanar
12-29-2005, 12:18 PM
You will need to assign the value back to the original table. I imagine that the iterator is by value, not reference. I have not tried it, but what about:


local tMyStringValue = {sEmail,sPhone1,sPhone2,sHomeAddress,sHomeCity};

-- step through fields table
for nMyValueIndex, sMyStringValue in tMyStringValue do
-- Check for blanks and change it to "-"
if sMyStringValue == "" or sMyStringValue==nil then
tMyStringValue[nMyValueIndex] = " - ";
end
end


Using tMyStringValue[nMyValueIndex] I got an ERROR immediately, with the following message:

ATTEMPT TO INDEX LOCAL "myStringValue" , (a string value).

What does it mean?

Brett
12-29-2005, 12:57 PM
You probably did:

sMyStringValue[nMyValueIndex] = " - ";

instead of:

tMyStringValue[nMyValueIndex] = " - ";

azmanar
12-29-2005, 01:23 PM
You probably did:

sMyStringValue[nMyValueIndex] = " - ";

instead of:

tMyStringValue[nMyValueIndex] = " - ";

Indeed. I made the mistake and corrected it as adviced. No error prompt occurred.

However, the empty fields refused to change to "-" or to whatever I tried.

So I setup a dialog.message prompt for each fields during the iteration to be sure it has no value. Yup, the fields has no value, yet it will not change as intended.

Any other cause of such problem?

Brett
12-29-2005, 03:02 PM
Have you tried using String.Length() to determine if the string is empty? Maybe you could post a full set of code that we could test here. Perhaps dumb down the code into a small example that illustrates the problem.

azmanar
12-30-2005, 04:42 AM
Have you tried using String.Length() to determine if the string is empty? Maybe you could post a full set of code that we could test here. Perhaps dumb down the code into a small example that illustrates the problem.

Hi,

I will try with String.Length(). Then I will follow up here.

Anyway, your tip here solved my other problem related to a ComboBox. hehehe.

Thanx

azmanar
12-31-2005, 03:40 PM
Hi,

I will try with String.Length(). Then I will follow up here.

Anyway, your tip here solved my other problem related to a ComboBox. hehehe.

Thanx

Hi,

I tested with the following and it too doesn't work. Probably, my variables that follows the function are incorrect. I will try until I can resolve it.


-- step through required fields table
for nMyValueIndex, sMyStringValue in tMyStringValue do
-- Check that required fields are blank and variables are nil
nCheckStringLength = String.Length(tMyStringValue[nMyValueIndex]);
if nCheckStringLength == 0 then
-- mark field with "-"
tMyStringValue[nMyValueIndex]=" - ";
end
end


Thanks for giving me the tips.

Intrigued
12-31-2005, 08:31 PM
Try this:

-- step through required fields table
for nMyValueIndex, sMyStringValue in tMyStringValue do
-- Check that required fields are blank and variables are nil
nCheckStringLength = String.Length(sMyStringValue);
if nCheckStringLength == 0 then
-- mark field with "-"
tMyStringValue[nMyValueIndex]=" - ";
end
end

See if my minds okay this holiday evening. ;)

azmanar
01-01-2006, 06:46 AM
Try this:

-- step through required fields table
for nMyValueIndex, sMyStringValue in tMyStringValue do
-- Check that required fields are blank and variables are nil
nCheckStringLength = String.Length(sMyStringValue);
if nCheckStringLength == 0 then
-- mark field with "-"
tMyStringValue[nMyValueIndex]=" - ";
end
end

See if my minds okay this holiday evening. ;)

Well Intrigue ....it didnt work either.

I went back to basic with the following code and it wont work too:


-- Get result from Input Fields
local sEmail = Input.GetText("InputEmail");
local sPhone1 = Input.GetText("InputPhone1");
local sPhone2 = Input.GetText("InputPhone2");
local sHomeAddress = Input.GetText("InputHomeAddress");
local sHomeCity = Input.GetText("InputHomeCity");
local sHomePostCode = Input.GetText("InputHomePostCode");
local sHomeState = Input.GetText("InputHomeState");
local sMemberRegNum = Input.GetText("InputMemberRegNum");
-- this is to avoid errors when displaying ViewAll List Page
-- set empty variables to string "-" or UNKNOWN
local tMyStringTable = {sEmail, sPhone1, sPhone2, sHomeAddress, sHomeCity, sHomePostCode, sHomeState, sMemberRegNum};
-- step through fields table
-- Check blank variables
for nValueIndex, sMyStringValue in tMyStringTable do
if sMyStringValue == "" or sMyStringValue == nil then
sMyStringValue = " - ";
end
end


As though the code above is not passing new values. Same problem with other ways.

Strange enough, if I do the long way below, it works and passed the " - ".

if sEmail=="" then sEmail=" - "; end
if sPhone1=="" then sPhone1=" - "; end
if sPhone2=="" then sPhone2=" - "; end
if sHomeAddress=="" then sHomeAddress=" - "; end
if sHomeCity=="" then sHomeCity=" - "; end
if sHomePostCode=="" then sHomePostCode=" - "; end
if sHomeState=="" then sHomeState=" - "; end
if sMemberRegNum=="" then sMemberRegNum==" - "; end


The values are then passed to a SQLite query, which worked well.

sQuery = "INSERT into "..mydbTable.." values(NULL,"..sEmail.."', '"..sPhone1.."', '"..sPhone2.. "', '"..sHomeAddress.."', '"..sHomeCity.."', '"..sHomePostCode.."', '"..sHomeState.."', '"..sMemberRegNum.."')";

SQLite.Query(myDB,sQuery);


I'm perplexed. What other ways can I do it?