如何确定所有参数是否都为空

时间:2016-01-07 04:03:07

标签: vb.net function

我正在创建这个函数/ sub,以便将用户添加到数据库中,但是现在我的初始方法正常工作;我相信这不是最好的解决方案。有没有更好的方法来做到这一点?谢谢专业人士!

Public Sub addNewSystemUser(_username As String, _password As String, _name As String, _restricionName As String)
    If _username <> String.Empty And _password <> String.Empty And _
     _name <> String.Empty And _restricionName <> String.Empty Then
        'SQL Execution here
    End If
End Sub

2 个答案:

答案 0 :(得分:0)

使代码更容易阅读(当然只有我的意见)你可以试试这个

#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>

bool isPowerofTwo(int);
void to_base_n(int, int);

int main(){

    //Variables
    int num, base;

    //Prompt
    printf("Please enter a number in base 10: ");
    scanf("%d", &num);
    printf("Please enter a base (2^n) to convert it to: ");
    scanf("%d", &base);

    //Precaution
    while(!isPowerofTwo(base)){
        printf("That number is not a power of 2. Please try again: ");;
        scanf("%d", &base);
    }

    if(isPowerofTwo(base)){
    //Output
    printf("The number %d (base 10) is equivalent to ", num);
    to_base_n(num, base);
    printf(" (base %d).", base);
    }

    //Return Statement
    return 0;
}

//Checks if Base is a Power of Two
bool isPowerofTwo(int base){
    while((base % 2 == 0) && base > 1){
            base = base / 2;
            if(base == 1){
                return true;
                break;
            }
        }
        return false;
}

//to_base_n
void to_base_n(int x, int n){
    int r, i = 0;
    int digits[16];
    while(x != 0){
        r = x % n;
        x = x / n;
        digits[i] = r;
        i++;
    }
    for(i = 0; i < 15; i++)
        printf("%d|",digits[i]);
}

答案 1 :(得分:0)

首先你应该验证者喜欢, &#34;必填字段验证器&#34;在您的相应页面/表格上,这样您就可以最大限度地减少工作量。

我的意思是你可以参加,

RequiredFieldValidator Control

RequiredFieldValidator控件确保必填字段不为空。它通常绑定到文本框以强制输入文本框。

此控件的语法如下:

<asp:RequiredFieldValidator ID="rfvemp" 
   runat="server" ControlToValidate ="ddlemp"
   ErrorMessage="Please choose a Employee" 
   InitialValue="Please choose a Employee">

</asp:RequiredFieldValidator>

希望你得到我对验证的真正含义。

此致