Separating characters from a text using a separator.

Question:

An application communicates with a list or file where there are values separated by a character. Example: “value1, value2, value3, value4, …”. How can I access these values individually?

Solution:

In the desired event, use the script below:

 

Dim charPos, start, option, separator, originalText

Screen.Item(“ComboBox1”).Clear()

originalText = Screen.Item(“TextBox1”).Value
separator = Screen.Item(“Text2”).Value

charPos = 1
start = charPos

Do While charPos < Len(originalText)

option = “”

if Mid(originalText, charPos, 1) = separator Then
option = Mid(
originalText , start, charpos – start)
option = Trim(option)
start = charPos + 1
End If

charPos = charPos + 1

if charPos = Len(originalText) Then
opcao = Mid(
originalText, start, charpos – start + 1)
opcao = Trim(option)
End If

if option <> “” Then
Screen.Item(“ComboBox1”).AddItem option
End if
Loop

To see this code commented and fully functional, download the sample application attached to this article.

 

Attachments:

Sample.zip

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *