Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

VBS to Javascript 2

I have a routine used by a simple development page that I need converting to work as Javascript.  As it is it effectively concatenates two strings:

strBuild is the concateneated string so far.
strItem is the string to add and could be blank or a constant "File Not Required"
If the string is blank, null or not required then the original strBuild string is returned otherwise if strbuild is not blank a comma is added in preparation for adding the stritem then the string is returned as the function result.

Chris
function retFileNames(strBuild, strItem)

	if stritem = "File Not Required" or stritem = ""  or stritem = "None" then
		retFileNames = strbuild
	else
		if strbuild = "" then
			retFileNames = stritem
		else
			retFileNames = strBuild & "," & stritem
		end if
	end if

end function

Open in new window

0
Chris Bottomley
Asked:
Chris Bottomley
  • 4
  • 2
1 Solution
 
iGottZFrontend EngineerCommented:
function retFileNames(strBuild, strItem) {
	if (stritem == "File Not Required" || stritem == "" || stritem == "None") {
		return strbuild;
	} else {
		if (strbuild == "") {
			return stritem;
		} else {
			return strBuild + "," + stritem;
		}
	}
}

Open in new window


have fun. this should be the same but in javascript.
0
 
Chris BottomleyAuthor Commented:
Some of the variables were the wrong case, but thanks for the heads up I think I have corrected all, now when I get to (other post) the line:

strFileName = InObj.value;

All is well, used an alert to demonstrate the file name, but it never passes any data and seems to fall over since I set an alert after the line:

 strFileNames = retFileNames(strFileNames, strFileName);

And this alert is not generated .. the rest of the page then falls over for the lack of data.  I include the case corrected?

Case for the combo titles is correct.  The combos return a file path as something alomg the following lines:

startpoint\subfolder\subsubfolder\displayedcombostring.doc

Where startpoint is the root of the server

Chris
function GenerateFile() {
	var MainFrm = parent.document.frames("main") || false;
	if (!MainFrm) {
		alert("Couldn't get frame");
		return;
	}
	var DocObj = MainFrm.document;
	var InObj = DocObj.getElementById("combo1");
		alert("Step 3");
	strFileName = InObj.value;
		alert("Step 4 :> " + strFileName);
	strFileNames = retFileNames(strFileNames, strFileName);
		alert("Step 5");
	
	var InObj = DocObj.getElementById("combo2");
	strFileName = InObj.value;
	strFileNames = retFileNames(strFileNames, strFileName);
	
	strfilenames = strfilenames.replace(/\r\n/gi, ",");
	alert(strfilenames);

	document.getElementById("files").value = strfilenames;
}

function retFileNames(strBuild, strItem) {
		alert("Step 5a");
	if (strItem == "File Not Required" || strItem == "" || strItem == "None") {
		return strBuild;
	} else {
		if (strBuild == "") {
			return strItem;
		} else {
			return strBuild + "," + strItem;
		}
	}
}

Open in new window

0
 
iGottZFrontend EngineerCommented:
in line 12 you pass in strFileNames.
still i dont see where you have initialized that variable.
if you have not initialized this variable before argumenting it into retFileNames, you pretty much found the issue.

what browser are you using? if firefox / chrome / opera you could use the debug console to see where the errors are.

could you post required code for this to run so i could debug this for errors?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Chris BottomleyAuthor Commented:
Unfortunately i'm not at work so I am working with some but not all the files .. and they would need further redacting to do so - that would therefore mean a postponement till Monday... hopefully not a biggie but I sense it is so darned close!  

As for strFileNames, I wasn't initialising it as I didn't think it critical, but have done so and after fixing a few more issues am seeing the strFileNames output at line 22 fine.  The next thing was the form hidden parameter files was actually Files but on correcting I still nothing into the form parameter ... and from VBS at the same point the transfer of the string is fine and therefore it would seem to lie with the line:

document.getElementById("files").value = strfilenames;
corrected in code as:
document.getElementById("Files").value = strFileNames;

Chris
0
 
Chris BottomleyAuthor Commented:
Correction, found another bad case variable, the failure mode is a bit dramatic when it happens but thanks it's working ... will try next week on FF but for now it has switched from VBS to JS on IE and that's what I was looking for so many thanks.

Chris
0
 
Chris BottomleyAuthor Commented:
Partial accuracy since there were some case errors in teh supplied code but since the info was supplied re the sensitivity to case it is churlish to say anything other than accurate.

Chris
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now