vb中如何從文字框中提取需要的字元

時間 2022-03-11 23:30:10

1樓:文件類共創空間

參考**如下:

private sub command1_click()

dim str5 as string

str5 = getaline(text1, 1) '取得第二行的字串,以0為基底

end sub

'以下在.bas

option explicit

const em_getline = &hc4

declare function sendmessage lib "user32" alias "sendmessagea" _

(byval hwnd as long, byval wmsg as long, byval wparam as long, _

lparam as any) as long

public function getaline(text1 as textbox, byval ntx as long) as string

dim str5(255) as byte '如果您的字串 > 255 byte請自行增加該byte array

dim str6 as string, i as long

str5(0) = 255 '字串的前兩個byte存該字串的最大長度

str5(0) = 255

i = sendmessage(text1.hwnd, em_getline, ntx, str5(0))

if i = 0 then

getaline = ""

else

str6 = strconv(str5, vbunicode)

getaline = left(str6, instr(1, str6, chr(0)) - 1)

end if

end function

2樓:匿名使用者

text2.text = mid(text1.text, 1, 2)text3.

text = mid(text1.text, 3, 2)text4.text = mid(text1.

text, 5, 2)正確,「無效呼叫或者引數」就是因為mid不能從0必須從第一位開始取值

3樓:秋色烽火

text2.text = mid(text1.text,0,2)text3.

text = mid(text1.text,2,2)text4.text = mid(text1.

text,4,2)哦 抱歉 一時記錯 mid的索引是從1開始的text2.text = mid(text1.text,1,2)text3.

text = mid(text1.text,3,2)text4.text = mid(text1.

text,5,2)

4樓:閃電風暴

text2 = left(text1,2)text3 = mid(text1,2,2)text4 = right(text1,2)也可,「.text」可以省略的,不信你可以試試。

vb怎麼獲取文字框裡的字串

5樓:匿名使用者

先定義乙個變數,然後將變數設定為文字框的內容即可。

**如下(以獲取text1控制項為例):

dim str1 as string '定義字元變數private sub text1_change() '當text1字元改變時

str1 = text1.text '設定為文字框的字串end sub

6樓:匿名使用者

dim a as string

'假設文字框名稱為t1

a=t1.text

這樣a變數的字串內容便成為了文字框裡面的了

7樓:匿名使用者

dim string1 as stringprivate sub text1_change()string1 = text1.text

end sub

就這樣。

8樓:匿名使用者

可以試一下mid函式。

返回 variant (string),其中包含字串中指定數量的字元。

語法mid(string, start[, length])

mid 函式的語法具有下面的命名引數:

部分 說明

string 必要引數。字串表示式,從中返回字元。如果 string 包含 null,將返回 null。

start 必要引數。為 long。string 中被取出部分的字元位置。如果 start 超過 string 的字元數,mid 返回零長度字串 ("")。

length 可選引數;為 variant (long)。要返回的字元數。如果省略或 length 超過文字的字元數(包括 start 處的字元),將返回字串中從 start 到尾端的所有字元。

說明欲知 string 的字元數,可用 len 函式

本示例使用 mid 語句來得到某個字串中的幾個字元。

dim mystring, firstword, lastword, midwords

mystring = "mid function demo" 建立乙個字串。

firstword = mid(mystring, 1, 3) ' 返回 "mid"。

lastword = mid(mystring, 14, 4) ' 返回 "demo"。

midwords = mid(mystring, 5) ' 返回 "funcion demo"。

vb怎樣獲取text文字框中的字元數

9樓:上山谷是個村

'用len(text1.text)實現

private sub command1_click()print "文字框字元數為:"; len(text1.text)end sub

10樓:聽不清啊

使用 len(text1) 就可以獲得其中的字元數。

vb中怎麼才能從乙個字串中提取乙個字元?

11樓:手機使用者

方法有很多,下面給兩個簡單點的你。 我不是網上搜尋的,因為我本身就懂vb,這種問題也很簡單。 天籟梓軒 的方法是最沒有效率的。

我的**: private sub command1_click() if text1.text like "*.

*" then exit sub text1.text = text1.text & ".

