Excel VBA 自定義資料型別及其它

2021-06-01 09:01:07 字數 1590 閱讀 4976

→使用者自定義資料型別需要使用type語句

type lianxiren

name as string

*** as string

age as integer

phone as string

address as string

department as string

end type

sub addresslist()

dim record as lianxiren

record.name = "alex"

record.*** = "male"

record.age = 23

record.phone = "18812345678"

record.address = "blahblah"

record.department = "blahblah"

msgbox record.name

end sub

前面建立乙個自定義的資料型別,後面就可以引用

→系統常量指vba系統內部定義的常量,一般以vb為字首開頭。

例如:vbred,vbokonly等等~

→object型資料表示物件的引用,其中儲存的內容是乙個物件的位址,對於乙個object型變數賦值時,不能直接採用複製語句,而應當利用set語句為其賦值

dim sheet as object

set sheet = worksheets("sheet1")

→is 比較兩個object型變數應用的是否是同乙個變數,如果是同乙個變數,則返回true,否則為false。

→like舉例(與word中的替換有點相似)

dim mycheck

mycheck = "abbba" like "a*a" '返回truemycheck = "f" like "[a-z]" '返回truemycheck = "f" like "[!a-z]" '返回falsemycheck = "a2a" like "a#a" '返回truemycheck = "am5b" like "a[l-p]#[!c-e]" '返回truemycheck = "bat123khg" like "b?t*" '返回truemycheck = "cat123khg" like "b?t*" '返回false

→暫停語句,stop語句,語句會在stop位置停下,再按下執行可以繼續執行。。。分號也可以連線字串,而且會在數字左右加入空格

sub stop1()

dim i as integer

for i = 1 to 5

debug.print "程式第"; i; "次暫停"

stop

next

end sub

C001 Excel VBA 自定義資料型別

使用者自定義資料型別需要使用type語句 type lianxiren name asstring asstring age asinteger phone asstring address asstring department asstring endtype subaddresslist di...

自定義資料型別

include include using namespace std typedef double weight,tall struct student int main cout for int i 0 i 4 i return 0 貼上正確的輸出 這裡tall和weight都是自己可以輸入的 ...

自定義資料型別 列舉型別

學習了乙個月c語言,卻從來沒有更新過部落格,沒有總結的學習是不完整的。好了,其實我是走c 方向的,就提前看了c 的有關內容。c 除了和c語言一樣常用的資料型別,他們還有允許使用者自己來設計的一些資料型別,比如列舉型資料,結構型資料和鍊錶。我就簡單的總結下列舉型別。列舉型別允許使用者自己來定義一種資料...