how to make a looping with a array?
this is my program, it make a visual basic 6.
this is program to input a many song to database, and the list song in a list box.
if we selected one song in a list, otomatic specific song will appear in the textbox in the under of listbox.
after that I click a button save and the song will a save in database.
after that appear a message box as to report if the song already stored in database, then "OK"
how to make after click "OK", the process can otomatic selected to the next song and a looping process like a previous. please help me..
regards

If you are asking for code to drive the form, that is a bit beyond what this forum does.

However here are some ideas that may help
For the browse button consider using the common dialog box:
click Project then Components then find MicrosoftCommonDialog X.x and the control will be in your tool box. If you click once on the CDL on your form and hit F1 you will get a help screen. Click the Also Applies and click the Open Close option. You will probably want to preset the path so the CDL opens in MyMusic or where ever you keep your files.

If you want the next Item in the ListBox to show in the text box

        Private Sub NextSong
        Static NextSong as Integer 'The Static declaration will keep the 
                                    'value between calls to the sub
            'When some event happens call this sub
            nextsong = nextsong + 1
            If NextSong > list1.ListCount then NextSong = 1
            MyTextBox.Text = List1.ListIndex(NextSong)
        End Sub

Appoligies, that code won't work. I should have tested it first.
This should work better

Private Sub Command3_Click()
Static NextSong As Integer
    Text1.Text = List1.List(NextSong)
    'List begins at 0; Count begins at 1; first pass must be 0
    'Then reset at (.ListCount - 1)
    NextSong = NextSong + 1
    If NextSong > (List1.ListCount - 1) Then NextSong = 0
End Sub

i really don't understand the issue.
please make it more clear.

To : Klahr_R

the code already and run in my program, but I need a code for a repeat process "save" in the program.
My program now could only save the songs one by one, but I want to direct My program can save a lot of songs,
so I need a code of looping,
sorry. are you understand me? :)

regards

To : rishif2

sorry, Which part does not make you understand?
This is a program to store a lot of songs with a single click "save",
My program now could only save the songs one by one, but I want to direct my program can save a lot of songs,
so I need a code of looping,
If you still do not understand you can ask again
thank you :)

If I understan correctly:
When you click Save then you want to save each song in the list box to? your database? doesn't matter, the loop mechanics are the same.
If I have that right then something like this would probably work:

Private Sub Save_cmd_Click()
Dim Counter As Integer
    ' I've added a second list box to have something to copy to
    ' You will use the "List2.AddItem" to save as you need.
    Do While Counter < List1.ListCount 'you may need other conditions here
        ' Your code to save would replace the next line
        List2.AddItem List1.List(Counter)
        Counter = Counter + 1
    Loop
End Sub

To : Klahr_R

Im sorry, I've tried the code :)
but after I save the song first, then all next songs list in ListBox1 automatically move into Listbox2.
sorry, that's not what I want, but I want is after the first song saved, then automatically he could Selected into the next song list that is in ListBox1.
big thanks :)

Yes, you have it. YOU WILL USE the code used when you click "save" for 1 song where I used list2.
The Do While Loop indexes through your List1 saving one entry each loop.

yes, I know. I understand the logic, but I am still confused. Sorry.
This is the first time I use VB6. : o
how to repeat it so many songs can be stored just a click "Save"?

Post the code for your "Save" click.
We can fix this!

I'd post the code in save buttton. but still looping still can not walk: o
and I still can not store many songs into the database with a click of the button "Save" anyway :)
yeah I'm sure we can finish this!!!
thanks Klahr_R :)

How do you populate Text1 through Text8?

Private Sub Command6_Click()
Dim SQLTambah As String
Dim lanjut As String
Dim counter As Integer

' The do while goes here. Where is the listbox Reference?

SQLTambah = "Insert Into tbmusik (idmusik,nama,judul,singer,kategori,path,location) values ('" & Text1 & "','" & Text2 & "','" & Text7 & "','" & Text3 & "','" & Combo1 & "','" & Text5 & "','" & Text8 & "')"
    Stop ' Will stop execution here. Remove when debug complete
    conn.Execute SQLTambah


     'Repopulate the list boxes here
'The loop goes here

Form_Load
    Call Command1_Click
    MsgBox ("Data berhasil disimpan.! :D ")
    'lanjut = MsgBox("Lanjut ke Lagu berikutnya? ", vbInformation + vbYesNo, "Information")
    Call cmdMovetoRight_Click
    Text2.Text = ""
    Text3.Text = ""
    Text7.Text = ""
    Combo1.Text = ""
    Text6.Text = ""
    Text5.Text = ""
    Text8.Text = ""
    ' The Do While loop goes above as noted.
End Sub

Show me how you are using the list box.

Text1 code that is in the Form_Load, and Text1 it to make automatic numbering.
I populate Text1 through text8 by way of using "Change".
are you understand me Klahr_R ? :)

this is listbox Reference for you
`

Private Sub List2_Click()
On Error GoTo salah
Text5.Text = Dir1.Path & "\" & List2.List(List2.ListIndex)
Text2.Text = List2.List(List2.ListIndex)
Text2.Text = List2.List(List2.ListIndex)
Exit Sub
salah:
MsgBox "File yang anda pilih salah", vbCritical
End Sub

`

Show me how you are using the list box.

means that how? Can I show you to use the image? what I have to show you using code? :)

when I add the "Stop" in my code, so my program and when I Debug error, it looks like this Klahr_R

This is the look of my ListBox1

this is the look of my ListBox2 and my msgBox

I have sent you a personal message concerning how you project works.

I already receive and reply to your personal message Klahr_R
and I guess you already understand the workflow of my program,
big thanks,

but if I do not wear an array of programs?

     Private Sub NextSong
    Static NextSong as Integer 'The Static declaration will keep the
    'value between calls to the sub
    'When some event happens call this sub
    nextsong = nextsong + 1
    If NextSong > list1.ListCount then NextSong = 1
    MyTextBox.Text = List1.ListIndex(NextSong)
    End Sub

sorry in advance Klahr,
code that you can actually give this to put into my program,
but I do not understand to implement.
I hope you can understand.
do you think, what you give this code could help my problem?
My friend said that this code can actually also be used within my code,
thanks Klahr, and I am always here waiting for your help Klahr,

regards,

Vivi

d2364010a947d78e53b4dfba7b7f2a0c
My form looks like this

welcome Klahr,
sorry I'm late.
because I'm a little busy with the code that you gave yesterday that.
thank you for getting me an image of your form,
This will be more clear for me, and I could probably make reference from here Klahr,
once again thanks

regards,

oh yeah Klahr,
what this code can not be directly implemented into my program?
because according to my friend is his coding can be inserted and looping but by using a fraudulent manner,
how do Klahr?
sorry and thanks

regards,

     Private Sub NextSong
    Static NextSong as Integer 'The Static declaration will keep the
    'value between calls to the sub
    'When some event happens call this sub
    nextsong = nextsong + 1
    If NextSong > list1.ListCount then NextSong = 1
    MyTextBox.Text = List1.ListIndex(NextSong)
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.