I need code for VB6, ComboBox if I change itemlist1 to itemlist2 automatic transfer to list 2 example
combo1.listindex
01 item list 1
02 item list 2
..etc
itemlist1
Apple
Orange
itemlist2
Book
CD desk
Hope I got this right. The combo1 contains "Item list 1" and "item list 2". If I select "Item list 1" then "Apple, Orange" are populated in combo2 and if I select "Item list 2" then "Book, CD desk" are populated in combo2. Below is the code.
Private listItem1() As String
Private listItem2() As String
Private Sub Combo1_Click()
Dim intCount As Integer
Combo2.Clear
If Combo1.ListIndex = 0 Then
For intCount = LBound(listItem1) To UBound(listItem1) - 1
Combo2.AddItem listItem1(intCount), intCount
Next intCount
ElseIf Combo1.ListIndex = 1 Then
For intCount = LBound(listItem2) To UBound(listItem2) - 1
Combo2.AddItem listItem2(intCount), intCount
Next intCount
End If
Combo2.ListIndex = 0
End Sub
Private Sub Form_Load()
Combo1.AddItem "Item list 1", 0
Combo1.AddItem "Item List 2", 1
ReDim listItem1(2)
ReDim listItem2(2)
listItem1(0) = "Apple"
listItem1(1) = "Orange"
listItem2(0) = "Book"
listItem2(1) = "CD Desk"
Combo1.ListIndex = 0
End Sub
Related
text1.text = "Mayweather vs McGregor: Los Angeles Press Conference"
text2.text returns count of space.
my custom value say = "love"
now on each button click , i want to randomly add that custom string to each position the space.
so first click
text1.text = "Mayweather vs love McGregor: Los Angeles Press Conference"
second click
text1.text = "Mayweather vs McGregor: ;love Los Angeles Press Conference"
and so on depending on the code were it detects the space then add it their only once per click.
Code:
Dim Count As Integer
Dim i As Integer
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = " " Then Count = Count + 1
Text2.Text = Count
Next
Here is a small test project:
Option Explicit
' 1 form with:
' 2 textbox controls: name=Text1 and name=Text2
' 1 command button : name=Command1
Private mstrText As String
Private Sub Command1_Click()
Static intCount As Integer 'declare as static to remember value of intCount on next click
Dim intLoop As Integer
Dim intSpace As Integer
intCount = intCount + 1
'find correct space
intLoop = 0
intSpace = 0
Do While intLoop < intCount
intSpace = InStr(intSpace + 1, mstrText, " ")
intLoop = intLoop + 1
Loop
Text1.Text = Left$(mstrText, intSpace) & "love " & Mid$(mstrText, intSpace + 1)
Caption = CStr(intSpace)
End Sub
Private Sub Form_Load()
mstrText = "Mayweather vs McGregor: Los Angeles Press Conference"
Text1.Text = mstrText
End Sub
Private Sub Text1_Change()
'show number of spaces
Dim intSpace As Integer
intSpace = Len(Text1.Text) - Len(Replace(Text1.Text, " ", ""))
Text2.Text = CStr(intSpace)
End Sub
Is this what you mean?
thanks for reading.
I'm writing a program to create a list consisting of 8 cols. so there are8 listboxes and a textbox under each one.
I want to check each textbox one by one if anyone is empty or not. ...and dunno how to do that!
I need your help!
thanks
instead of using 8 listboxes you might consider using a flexgrid control
but using 8 listboxes and 8 textboxes, you can create them as an array and check them as follows :
'1 form with with
' 1 listbox : name=List1 index=0
' 1 textbox : name=Text1 index=0
' 1 commandbutton : name=Command1
Option Explicit
Private Sub Command1_Click()
If IsEmpty Then
MsgBox "Textboxes are all empty", vbInformation, "IsEmpty"
Else
MsgBox "At least 1 Textbox is not empty", vbInformation, "IsEmpty"
End If
End Sub
Private Sub Form_Load()
Dim intIndex As Integer
For intIndex = 1 To 7
Load List1(intIndex)
Load Text1(intIndex)
List1(intIndex).Visible = True
Text1(intIndex).Visible = True
Next intIndex
Move 0, 0, 10000, 10000
End Sub
Private Function IsEmpty() As Boolean
Dim intIndex As Integer
Dim blnEmpty As Boolean
blnEmpty = True
For intIndex = 0 To Text1.Count - 1
If Len(Text1(intIndex).Text) > 0 Then
blnEmpty = False
Exit For
End If
Next intIndex
IsEmpty = blnEmpty
End Function
Private Sub Form_Resize()
Dim intIndex As Integer
Dim sngWidth As Single
Dim sngListWidth As Single, sngListHeight As Single
Dim sngTextHeight As Single
Dim sngCmdHeight As Single
sngWidth = ScaleWidth
sngListWidth = sngWidth / List1.Count
sngTextHeight = 315
sngCmdHeight = 315
sngListHeight = ScaleHeight - sngTextHeight - sngCmdHeight
For intIndex = 0 To List1.Count - 1
List1(intIndex).Move intIndex * sngListWidth, 0, sngListWidth, sngListHeight
Text1(intIndex).Move intIndex * sngListWidth, sngListHeight, sngListWidth, sngTextHeight
Next intIndex
Command1.Move 0, sngListHeight + sngTextHeight, sngWidth, sngCmdHeight
End Sub
I have a simple form with a drop down box with a list of names in it
and a picture box above that .
how can i make it when i select a name the picture
of that person shows up automatically in the picture box ?
use a user defined type containing both the name as well as the picture file, and then create an array of this type
for example :
'1 form with :
' 1 listbox : name=List1
' 1 picturebox : name=Picture1
Option Explicit
Private Type PERSON
strName As String
strPicture As String
End Type
Private mperFriend(4) As PERSON
Private Sub Form_Load()
Dim intIndex As Integer
mperFriend(0).strName = "Bob"
mperFriend(0).strPicture = "Bob.jpg"
mperFriend(1).strName = "Jane"
mperFriend(1).strPicture = "Jane.jpg"
mperFriend(2).strName = "Fred"
mperFriend(2).strPicture = "Fred.jpg"
mperFriend(3).strName = "Iris"
mperFriend(3).strPicture = "Iris.jpg"
mperFriend(4).strName = "John"
mperFriend(4).strPicture = "John.jpg"
List1.Clear
For intIndex = 0 To UBound(mperFriend)
List1.AddItem mperFriend(intIndex).strName
Next intIndex
End Sub
Private Sub List1_Click()
Caption = mperFriend(List1.ListIndex).strPicture
Picture1.Picture = LoadPicture(App.Path & "\" & mperFriend(List1.ListIndex).strPicture)
End Sub
My Code-
Private Sub Form_Load()
Dim i
For i = 1 To GetSetting("Listview", "items", "c")
ListView1.ListItems.Add i, , GetSetting("Listview", "items", "li" & i)
Next i
MsgBox ListView1.ListItems.count
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim i
Dim count
If ListView1.ListItems.count = 0 Then
count = 1
Else
count = ListView1.ListItems.count
End If
For i = 1 To ListView1.ListItems.count
SaveSetting "Listview", "items", "li" & i, ListView1.ListItems(i).Text
Next
SaveSetting "Listview", "items", "c", ListView1.ListItems.count
End Sub
I need to save the values of all rows in all cols. Please help.
use vsflexgrid instead of listview
you can save flexgrid in a file & reload it again
just see the syntax
to save
VSFlexGrid1.SaveGrid “C:\test.doc”, flexFileAll
to Load
VSFlexGrid1.loadGrid “C:\test.doc”, flexFileAll
for more info please check
http://www.fredshack.com/docs/vsflex.html
or componentone's website
I am making a music player using the list control. I want to let the user change the name of the song on the list, but i want some property of THAT list item to contain its path.
Please help me in this. Any kind of help will be appreciated. Thanks in advance.
EDIT
Private Sub AddToList(ByVal txtFileName As String)
Dim I As Integer
Dim blnFileAlreadyexists As Boolean
txtFileName = Trim(txtFileName)
If txtFileName <> "" Then
blnFileAlreadyexists = False
For I = 0 To List1.ListCount - 1
If Trim(List1.List(I)) = txtFileName Then
blnFileAlreadyexists = True
End If
Next
If Not blnFileAlreadyexists Then
List1.AddItem (txtFileName)
List1.ItemData (txtFileName)
End If
End If
End Sub
For a listbox, after you add an item set its x.itemdata(x.newindex) to the index of an array (or UDT array) that contains the corresponding data.
For a listview you can similarly use an individual items .Tag or .Key to store an array (or collection) index.
Linking a listbox example;
Option Explicit
Private Type TFileData
OriginalFilePath As String
ListBoxIndex As Integer
MoreBlaBla As String
'//any more members
End Type
Private maFiles() As TFileData
Private Sub Form_Load()
'//initial alloc
ReDim maFiles(0)
AddToList "AAAA"
AddToList "BBBB"
AddToList "AAAA"
AddToList "CCCC"
'//test by looping listbox;
Dim i As Integer
For i = 0 To List1.ListCount - 1
MsgBox List1.List(i) & " - " & maFiles(List1.ItemData(i)).OriginalFilePath
Next
'// a better type centric test;
For i = 0 To UBound(maFiles) - 1
MsgBox maFiles(i).OriginalFilePath & " - List entry: " & List1.List(maFiles(i).ListBoxIndex)
Next
End Sub
Private Sub AddToList(ByVal txtFileName As String)
Dim i As Integer
Dim blnFileAlreadyexists As Boolean
txtFileName = Trim(txtFileName)
If txtFileName <> "" Then
blnFileAlreadyexists = False
For i = 0 To List1.ListCount - 1
If Trim(List1.List(i)) = txtFileName Then
blnFileAlreadyexists = True
End If
Next
If Not blnFileAlreadyexists Then
'//add to list
List1.AddItem (txtFileName)
'//store the original value in the array;
maFiles(UBound(maFiles)).OriginalFilePath = "TEST: " & txtFileName
'//store the index of the array in the list;
List1.ItemData(List1.NewIndex) = UBound(maFiles)
'//or better store in the type
maFiles(UBound(maFiles)).ListBoxIndex = List1.NewIndex
'//increment the array for the next item;
ReDim Preserve maFiles(UBound(maFiles) + 1)
End If
End If
End Sub