Question:

How do you split a string into pieces in vb6?

by  |  earlier

0 LIKES UnLike

I have a Text Box called Text1 and a Command Button named Command1. I also have an Array. This is what I declared as my array:

Dim Groups(1 to 102) as String

The maximum length for Text1 is 306 characters. When the user enters a string into Text1 and presses Command1, I want the computer to make the string 306 characters long by adding a 0 to the front of it until it is 306 characters long. I then want the computer to divide the string the user typed in into groups of three and then store each group into the array. Here is an example:

If you type in Hello and pressed Command1

Groups(1) would = "000"

Groups(2) would = "000"

..................................

Groups(100) would = "000"

Groups(101) would = "0He"

Groups(102) would = "llo"

Please help me because I am in desperate need of help. If you have a question please ask because I NEED HELP! PLEASE! I will give best answer to whoever gives me an answer that eventually leads to my success.

 Tags:

   Report

1 ANSWERS


  1. it's been awhile since I've used vb so some of the commands may not be the correct syntax but maybe it'll get you started in the right direction (you can look up the commands in the help section for the correct usage/spelling).  Basically though you could do:

    UserText = "Hello"

    tempText = STRING(306-LEN(UserText), "0") & UserText

    <this should set tempText to be 306 characters, padded with a 0 so you end up with "00000000.....Hello"

    now you could do a loop of 102 iterations (306/3) and split this up into your groups.  something like >

    counter=0

    do while counter<> 102

    Group(counter+1)=MID(UserText, (counter*3)+1, 3)

    counter=counter+1

    loop

    this would loop 102 times

    first time, counter is 0 so

    group becomes group(1)  (counter+1)

    mid stmt will extract starting from 1st postiion (counter*3=0+1=1)

    next time counter is 1 so

    group becomes group(2) (counter+1)

    mid stmt will extract starting from 4th postion (counter*3=3+1=4)

    etc, etc.

    above syntax is not going to be correct for vb but hopefully if you gives you an idea of how you could accomplish what you need.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.