" end sub '或者這個也行 private sub command2_click() if instr(1, text1.text, ".") > 0 then exit sub text1.

text = text1.text & "." end sub

vb 如何把文字框中的字串按行分割出來

12樓:匿名使用者

如果只是需要提取而不需要對每個資料處理的話,可以用下面這個private sub command1_click()msgbox replace(text1.text, ";", vbcrlf)

end sub

13樓:匿名使用者

如果輸入在乙個文字框中,用text1.text就可以得到全部,要想在分號的地方斷開,只需要使用split函式

14樓:匿名使用者

a= split(text1, ";")

for i=0 to ubound(a)

print a

next i

15樓:歸萱

'自己理解一下

private sub command1_click()dim arr

arr = split(text1, ";")msgbox join(arr, vbnewline)end sub

private sub form_load()text1 = "a1;a2;a3;a4;an"

end sub

16樓:勒泰號

private sub command1_click()dim str1() as string

dim txt1 as string

dim i as integer

txt1 = text1.text

str1 = split(txt1, ";")i = 0

for i = 0 to ubound(str1)print str1(i)

next i

end sub

17樓:匿名使用者

dim s as string

dim i as integer

for i = 1 to len(text1.text)s = mid(text1.text, i, 1)print s

next i

18樓:

multiline和index屬性

vb6.0 要求文字框的內容必須含有某個字元 怎麼寫**啊?

19樓:慶年工坊

private sub text1_exit(byval cancel as msforms.returnboolean)

if instr(text1.text, "a") = 0 thenmsgbox "文字必須包含a"

text1.text = ""

end if

end sub

20樓:day忘不掉的痛

在彈出框**後加入: frmmain.text1.text=輸入的埠號

怎樣用vb來提取文字中的字串 20

21樓:匿名使用者

dim tmpstr as string

tmpstr = text1

tmpstr = replace(tmpstr, "-", "")tmpstr = replace(tmpstr, "/", "")變數"tmpstr"就是你想要的效果!

函式"replace"的作用,是把一些你回不想要的字元進行答替換.

22樓:伊人尤在

public function extract_num(mystr as string) as string

extract_num = ""

for i = 1 to len(mystr)if isnumeric(mid(mystr, i, 1)) then

extract_num = extract_num + mid(mystr, i, 1)

end if

next i

end function

如何在vb中檢查文字框中包含特定字元

23樓:匿名使用者

以下為當在text1中按下按鍵時,判斷是否為m或m,如果是,則遮蔽輸入

private sub text1_keypress(keyascii as integer)

if chr(keyascii) = "m" or chr(keyascii) = "m" then

keyascii = 0

end if

end sub

以下為判斷文字框是否包含字元

private sub command1_click()if instr(lcase(text1.text), "m") > 0 then '當包含m或m時

'包含else

'不包含

end if

end sub

24樓:匿名使用者

正規表示式,字元處理必備

25樓:一見歸西

dim c as string, 是否含有字母m或m as boolean

c = "abcdemfgm"

是否含有字母m或m = (instr(c, "m") > 0 or instr(c, "m") > 0)

msgbox 是否含有字母m或m

VB中,如何實現 當滑鼠點選文字框時,文字框內的提示字元會自

option explicit dim defs as string private sub form activate defs 請在這裡輸入 定義提示字元command1.setfocus 給按鈕置焦點end sub private sub text1 gotfocus 文字框得到焦點 if t...

VB中如何輸入文字框文字輸入字元,在這字元後加上

private sub text1 change if len text1.text 4 then text1.text text1.text end sub 我精心寫了一段哦!現在針對的是text1這個控制元件只需要放一個text1控制元件在窗體上在複製這段 貼上執行就可以了。我想了3種方法,一個...

vb中怎麼儲存文字框中的內容,VB怎麼將文字框的內容儲存到txt

不能寫入乙個ini檔案或者txt檔案儲存設定麼?不涉及到資料庫。需要的話給你個小例子看。vb怎麼將文字框的內容儲存到txt private subtext1 change open d data.txt foroutput as 1 print 1,text1 close 1end sub 這樣還是...