GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Problem with script example conversion to JS


#1

I wanted to understand the Script Dialog creation better. I have not written VB in a while so I decided to take some of the examples and convert them into JavaScript. I did and it helped, besides being stuck at one point. I wanted to share with other members so they can use if they understand JavaScript more than VB. However, I am stuck with one part. That being, it seems like there must be different ways the objects work in JavaScript to set properties. In the radio button example (p 566 in User Manual) I cannot set a property when it not preceded by a valid event (maybe) or I should say that I can set a property that is easily set in the same function. In the function radioSelected I cannot set dlg.Control("static" + 1).enabled to false.

function OnClick(clickData) {

	var dlg  = DOpus.Dlg
	dlg.window = clickData.func.sourcetab
	dlg.template = "testdlg"
	dlg.detach = true
	dlg.Show
	
	// message loop
	
	do {
		var msg = dlg.GetMsg()
		
		if (msg.event == "click" && msg.control.substr(0, 5) == "radio") {
			radioSelected(dlg, msg)	
		} else if (msg.event == "editchange" && msg.control == "val") {
			editChanged(dlg, msg)
		}
	}
	while (msg);
}

function radioSelected(dlg, msg) {
	if (msg.data) {
		
		for (i=0;i<=5;i++) {
			if (msg.control == "radio" + i){
				dlg.Control("static" + i).enabled = true
				dlg.Control("seltext").label = "You selected option #" + i
				if(msg.focus) {
					dlg.Control("val").value = i
				}
				
			} else {
				dlg.Control("static" + i).enabled = false // cannot set this property back to flase?
			}

		
		}
		
	}
}

function editChanged(dlg, msg) {
	if (msg.focus && msg.value >= 1 && msg.value <= 5) {
		dlg.Control("radio" + msg.Value).value = true
	}
	
}



#2

I don't know what you're asking, sorry. Could you rephrase or simplify the question?


#3

Inside the radioSelected function (line 35) I cannot set the enabled property to false. It works well in the VB version shown in the manual. Thanks


#4

Please attach the whole button, including the dialog definition.

If you drag the button to a folder, while in Customize mode, the file it outputs will have everything.

Without that, we can't see what the names of the controls are or run the code ourselves.


#5

OK, forgot about that way :slightly_smiling_face: Thanks
example.dcf (6.6 KB)


#6

You've changed the loop to start from 0 but the controls are labelled "static1", "static2" etc. If you put the loop back to starting from 1 it should work.


#7

Yes... Thanks for the help. You guys are super!