Create a subroutine in VB6

Asked

Viewed 202 times

0

I am trying to create a subroutine capable of reading the entire alphabet from A to Z and storing/displaying the letters read in duplicate (AA, BB, CC, ...) in VB6 but it hasn’t worked out yet.

My attempt:

Do  while alfa <> z
    alfa = alfa + a
    lstalfabeto.additem alfa
Loop
  • You can understand that you are trying to learn VB6/VBA and are having some difficulties (it is normal). I would suggest that you read the following tutorials (are in PT) (Tutorial1 and Tutorial2). I believe that at the end of reading you will be able to express your doubts better (or maybe have no doubts.)

  • The first tutorial didn’t open but I liked it has a lot I need to know about it,if you can send more links thank you bro.compliments.alex from Mozambique

1 answer

1

Assuming you have a collection of letters you want to duplicate, a way to write the subroutine will be:

Private Sub CommandButton1_Click()

    Dim alfabeto As New Collection

    ' Colecção que vai receber o alfabeto duplicado
    Dim alfabetoDuplicado As New Collection

   'Fora do escopo da pergunta mas preencher um array com o alfabeto para clareza
    For Index = 65 To 90
        alfabeto.Add Chr(Index)
    Next

    For t = 1 To alfabeto.Count
        alfabetoDuplicado.Add (alfabeto(t) + alfabeto(t))
    Next

End Sub
  • thanks ai mano worked out my cordial embraceAlex from Mozambique

  • but there is a little problem to duplicate not accept I do not know if I could give a little more help I’m doing it in vb6.

  • How can you not accept it? What error appears to you?

  • type error Mismatch in t

  • misttype match and error in "t"

  • what is Chr’s job?

  • Chr returns the character associated with the code passed. In this case 65 -> A...90 -> Z. More information about strings on VB6

  • @user7752 test again, there was a lapse in the code (the list to which objects were being added had the wrong name. It should be alphabet Upped but charDouble).

  • but it’s still the same.

  • I ran the code I posted on VB6 and I didn’t have a problem. If you could give some more information about the error you are giving, on which line, what language you are using (VB6, VBA, etc), IDE.

  • excel vba ,no error writes type Mismatch and error in t in first line.

  • I’m out of ideas, I’ve tried the code both in VB6 and VBA (Excel 2013) and found no problems. Two attempts. Paste the answer code yourself, with no more code inside a function and run to see if it works. Paste the code you are using (edit the question or paste in the comments) to analyze.

  • Private Sub Commandbutton1_click() Dim t, alphabet, alphabet As New Collection For Index = 65 To 90 lstteste.Additem Chr(Index) Next dim alphabet produced as new Collection For t = 1 To alphabet. Add (alphabet(t) + alphabet(t)) Count Next End Sub

  • The problem is in the following line: Dim t, alphabet, alphabet As New Collection This way you are declaring that t will be a Collection too. No need to declare t given that it is only an Indice, such as Index in the first for. One more detail, you cannot declare two Collections on the same line, it must be Dim alphabet as new Collection Dim alphabet Upped the new Collection .

  • the problem is even no for t = 1 to alphabet.Count gives the error type Mismatch

  • I ask again, what mistake are you making in for t = 1 to alfabeto.Count? Please note that if you are taking items from another collection (other than alfabeto) you will need to change the name here for t = 1 to alfabeto.Count. And if it’s not a collection, it might not expose the Count function and you should look for the equivalent for the data structure you’re using.

  • thank you so much for the attention, thanks so much. abs

Show 12 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.