Visual Basic 6.0
Slip3
Q.1) Write a VB Program to place three text boxes onto the form at run time. Enter differentstrings in first and second textbox. On clicking to command button, concatenation of two
strings should be displayed in the third text box. [15 Marks]
Solution
Dim WithEvents cmd As CommandButton
Dim WithEvents text1 As TextBox
Dim WithEvents text2 As TextBox
Dim WithEvents text3 As TextBox
Private Sub Form_Load()
Set cmd = Controls.Add("vb.commandbutton", "cmd")
cmd.Left = 1680
cmd.Top = 1320
cmd.Caption = "concat"
cmd.Visible = True
Set text1 = Controls.Add("vb.textbox", "Text1")
text1.Left = 240
text1.Top = 240
text1.Visible = True
Set text2 = Controls.Add("vb.textbox", "Text2")
text2.Left = 2400
text2.Top = 240
text2.Visible = True
Set text3 = Controls.Add("vb.textbox", "Text3")
text3.Left = 1560
text3.Top = 2160
text3.Visible = True
End Sub
Private Sub cmd_click()
text3.Text = text1.Text + text2.Text
End Sub
Output
![]() |
Concate |
Q.2) Design a form in VB with two List boxes. Set the style property of both to 0 and 2 (Multi
select) respectively. One with the left arrow and one with the right arrow. On pressing
the left arrow the selected item from List Box 1 should be transferred to List Box 2 (only
if it does exist in List Box 2). If the right arrow is pressed, the selected item (multiple
selection are not in ListBox2) transferred to List box 1.Add items and remove items
buttons for each list. Duplicate item should not be added. [25 Marks]
Solution
Private Sub Command1_Click()
cnt = List2.ListCount
If List1.ListCount = 0 Then
MsgBox ("No more items to Move")
Exit Sub
Else
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
For j = List2.ListCount - 1 To 0 Step -1
If List2.List(j) <> List1.List(i) Then
List2.AddItem (List1.List(i))
List1.RemoveItem (i)
Else
MsgBox ("Item " & List1.Selected(i) & "already exist")
End If
Next
End If
Next
End If
End Sub
Private Sub Command2_Click()
If List2.ListCount = 0 Then
MsgBox ("No more items to Move")
Exit Sub
Else
List1.AddItem (List2.List(ListIndex))
List2.RemoveItem (ListIndex)
End If
End Sub
Private Sub Command3_Click()
List1.AddItem (InputBox("Enter Item"))
End Sub
Private Sub Command4_Click()
If List1.ListCount = 0 Then
MsgBox ("No more items to delete")
End
Else
List1.RemoveItem (0)
End If
End Sub
Private Sub Command5_Click()
If List2.ListCount = 1 Then
MsgBox "Record Is Already Present In The List.", vbOKOnly, "Result"
Else
List2.AddItem (InputBox("enter item"))
End If
End Sub
Private Sub Command6_Click()
If List2.ListCount = 0 Then
MsgBox ("No more items to delete")
End
Else
List2.RemoveItem (0)
End If
End Sub
Private Sub Command1_Click()
cnt = List2.ListCount
If List1.ListCount = 0 Then
MsgBox ("No more items to Move")
Exit Sub
Else
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
For j = List2.ListCount - 1 To 0 Step -1
If List2.List(j) <> List1.List(i) Then
List2.AddItem (List1.List(i))
List1.RemoveItem (i)
Else
MsgBox ("Item " & List1.Selected(i) & "already exist")
End If
Next
End If
Next
End If
End Sub
Private Sub Command2_Click()
If List2.ListCount = 0 Then
MsgBox ("No more items to Move")
Exit Sub
Else
List1.AddItem (List2.List(ListIndex))
List2.RemoveItem (ListIndex)
End If
End Sub
Private Sub Command3_Click()
List1.AddItem (InputBox("Enter Item"))
End Sub
Private Sub Command4_Click()
If List1.ListCount = 0 Then
MsgBox ("No more items to delete")
End
Else
List1.RemoveItem (0)
End If
End Sub
Private Sub Command5_Click()
If List2.ListCount = 1 Then
MsgBox "Record Is Already Present In The List.", vbOKOnly, "Result"
Else
List2.AddItem (InputBox("enter item"))
End If
End Sub
Private Sub Command6_Click()
If List2.ListCount = 0 Then
MsgBox ("No more items to delete")
End
Else
List2.RemoveItem (0)
End If
End Sub
Tags:
VB 6.0