Numbers in format

Hello all

I would like to transfer every value from my column 1 of my MSHFlexgrid1 in my text1 but in a specific format.


Ex:

Collumn 1 of my grid
123456
321654
456789
987654
963852


In my Text1, i would have the result:
Text1 = ('123456','321654','456789','987654','963852')

How can i do that?

This is what i have for now:

Dim s As String
Dim i As Long, j As Long, n As Long
For n = 1 To MSHFlexGrid1.Rows - 1

 If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then

        s = MSHFlexGrid1.TextMatrix(n, 1) & "/" & MSHFlexGrid1.TextMatrix(n, 1)

    Text1 = s
  
End If
Next

Open in new window



Thanks again for your help
LVL 11
Wilder1626Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

santhimurthydCommented:
Try with this

Dim s As String
Dim i As Long, j As Long, n As Long
s = "('"

For n = 1 To MSHFlexGrid1.Rows - 1
 If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
         s = s & "','" & MSHFlexGrid1.TextMatrix(n, 1)
 End If
Next
s = s & "')"

Text1 = s


0
IronhoofsCommented:
Is this what you mean?

Dim s As String
Dim i As Long, j As Long, n As Long
For n = 1 To MSHFlexGrid1.Rows - 1
   If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
      If Len(s) > 0 Then
         s = s + ","
      End If
      s = s + MSHFlexGrid1.TextMatrix(n, 1)
   End If
Next

Text1 = s

Open in new window

0
IronhoofsCommented:
Oops forgot a part of the format:
Dim s As String
Dim i As Long, j As Long, n As Long
For n = 1 To MSHFlexGrid1.Rows - 1
   If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
      If Len(s) > 0 Then
         s = s + ","
      End If
      s = s + "'" + MSHFlexGrid1.TextMatrix(n, 1) + "'"
   End If
Next

Text1 = "(" + s + ")"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Wilder1626Author Commented:
Hello santhimurthyd

I was getting an extra ",  before the value.


Ironhoofs, that code is very good :

Dim s As String
Dim i As Long, j As Long, n As Long
For n = 1 To MSHFlexGrid1.Rows - 1
   If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
      If Len(s) > 0 Then
         s = s + ","
      End If
      s = s + "'" + MSHFlexGrid1.TextMatrix(n, 1) + "'"
   End If
Next

Text1 = "(" + s + ")"

Open in new window


Let me try one last test
0
keyuCommented:
Dim s As String
Dim i As int, n As int
s = "('"

For n = 1 To MSHFlexGrid1.Rows - 1

 If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
if n=1 then

         s = "''" & MSHFlexGrid1.TextMatrix(n, 1)&"'"

else

     s = s & "',''" & MSHFlexGrid1.TextMatrix(n, 1)&"'"

end if

 End If
Next

s = s & "')"

Text1 = s

0
santhimurthydCommented:
Dim s As String
Dim i As Long, j As Long, n As Long
s = "('"

For n = 1 To MSHFlexGrid1.Rows - 1
 If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
      If Len(s) > 0 Then
            s = s & "','" & MSHFlexGrid1.TextMatrix(n, 1)
      Else
        s = MSHFlexGrid1.TextMatrix(n, 1)
      End If
 End If
Next
s = s & "')"

0
santhimurthydCommented:
Corrected code

Dim s As String
Dim i As Long, j As Long, n As Long
s = "('"

For n = 1 To MSHFlexGrid1.Rows - 1
 If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
      If Len(s) == 2 Then
        s = MSHFlexGrid1.TextMatrix(n, 1)
      Else
            s = s & "','" & MSHFlexGrid1.TextMatrix(n, 1)
      End If
 End If
Next
s = s & "')"

0
Wilder1626Author Commented:
Hello all

Ok, after many test, i'm having the best solution with this code:
Dim s As String
Dim i As Long, j As Long, n As Long
For n = 1 To MSHFlexGrid1.Rows - 1
   If MSHFlexGrid1.TextMatrix(n, 1) <> "" Then
      If Len(s) > 0 Then
         s = s + ","
      End If
      s = s + "'" + MSHFlexGrid1.TextMatrix(n, 1) + "'"
   End If
Next

Text1 = "(" + s + ")"


Thanks again to all for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.