Len
Returns the length of a given string or 0 for Empty.
Usage
Len(expression)
expression = a string or Empty
Example
mystring = InputBox(“Enter a string to test”)
length = Len(mystring)
MsgBox “Length of the string is “ + length
e.g. where mystring is “Hello”, length will be 5.
Left
Returns a given number of characters from the left hand side of a string
Usage
Left(string,x)
string = string to use
x = number of characters
Example
mystring = InputBox(“Enter a string”)
mystring = Left(mystring, 4)
MsgBox “First four characters of your input are “ + mystring
e.g. where the input mystring is “Hello”, the output mystring will be “Hell”
Right
Returns a given number of characters from the right hand side of a string
Usage
Right(string, x)
string = string to use
x = number of characters
Example
mystring = InputBox(“Enter a string”)
mystring = Right(mystring, 4)
MsgBox “Last four characters of your input are “ + mystring
e.g. where the input mystring is “Hello”, the output mystring will be “ello”
Mid (Function)
Returns a given number of characters from the middle of a string
Usage
Mid(string, start, length)
string = string to use
start = character to start at (1 is the first character)
length = number of characters
Example
mystring = InputBox(“Enter a string”)
mystring = Mid(mystring, 2, 3)
MsgBox “The second, third, and fourth characters of your input are “ + mystring
e.g. where the input mystring is “Hello”, the output mystring will be “ell”
Mid (Statement)
Sets a given number of characters in the middle of a string equal to the same number of characters from the beginning of another string
Usage
Mid(mystring, start, length)
mystring = the string to take characters from start = character to start at (1 is the first character)
length = number of characters
Example
mystring = InputBox(“Enter a string”)
Mid(mystring, 2, 3) = "abcd"
MsgBox “Your string with abc as the second, third, and fourth characters of your input are “ + mystring
e.g. where the input mystring is “Hello”, the output mystring will be “Habco”
Trim
Removes leading and trailing spaces from a string
Usage
Trim(string)
string = string to use
Example
mystring = Trim(mystring)
e.g. where the original value of mystring was “ Hello “, the new value of mystring will be “Hello”.
LCase
Converts a string to lowercase
Usage
LCase(string)
string = string to use
Example
mystring = LCase(mystring)
e.g. where the original value of mystring was “HELLO”, the new value of mystring will be “hello”.
UCase
Converts a string to uppercase
Usage
UCase(string)
string = string to use
Example
mystring = UCase(mystring)
e.g. where the original value of mystring was “Hello”, the new value of mystring will be “HELLO”.
String
Creates a string with the specified length of the specified character
Usage
String(length, character)
length = length of string
character = character to fill string with
Example
mystring = String(5,"a")
e.g. the new value of mystring will be “aaaaa”.
Space
Creates a string with the specified length of spaces
Usage
Space(length)
length = length of string
Example
mystring = Space(5)
e.g. the new value of mystring will be “ ”.
StrConv
Returns a converted string as specified.
Usage
StrConv(string, conversion,LCID)
string = string to use
conversion = case to convert the sting to (lowercase: vbLowerCase, uppercase: vbUpperCase, proper case (first letter in caps): vbProperCase) LCID = optional. The LocaleID, if different than the system LocaleID.
Example
mystring = StrConv(mystring, vbProperCase)
e.g. where the original value of mystring was “HELLO”, the new value of mystring will be “Hello”.
سلام خدمت تمامی دوستان عزيز
بابت زحمات شما بينهايت سپاسگزارم
از وقتی عضو اين انجمن شدم، خيلی از مطالب شما استفاده کردم و ياد گرفتم
خسته نباشيد
اما سوال:
داخل يک جعبه متن Text Box . کاربر بايد 16 کاراکتر وارد کنه .اين 16 کاراکتر هم ميتونه عدد داشته باشه و هم حرف
سوال اول:
کاراکتر های حرفی محدود هستند.يعنی کاربر فقط بايد از اين حروف استفاده کنه : A,B,C,D,E,F .
چطور ميتونم کاربر رو محدود کنم تا کاراکتری نادرست وارد نکنه؟
سوال دوم :
ميخوام با زدن يک دکمه کاراکترهای 7و 8 ،نيز کاراکترهای 15 و 16 حذف شوند و مابقی در يک جعبه متن ديگه نمايش داده
بشوند.
مثال : http://i28.tinypic.com/idcao9.jpg
Private Sub Command1_Click()
Text2.Text = Mid(Text1.Text, 6, 2)
End Sub
اگر منظور شما را درست متوجه شده باشم
فکر کنم کد زیر مشکل را حل کند:
کد:Print " "" text "" " Text1.Text = " "" text "" "
باید یک فضای خالی قرار داشته باشه تا خطا نگیره .
MyString = """"
MyString = """Test"""
MyString = """" & MyString & """"
MyString = Chr(34) & MyString & Chr(34)
با تشکر از شمانه جانم، منظور saalek110 عزیز رو اشتباه متوجه شدید، اون فاصله ها را درج کردند تا بخوبی نحوه درج Quot مشخص بشه
وگرنه اصلا نیازی به فاصله نیست.
ولی به این شکلی که شما نوشتین خطا میگیره:razz:MyString = """Test"""