See discussions, stats, and author profiles for this publication at: [Link]
net/publication/351198059
Functions in Visual Basic 6.0
Presentation · April 2011
DOI: 10.13140/RG.2.2.18287.56487
CITATIONS READS
0 1,118
3 authors, including:
Ali Al Sbou Ali M. H. Ghonmein
Al-Hussein Bin Talal University Al-Hussein Bin Talal University
12 PUBLICATIONS 3 CITATIONS 17 PUBLICATIONS 18 CITATIONS
SEE PROFILE SEE PROFILE
Some of the authors of this publication are also working on these related projects:
Programming Languages View project
Exploring the Relationship between MIS and Decision-Making Process atAl-Hussein Bin Talal University View project
All content following this page was uploaded by Ali M. Al-Ghonmein on 30 April 2021.
The user has requested enhancement of the downloaded file.
Functions in VB6
Functions
• Function - unit of code that returns a value
1. Built-in functions
2. User defined function.
• Built-in Functions ( Library functions ( اإلقترانات المكتبية
– String Functions
– Mathematics Functions
– Conversion Function
– Date and Time Functions
String Functions
Ucase (string): Returns a string or character converted to capital letters.
Lcase (string) :Returns a string or character converted to small letters.
Len (string): Returns an integer that contains the number of characters in a string.
Left (string , number of characters): Returns a string containing a specified number of characters
from the left side of a string.
Right (string , number of characters): Returns a string containing a specified number of
characters from the right side of a string.
Mid (string , start , number of characters) :Returns a string containing a specified number of
characters from a string.
Examples
Ucase (string) تحويل حروف النص الى احرف كبيرة
Print Ucase("Computer") ➔COMPUTER
Print Ucase(" abXYZ123&# ") ➔ABXYZ123&#
Dim x As String
x = "Ahu2012 " : Print UCase(x) ➔AHU2012
==========================================================
Lcase (string) تحويل حروف النص الى احرف صغيرة
Print Lcase("Computer") ➔computer
Print Lcase(" abXYZ123&# ") ➔abxyz123&#
Dim x As String
x = "ABcd2012 " : Print LCase(x) ➔ abcd2012
Examples
Len ( string ) )ايجاد عدد احرف النص ( طول النص
Print len(" Computer ") ➔ 8
Print len(" abXY Z123&# ") ➔ 11
Dim x As String
x = "Ahu2012 " : Print len(x) ➔ 7
==========================================================
Left ( string , number of characters) ارجاع االحرف من جهة الشمال
Print left(" Ali and ahmad ",9) ➔ Ali and a احرف9 طباعة اول
Dim X as string
X= "Mohanad" : print left(x,5) ➔ Mohan احرف5 طباعة اول
Dim x as string
Dim n as integer=3
X="Mohammad"
Print left(x,n) ➔Moh
Examples
Right(string , number of characters) ارجاع االحرف من جهة اليمين
Print Right(" Ali and ahmad ",9) ➔ and ahmad ) احرف من اليمين9( احرف9 طباعة آخر
Dim X as string
X= "Mohanad" : print Right(x,5) ➔ hanad ) احرف من اليمين5( احرف5 طباعة آخر
Dim x as string
Dim n as integer=3
X="Mohammad"
Print Right(x,n) ➔ mad
Print Left(UCase("Computer"), 5) ➔COMPU
Print Right(Left(Mid("Computer ", 1, 2), 2), 3) ➔ CO
Print len (Right(Left(Mid("Computer ", 1, 2), 2), 3)) ➔ 2
Examples
Mid ( String , start , number of character )
Print Mid(“ABCDabcdXYZ”,3,4) ➔CDab حروف4 من الحرف الثالث ابدأ وإرجاع
Dim x as string
X=“Welcome to Jordan”
Print Mid(x,3,7) ➔ lcome t
Print Mid(“ABcdeXYZ”,3) ➔cdeXYZ
Print mid(“ABC”,2,4) ➔BC
Dim x as string
Dim n as integer=3
X="Mohammad"
Print Mid(x,n,n) ➔ham
Examples
Print len(Right(Left( Mid("Computer", 1, 2), 2), 3)) ➔ 2
Print Len(left("ABCDEF",4)) ➔4
Print right(left("abcdxyz",4),2) ➔ cd
Print Mid(Right("ABCXYZ",4),3,2) ➔ YZ
Print Lcase(Mid("123456",2,1)) ➔2
Print right(left("Jordan",5),2) ➔ da
Print Lcase(Mid(left("abcABC*&#",9),3,4) ➔ cabc
Print left(ucase("Computer"),5) ➔ COMPU
Print Right(left(Mid("Computer",1,2),2),3) ➔ Co
Print Left(Right(Mid("Computer", 1, 4), 2), 3) ➔ mp
Print UCase(Left(Right(Mid("Computer", 1, 4), 2), 3)) ➔MP
Trace the following program?
Private Sub Command1_Click()
Print UCase("ABcdxXyZ123")
Print LCase("AbcdefhXYZ")
Print Len("Computer skills(2)")
Print Left("Computer", 4)
Print Right("Computer", 5)
Print Mid("Computer", 2, 4)
Print Right(Left(Mid("computer", 2, 5), 4), 2)
End Sub
Mathematics Functions
ABS(n) :returns the absolute value of n. اقتران القيمة المطلقة
SQR (n):return the square root of n. اقتران الجذر التربيعي
MOD : Divides two numbers and returns the remainder. اقتران باقي القسمة
INT(n) :The largest integer less than or equal to n. اقتران أكبر عدد صحيح
FIX(n) : The integer part of n. اقتران الجزء الصحيح
Rnd(n) :generate a random number between (0 and 1). اقتران القيمة العشوائية
VAL(n): convert a string value to number. تحول النص الى القيمة الرقمية المقابلة له
STR(n) : convert a number to a string value. تحول الرقم الى القيمة النصية
CHR(n) : returns the string corresponding to an ASCII value.
Abs function
ABS (n): ) يعطي هذا االقتران القيمة المطلقة (يحول القيمة السالبة الى قيمة موجبة
Print abs(2.5) ➔ 2.5
Print abs(-2.3) ➔ 2.3
Print abs(0) ➔0
Print abs(54) ➔ 54
Print abs(-23) ➔ 23
Print abs(-2.8)+abs(-2.2)+abs(-2) ➔7
Print abs(2.8)-abs(2.2)+abs(2) ➔2.6
Dim x as single
x=-3.55
Print abs(x) ➔3.55
Sqr and Mod function
SQR(n): يعطي هذا االقتران الجذر التربيعي للعدد اذا كان موجبا ً او صفر ويعطي خطأ اذا كان سالب
Print sqr(9) ' Print 3.
Print sqr(16) ' Print 4.
Print sqr(25) ' Print 5.
Print sqr(sqr(16)) ' Print 2.
Print sqr(-100) ' Error
X Mod Y : يعطي هذا االقتران باقي القسمة العدد االول على العدد الثاني
Print 5 mod 3 ' Print 2.
Print 20 mod 5 ' Print 0.
Print 16 mod 3 ' Print 1.
Print 9 mod 7 ' Print 2.
Print 33 mod 100 ' Print 33.
Print 7 +3 mod 4 * 2 / 8 + 5 ' Print 12.
Print 3 ^ 2 + 5 * 4 – 2 ^ 3 mod 2 + 2 / 2 ' Print 30.
➔ ➔➔Remember the priorities () , ^ , * / , \ , mod , + -
Int and Fix function
INT(n) : يعطي هذا االقتران اكبر عدد صحيح اقل من او يساوي العدد
Print int(99.8) ' Print 99.
Print int(99.2) ' Print 99.
Print int (99) ' Print 99.
Print int(-99.8) ' Print -100.
Print int(-99.2) ' Print -100.
Print int(-99) ' Print -99.
Fix(n): )هذا االقتران يعطي الجزء الصحيح فقط مهما كانت قيمة الرقم (يتخلص من الكسور
Print fix(99.8) ' Print 99.
Print fix (99.2) ' Print 99.
Print fix(99) ' Print 99.
Print fix(-99.8) ' Print -99.
Print fix(-99.2) ' Print -99.
Print fix(-99) ' Print -99.
Fix function
Rnd() function
Rnd: Generates a random number. ) اقتران العدد العشوائي (يعطي عددا ً عشوائيا ً بين الصفر و الواحد
هذا االقتران ال يتطلب تزويده بأي عدد حيث انه مبرمج إلعطاء اعداد عشوائية بين الصفر والواحد
Print Rnd ‘print a random number between (0,1) ➔ 0<n<1
Print Rnd * 35 ‘Print a random number between (0,35)➔0<n<35
Print Fix ( Rnd * 10 ) ‘Print integer random number between (0,10)➔0<=n<10
Generate 10 random number between (0,1) برنامج لطباعة عشرة اعداد عشوائية محصورة بين الصفر والواحد
For x = 1 to 10
Print Rnd
Next x
============================================================
Generate 1 random number between (0,1) 100 برنامج لطباعة عشرة اعداد عشوائية صحيحة بين الصفر و
For x = 1 to 10
Print Fix( Rnd * 100 )
Next x
Rnd() function
Generating a number in a specific range
➔ Fix ( ( Rnd()* ( HighestNumber-LowestNumber+1 ) ) + LowestNumber )
Ex. generates a random number from -5 to 8
➔ n= (Rnd * 14 - 5 )
Ex. generates a random number from 1 to 31
➔ fix( Rnd* (31 - 1 + 1) + 1) or fix (Rnd* 31 + 1)
Ex. Fix (Rnd * 31) ➔ generates a random number from 0 to 30
Val function
Val
[Link]=val([Link])
Sum=val([Link])+val([Link])
Area=4* val([Link])
Print Val("24")➔24
[Link]=val("1990")
Print val(“ABC34") ➔0
Print Val("12") + Val(" 2 ") ➔14
Print "12" + "2 " ➔122
Print Val("0 1") ➔1
Print val("123 XYZ456") ➔123
Print val("person 123") ➔0
Val function
What will be the output?
Chr and Str function
chr : تحويل الرقم الى الرمز المقابل له في جدول اسكي كود
Print chr (65) ' Print A.
Print chr (66) ' Print B.
Print chr(90) ' Print Z.
Print chr (97) ' Print a.
Print chr (99) ' Print c.
Print chr(122) ' Print z.
===========================================
Str تحويل الرقم الى نص
Print Str(66) + Str(9) ➔ 669.
Print Str(66) ➔66
ASCII Alphabet Characters
Examples
Print abs(int(-3.9)+fix(-3.9)+sqr(sqr(81))) ➔ 4
Print Abs(Fix(-4.6)-int(-5.8)) ➔ 2
Print Int(-3.9) + Fix(-3.9) + Sqr(Sqr(81)) ➔ -4
Print fix(5.7)-abs(int(3.7)-fix(-4.3))+int (-9.7)+abs(int (5.3)-fix(-4.8)) ➔-3
Print Abs(Int(3.9) + Fix(3.9) + Sqr(Sqr(81))) ➔ 9
Print Chr(67) + "abc“ ➔Cabc
Print Int(-3.9) - Fix(-3.9) * Sqr(Sqr(81)) ➔5
Print Int(-2.3) - Fix(-4.5) * Sqr(Sqr(16)) ➔5
Print Int(-2.1) - Fix(-3.8) * Sqr(36) + Int(2.7) + Fix(2.7) ➔19
Print Abs(Int(-2.1)) - Abs(Fix(-3.8) * Sqr(36)) + Int(2.7) + Fix(2.7) ➔-11
Show the output of the following programs?
For X =1 to 4 step 0.5
print Fix( X)
Next X
=================================================
Print SQR(100)*2.5
=================================================
Print –ABS(-12.7)
=================================================
Print ABS ( - 5^2-7+8*2/4+1*2 )
=================================================
Print SQR(81) ; INT(-9.7); FIX(-9.7); ABS(-6.7)
Date, Time and Now Function
Date and Time Functions
Private Sub Command1_Click()
Print Now
Print Date
Print Time
End Sub
Date and Time Functions
◼ Time :
Print time ‘[Link] pm
◼ Date :
Print date ‘19/10/2011
◼ Now :
Print now ‘19/10/2011 [Link] pm
Examples
Write a suitable code to show the following output The string is “Computer”
Hint: use ( left , right , mid,ucase )
Co
M
puter
UT
R
Private Sub Command1_Click()
Print Left("Computer", 2)
Print UCase(Mid("Computer", 3, 1))
Print Mid("Computer", 4)
Print UCase(Mid("Computer", 5, 2))
Print UCase(Right("Computer", 1))
End Sub
Round function : اقتران التقريب
اذا كان العدد
الصحيح زوجي
يقرب لألسفل
وإذا كان فردي
يقرب لألعلى
CINT function : اقتران التقريب
Examples
Private Sub Command1_Click()
x = "123456789"
Sum = Val(Left(x, 1)) + Val(Mid(x, 2, 1))
Print Sum
End Sub 3
Print 2 mod 3 ➔2
Print 1+2 mod 3 *6 ➔3
Print ucase(Mid("computer", 1, 14)) ➔COMPUTER
Print Mid(“ABCDEF", 0, 6) ➔ERROR
Print Mid(“ABCDFXZ", 5, 0) ➔ Print nothing
Print Mid(Chr(97) & UCase("example"), Len("M"), Val(3)) ➔ aEX
Print Round(2.276, 2) ➔ 2.28
Print Round(2.276, 1) ➔ 2.3
View publication stats