Visual Studio 2012 Form1.vb user input validation - visual-studio-2010

I have connected the sql database to my vb project and the last feature I need is to validate the user input. Two of the textboxes needs to be validated when adding a new record.
txtName is the first textbox that consists of the following format: BCO103/T1/01 . 'BCO' will always stays the same, however the rest needs to be input by the user. Letters and numbers needs to stay in exact the same place.
txtModuleID is the second textbox that needs to be validated. The data for this field looks like this: BCO120 . Yet again, BCO will always stay the same, however the 3-digit number will change.

Im sure you can use substrings for this
for example:
If txtModuleID.Text.Substring(0,2) = "BCO" And txtModuleID.Text.Substring... etc Then 'add other conditionals
blnValidated = True
Else
blnValidated = False
End If

If txtModuleID.Text.Trim.ToUpper().SubString(0,2).equals("BCO") and len(txtModuleID.Text.Trim) = 6 Then
If txtModuleID.Text.Trim.SubString(3,5).isNumeric() Then
//valid input
Else
//message prompt that last 3 digits of the input is not numeric
End If
Else
//message prompt that input has invalid format and that input must start with BCO
End IF
Substring (0, 2) means from 0 until 2... getting the sub string of the input with letters in index 0, 1 and 2. The rest follows.
As for the first input, please do expound. I didn't quite catch how you want it to be validated.

Related

If results are not >= "Number" then show blank

New to building Crystal Reports and SQL.
I'm trying to write a script to where if results is >= 12.1 then show result else show no results.
Same goes for the <=9.9.
Here is what I have so far:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then {TestResults.numresult} else "";
Below is an image showing the same results across the board. I just want the results to show when its <=9.9 or >=12.1.
Hope this make sense.
Your statement returns a number from one branch and a string from the other. It must return the same data type.
One option is to use a True/False expression in a Suppress expression.
Another option is to return a zero in the other branch and use number formatting to suppress if zero (it's a built-in option for numbers).
Another option is to modify your expression so it returns a string from both branches. For example:
if {Test.Name} = "xyz" and {TestResults.numresult}>= 12.1 then ToText({TestResults.numresult}, 1, ",") else "";
The 1 argument requests 1 decimal point. The "," argument requests a comma as thousands separator. You can adjust those to match your number formatting requirements.

Why isn't Lua reevaluating io.read("*n")?

I have some code
::redo::
io.write("input: ")
var = io.read("*n")
if var then
if var > 5 and var < 10 then io.write("yes\n") goto redo
else io.write("invalid\n") goto redo end
else io.write("invalid\n") goto redo end
that is supposed to check a numeric input value and return if it's within a certain range. If it isn't a numeric value, it's supposed to "redo" the script and ask for input again. The issue is that whenever it takes an input that isn't a number it repeats io.write("input: ") and io.write("invalid\n") unceasingly meaning it's skipping the var = io.read("*n") line. Is there a special meaning or quirk to io.read("*n") that keeps it from reevaluating? The code seems to work if replaced with io.read()
When you call io.read('*n') and it doesn't find a number, it doesn't use up the input, and any calls to io.read('*n') will read the same input over and over. You need to eat up the input and discard it by calling io.read('*l'). That will let you read new input with io.read('*n').
Another method would be to read a line with io.read('*l'), extract a number from it with string.match and convert it to a number with tonumber. Then you don't have to read the same input twice, but you'd have to decide what types of number notation you want to match. (io.read('*n') accepts various types of numbers, including hexadecimal and scientific notation.)

how to check whether the string taken through gui is a binary string in matlab?

I am working on a watermarking project that embeds binary values (i.e 1s and 0s) in the image, for which I have to take the input from the user, and check certain conditions such as
1) no empty string
2) no other character or special character
3) no number other than 0 and 1
is entered.
The following code just checks the first condition. Is there any default function in Matlab to check whether entered string is binary
int_state = get(handles.edit1,'String'); %edit1 is the Tag of edit box
if isempty(int_state)`
fprintf('Error: Enter Text first\n');
else
%computation code
end
There is no such standard function, but the check can be easily implemented.
Use this error condition:
isempty(int_state) || any(~ismember(int_state, '01'))
It returns false (no error) if the string is non-empty and composed of '0's and '1's only.
The function ismember returns a boolean array that indicates for every character in int_state whether it is contained in the second argument, '01'. The advantage is that this can be generalized to arbitrary sets of allowed characters.
I think the 2nd and 3rd can be combined together as 1 condition: your input string can only be a combination of 0 and 1? If it is so, then a small trick with findstr can do that:
if length(findstr(input_str, '1')) + length(findstr(input_str, '0')) == length(input_str)
condition_satisfied;
end
tf = isnumeric(A) returns true if A is a numeric array and false otherwise.
A numeric array is any of the numeric types and any subclasses of those types.
isnumeric(A)
ans =
1 (when A is numeric).

struggling with my pseudocode

I'm about to build a program written in pseudocode. I've already done most of the work , but I'm stuck on the code and I don't know what to do exactly. im a begginer and not everything is clear to me ...in one of the tasks i have to do , i have to make the program ask for the players name , which will be stored as a string then the program has to check if it exceeds the limit between 2/20 characters and inform the user if the input is wrong . i have researched and tried to figure out how i might be able to fix my code but i have a really short amount of time left and coudn't find anything regarding my problem :/ . this is the code ive done for this specific task. i know its wrong but i just dont know how to fix it . any help with be much appreciated . Thanks in advance :)
pseudocode:
// Getting user's name
valid = false
loop until valid is equal to true
Output" please enter your name "
Input playName
If (playName is => 1)AND(=<20)then
Valid = true
Otherwise
output "name exceeds the character limit"
I'm not sure what the syntax of your pseudo code is but :
assuming tabulation has meaning, you may have forgot to indent some lines to include them in the loop
'valid' is first declared with a lower case first letter so you may continue referencing it same way in line "Valid = true" -> "valid = true"
In the 'If' you want to test the lenght of the String and not compare the string to an int so maybe call a function length(String) that would return the length of the string or access a string.length attribute (as you wish in pseudo code)
You want the playName to be superior or equal to 2 "length(playName) >= 2" and inferior or equal to 20 "length(playname) <= 20"
The commonly used keyword meaning Otherwise is 'Else' as in
IF (Condition) THEN (code) ELSE (code)
I may modify you code like this :
// Getting user's name
valid = false
loop until valid is equal to true
Output" please enter your name "
Input playName
If (length(playName) >= 2) AND (length(playName) <= 20)
Then
valid = true
Else
output "name exceeds the character limit"

Django alpha numeric validation in form fields

I want to perform a field validation,but the conditions are
1)The field should have 10 character.
2)off these 1st 5 character should be alphabets and next 5 character should be numeric digits
I performed validation for maximum length check,but rest of the thing how to perform.Is that can be done on a single "if" condition.
I am searching for the logic in google for performing that,but not got any idea.Can any one help me to perform the same.
forms.py for length check
def clean_bookref(self):
cd=self.cleaned_data
bookref=cd.get('bookref')
if len(bookref)<10 and re.match(r'[A-z0-9]+', bookref):
raise forms.ValidationError("Should be 10 digits")
return bookref
I am using this code to do but it is not working.
Thanks
Perhaps you could use something like his:
def clean_bookref(self):
cd=self.cleaned_data
bookref=cd.get('bookref')
if not re.match(r'^[A-Za-z]{5}[0-9]{5}$',bookref) :
raise forms.ValidationError("Should be of the form abcde12345")
return bookref

Resources