Validating a number in a textbox [VB2010] - vb.net

I'm writing a part of an application for a movie ticket program.
Basically, I have to write an If statement verifying the age put in a textbox, based on a radiobox that is checked.
So, if the radiobox "PG" is checked, the age in the textbox has to be equal to or greater than 12. If "Restricted" is checked, then the textbox has to be equal to or great than 17.
Can anyone help me out with this? I'd appreciate it a lot.
Thank you!

I'm working on the assumption that this is an asp.net app?
If that's the case, the best approach is to make the radio button and the text postback by setting its Autopostback property to true. On server-side, check the combination and act accordingly.
Use a Switch statement to check the age based on the rating selected.
You could wrap these in an UpdatePanel to prevent visible post-back.
psuedo code:
rating_changed() {
checkAge();
}
txtAge_changed() {
checkAge();
}
void checkAge() {
bool ageOkay = false;
int age = Convert.ToInt32(txtAge.Text);
switch (rating.SelectedItem.Value) {
case "G":
ageOkay = true;
break;
case "PG":
if (age >= 8) ageOkay = true;
break;
case "PG-13":
if (age >= 13) ageOkay = true;
break;
}
if (ageOkay) {
//do next task
} else {
//you're not old enough
}
}

Related

How to select an action based on user ID in web page using Selenium Webdriver?

I want to compare the Id from excel with the table in the system. If the both Id are same then it will select an action in the table.
It will go to the next page until it find the user Id and select the action process. It looks like my code are wrong but I don't know which part that I need to change.
driver.findElement(By.linkText("S")).click();
String author = sh1.getRow(5).getCell(0).getStringCellValue();
String id = driver.findElement(By.xpath("//td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/thead/tr/td[2]")).getText();
do {
if(id.equals(author)){
Select view = new Select(driver.findElement(By.xpath("(//select[#name='selectedAction'])")));
view.selectByVisibleText("View");
driver.findElement(By.id("returnImage2")).click();
driver.findElement(By.linkText("Logout")).click();
driver.close();
break;
}
else {
driver.findElement(By.id("imgListNext2")).click(); }
}
while(!id.equals(author));
}
}
This is the screenshot for the table. So based on the ID in the excel which i put as an (author) then it will compare the ID in the table (User ID).
First please check that the element ids you can using are same for the current page and the next page, if not then you need to pick new ids for every page you are on and you can take a boolean which will change to true if your condition matches and till the condition is not met you can continue to check it using a while loop, like:
boolean match = false;
while(!match){
if(id.equals(author)){
//Insert the select code here and set the boolean as true like:
match = true;
}
else{
driver.findElement(By.id("imgListNext2")).click();
}
}
Please let me know if it helps.
You are testing id == author twice (once in if and once in while) and you aren't pulling the ID off the page on each new page since it's outside the loop. Something like this should fix it
driver.findElement(By.linkText("S")).click();
String author = sh1.getRow(5).getCell(0).getStringCellValue();
while (!author.equals(driver.findElement(By.xpath("//td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/thead/tr/td[2]")).getText()))
{
driver.findElement(By.id("imgListNext2")).click();
// you will probably need to add some sort of wait here... wait for stale or the like to make sure the page has changed before you pull the ID again in the while
}
Select view = new Select(driver.findElement(By.xpath("(//select[#name='selectedAction'])")));
view.selectByVisibleText("View");
driver.findElement(By.id("returnImage2")).click();
driver.findElement(By.linkText("Logout")).click();
driver.close();

How to read only the CalendarView control in UWP

