Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

SGDT2053

Pengaturcaraan Visual

STRING
Form of data presentation which consists
of a string of characters.
All value put in TextBox String data
type.
VB6 automatically changes string to
number data type when arithmetic
operations are performed.
String Declaration
Dim Variablename As String
Or
Dim Variablename As String*20
-VB6 only provides 20 spaces of length

Example
Dim Name As String
Name = Visual Basic 6
String Operations
Combining String

Example

Dim name1 As String


Dim name2 As String
Dim name3 As String

name1 = Universiti
name2 = Utara
name3 = name1 + name2
name3 = name1 & name2
name3 = name1 + + name2
String Operations
Comparing String

Example

If Visual > Basic Then


Print Visual is larger than Basic
Else
Print Basic is larger than Visual
End If
String Operations
Comparing String based on ANSI value

StrComp(string1, string2)
0 string1 = string2
1 string1 > string2
-1 string1 < string2
String Operations
Example
Dim name1 As String
Dim name2 As String
Dim valueCompare As Integer

name1 = Visual
name2 = Basic
valueCompare = StrComp(name1,name2)
If valueCompare = 0 Then
Print name1 & same as & name2
ElseIf valueCompare = 1 Then
Print name1 & larger than & name2
Else
Print name1 & smaller than & name2
End If
String Operations
Functions in String Operation
String Operations
Functions in String Operation
Examples of String Used
A program to input name and IC number.
Output- Date of Birth, Age in Years, Place of Birth and Sex

You might also like