判斷文字框是否為空

2021-06-22 22:02:51 字數 1280 閱讀 6774

在窗體上往往有很多文字框需要輸入資訊,一些下拉框需要選擇,對於這些資訊的輸入,我們總是需要判斷輸入的是否為空,以前,總是乙個乙個的判斷,這樣太繁瑣,也可能會丟掉其中的乙個兩個的。現在就讓我們輕鬆解決判斷文字框是否為空吧。

''' ''' 用來判斷文字框和下拉框是否為空

'''

'''

module module1

public function issomeemptytext(byval arraycontrol() as control) as boolean

dim control as new control

for each control in arraycontrol '遍歷陣列中的所有元素

if typeof control is textbox then '判斷控制項是不是文字框

if control.text.trim = "" then '判斷文字框內容是不是為空

control.focus()

return true

exit function

end if

elseif typeof control is combobox then '判斷控制項是不是組合框

if control.text.trim = "" then

return false

exit function

end if

end if

next

return false

end function

end module

呼叫函式:

dim arraycontrol() as control

redim preserve arraycontrol(5)

arraycontrol(0) = txthourrate

arraycontrol(1) = txthourtmprate

arraycontrol(2) = txtleasttime

arraycontrol(3) = txtleastm

arraycontrol(4) = txtincreasetime

arraycontrol(5) = txtpreparetime

if issomeemptytext(arraycontrol) then

exit sub

end if

注意:其中的 tag 屬性往往忘記賦值,通常賦值為文字框前面的label.text

推斷文字框是否為空

在視窗上往往有非常多文字框須要輸入資訊,一些下拉框須要選擇,對於這些資訊的輸入,我們總是須要推斷輸入的是否為空。曾經,總是乙個乙個的推斷。這樣太繁瑣。也可能會丟掉當中的乙個兩個的。如今就讓我們輕鬆解決推斷文字框是否為空吧。用來推斷文字框和下拉框是否為空 module module1 public f...

封裝重複工作 判斷文字框是否為空

重複歸一,怎麼來解釋這個詞呢!在寫這篇部落格的時候,腦子中就突然蹦出了這樣的乙個詞彙。這個詞不知道字典中有沒有,但是我的理解就是將重複的事情化為一件事情來做。記得建新 去年給我驗收系統的時候,我的電腦上總是蹦出一些沒用的窗體,每次開機都要點一遍。然後 說 不要每次都做重複的事情,做了超過兩次,就要想...

VB限制窗體內所有文字框為空

做系統的時候經常遇到限制窗體中文字框為空的情況,如果逐個判斷 寫起來會很慢,想了個比較簡單的方法,從窗體控制項的角度出發。如下 private sub cmdok click dim s as control dim frm as form for each s in frm if typeof s...