On my UWP app, I have added a CalendarView and programmatically selected several dates. Now I want to make it read only to the end user. But the control does not provide such functionality and making IsEnabled = False is not an option.
Please let me know a way of making the control read only.
Thanks.
NOTE: I get this problem with the keyboard. When a user hits enter key or space bar key, Calender changes its view. I want to make it static.
Setting IsEnabled to False is the right way to go. I guess the reason that you don't want to use it is because doing so would dim the whole control. So the real question comes down to - how to disable the control while making its appearance unchanged?
Generally, the appearance of a disabled (i.e. IsEnabled="False") control is defined in the Disabled state inside its style. In your case though things will get a little bit more complicated because you need to update more than one styles as the CalendarView is a complex control.
Here is how it can be done.
First, you need to find the default style of the CalendarView control and put it inside your App.xaml. Then, search for <VisualState x:Name="Disabled"> and comment out everything within this visual state. There should be two of them 'cause the first one is for the up/down button and second one is for all the day of week text.
Apart from this, you also need to manually update the color of each CalendarViewDayItem simply because the TextBlock which is used to display the day number doesn't live inside its style.
To do this in code, go to my answer here and copy overChildren extension method, then you just need to run the following code in your Loaded event. Note you might want to give it a little bit delay so the Disabled state is applied properly.
Loaded += async (s, e) =>
{
await Task.Delay(100);
var dayItems = MyCalendarView.Children().OfType<CalendarViewDayItem>();
foreach (var dayItem in dayItems)
{
var textBlock = dayItem.Children().OfType<TextBlock>().Single();
textBlock.Foreground = new SolidColorBrush(Colors.Black);
}
};
After doing all this, your CalendarView control will now appear just as normal when it's actually disabled.
Hope this helps!
You could also try
YourCalendarView.IsHitTestVisible = false;
or
<CalendarView IsHitTestVisible="False" />
For anyone who's looking for a complete code here it is. All this is thanks to Justin XL.
static int minOne = -1;
static int plsOne = 1;
public static async Task ManipCalenderUserInterface(List<CalendarView> calenders, List<List<DateTime>> datesListByMonth)
{
try
{
CoreDispatcher coreDispatcher = Window.Current.Dispatcher;
await Task.Run(async () =>
{
await Task.Delay(1000);
//coreDispatcher is required since you're not on the main thread and you can't manip UI from worker threads
await coreDispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
int cnt = 0;
bool cont = false;
bool stop = false;
//Highlight color. I get it from my resource file
SolidColorBrush colorBrush = (SolidColorBrush)Application.Current.Resources["FgBlue1"];
//This code wrote to manipulate multiple calenders
foreach (var item in calenders)
{
var dayItems = item.Children().OfType<CalendarViewDayItem>();
var firstDayOfMonth = new DateTime(dayItems.Skip(15).First().Date.Year, dayItems.Skip(15).First().Date.Month, plsOne);
var lastDayOfMonth = firstDayOfMonth.AddMonths(plsOne).AddDays(minOne);
foreach (var dayItem in dayItems)
{
var textBlock = dayItem.Children().OfType<TextBlock>().Single();
int dayNum = System.Convert.ToInt32(textBlock.Text);
if (dayNum == 1 && !stop) cont = true;
if (cont && dayNum >= 1 && dayNum <= lastDayOfMonth.Day)
{
textBlock.Foreground = new SolidColorBrush(Colors.Black);
//Bold the today date on this month's calender
if (dayItem.Date == DateTime.Now.Date)
{
textBlock.FontWeight = FontWeights.Bold;
}
//datesListByMonth: contains all the dates need to be highlighted on th calender
if (datesListByMonth[cnt] != null && datesListByMonth[cnt].Contains(dayItem.Date.Date))
dayItem.Background = colorBrush;
}
if (cont && dayNum == lastDayOfMonth.Day)
{
cont = false;
stop = true;
}
}
cnt++;
cont = false;
stop = false;
}
});
});
}
catch (Exception ex)
{
}
}
I know this is late, but assuming that you want the user to still be able to select and scroll through months, etc. this is all you should need to do:
<CalendarView SelectionMode="Multiple">
<CalendarView.Resources>
<Style TargetType="CalendarViewDayItem">
<Setter Property="IsHitTestVisible"
Value="False" />
<Setter Property="IsTabStop"
Value="False" />
</Style>
</CalendarView.Resources>
</CalendarView>
The IsHitTestVisible setter will ensure that the DayViewItem cannot be clicked or tapped, and the IsTabStop setter prevents keyboard focus on it.
This allows you to keep the full CalendarView functionality while simply disabling user date-selection.

How to check text field empty or not with tags xcode

I am using text fields for signup it's have 7 text fields like Name, Email ID, Phone number etc.,
How do I check each and every text field not empty. I am set tags each text field start from 101 to 108
Is anyway to check that with for loop text field empty or not.
How about this?
int isError = 0;
UITextField *mTextField;
for (int i=101;i<=108;i++) {
mTextField = (UITextField*)[self.view viewWithTag:i];
if ([mTextField length]==0) {
isError = 1;
break;
}
}
if (isError==1) {
// alert there is error
} else {
// continue with logic here
}
Either you could run through your textfields with a for-loop, and check the contents of each field. If a textfield is empty at any point, you could set a boolean to false, and check the boolean after the loop is done.
if the boolean is false, you tell the user they need to fill out everything, if the boolean is true, they can continue.
Or you could write an if-statement for each field, and again, if any statement returns false, you show a warning to the user etc.

