I think, it would be better accept empty values as correct input for GetPortNumber (and similar functions). You can then remove these QueryWidgets on same widget id(s) couple of lines above and one level of if.