JavaFX TextField causes NullPointerException

I am using a Button with an event to control the input of a user, but I am having trouble checking whether or not the TextField is empty.
The TextField and Button are declared before the button event, like
TextField svar = new TextField();
Button submitB = new Button("submit");
This is my code:
submitB.setOnAction((event) -> {
if (svar.getText().equals(null) {
primaryStage.setTitle("No input!");
}
if (svar.getText().subSequence(0, 1).toString().toLowerCase().equals(animals.get(pic).getName().subSequence(0, 1).toString().toLowerCase())) {
primaryStage.setTitle("RÄTT!");
bild.setImage(new Image(animals.get(pic+=1).getImgsrc()));
svar.setText(null);
svar.requestFocus();
}
else
{
primaryStage.setTitle("FEL!");
svar.setText(null);
svar.requestFocus();
}
});
This piece of the code above is what in my mind should handle a situation where the TextField is empty:
if (svar.getText().equals(null) {
primaryStage.setTitle("No input!");
}
However I am still getting a NullPointerException no matter what. I've tried some different solutions which have all failed and I'm hoping someone can point me in the right direction. Thanks!
Instead of calling equals to check for null, you should use "==" like:
if (svar.getText() == null) {
Reason you get NPE (NullPointerException) is, since as you say svar.getText() is null, you are trying to call equals on null and a reason for NPE.
The correct way to do it, is not check for Null, but to check for a empty String:
if (svar.getText().equals("") {
primaryStage.setTitle("No input!");
}
Some prefer:
if ("".equals(svar.getText() {
primaryStage.setTitle("No input!");
}

How to exclude a field from spellcheck in sharepoint 2010?

I have a SharePointWebControls:UserField in a page layout that needs to be excluded from spell checking, as otherwise whenever a user is selected there are a large number of spelling errors are detected in the code-behind for the control.
It seems that in Sharepoint 2007 this behaviour could be implemented by using excludefromspellcheck = "true" but this doesn't seem to work for Sharepoint 2010. Has anyone come across the same problem and found a way around it?
Based on SpellCheckEntirePage.js, that appears to still be the way:
var elements=document.body.getElementsByTagName("*");
for (index=0; index < elements.length;++index)
{
if (null !=elements[index].getAttribute("excludeFromSpellCheck"))
{
continue;
}
// snipped - if (elements[index].tagName=="INPUT")
// snipped - else if (elements[index].tagName=="TEXTAREA")
}
But excludeFromSpellCheck is not a property of UserField, so it probably won't automatically copy down to the rendered HTML. When rendered, the UserField control is made up of several elements. I would try looking at the View Source to see if excludeFromSpellCheck is making it into the final HTML. But to set the attribute on the appropriate elements, you might need to use some jQuery like this:
$("(input|textarea)[id*='UserField']").attr("excludeFromSpellCheck", "true");
You can disable the spell check for certain fields by setting the "excludeContentFromSpellCheck" attribute to "true" on text area and input controls that you dont want to be spell checked.
I did this on all my page layouts. Now i dont get false positives anymore.
The solution is to add a div tag around the fields you don't want spell checked and adding a javascript that sets "excludeFromSpellCheck" to "true" for the elements within the div tag.
The solution i found is described here: Inaccurate Spell Check on SharePoint Publishing Pages
Joe Furner posted this solution, which has worked for me.
https://www.altamiracorp.com/blog/employee-posts/spell-checking-your-custom-lay
It excludes all PeoplePickers on the page:
function disableSpellCheckOnPeoplePickers() {
var elements = document.body.getElementsByTagName("*");
for (index = 0; index < elements.length; index++) {
if (elements[index].tagName == "INPUT" && elements[index].parentNode && elements[index].parentNode.tagName == "SPAN") {
var elem = elements[index];
if (elem.parentNode.getAttribute("NoMatchesText") != "") {
disableSpellCheckOnPeoplePickersAllChildren(elem.parentNode);
}
}
}
}
function disableSpellCheckOnPeoplePickersAllChildren(elem) {
try {
elem.setAttribute("excludeFromSpellCheck", "true");
for (var i = 0; i < elem.childNodes.length; i++) {
disableSpellCheckOnPeoplePickersAllChildren(elem.childNodes[i]);
}
}
catch(e) {
}
}
This code is working partially only,because if you put the people picker value again checking the people picker garbage value for one time.