Solved

VB6 - Transfer cell from MSFlexgrid into TEXTbox

Posted on 2013-12-07
8
508 Views
Last Modified: 2013-12-07
Hi,

I would like to transfer all numbers from my MSHFlexgrid1 into my TextBox named clone_store so that each numbers shows one under the other.

Ex:

In MSHFlexgrid1:
1
2
3
4
5

Once in the TextBox clone_store
1
2
3
4
5


When i use the code below, it always leave an empty spaces on the first row of the textbox.

How can i fix this.

Thanks again for your help

    Dim clone As Long
    For clone = 2 To MSHFlexGrid1.Rows - 1
        If MSHFlexGrid1.TextMatrix(clone, 1) <> "" Then
            clone_store = clone_store & vbCrLf & MSHFlexGrid1.TextMatrix(clone, 1)
        End If
    Next clone

Open in new window

0
Comment
Question by:Wilder1626
  • 3
  • 3
  • 2
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39703051
Your code should work. Don't forget to set the Multiline property of the text box to True.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39703053
Hi GrahamSkan

It work but it leaves an empty space on the first row of the textbox since the Textbox always start empty.

So what it does right now is:

----------------------

1
2
3
4
5



when it should do:

----------------------
1
2
3
4
5
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39703078
Try this and if it doesn't work then please zip up and attach your project files.

Dim clone As Long
    For clone = 2 To MSHFlexGrid1.Rows - 1
        If Trim(MSHFlexGrid1.TextMatrix(clone, 1)) <> "" Then ' no spaces between the quotes
            clone_store = clone_store & vbCrLf & MSHFlexGrid1.TextMatrix(clone, 1)
        End If
    Next clone

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39703085
Hi MartinLiss

Sorry but still same result

Here is a draft example.
Form1.zip
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 total points
ID: 39703091
This is one way:
    Dim clone As Long
    For clone = 2 To MSHFlexGrid1.Rows - 1
        If MSHFlexGrid1.TextMatrix(clone, 1) <> "" Then
            If Len(clone_store) = 0 Then
                clone_store = MSHFlexGrid1.TextMatrix(clone, 1)
           Else
                clone_store = clone_store & vbCrLf & MSHFlexGrid1.TextMatrix(clone, 1)
           end if
        End If
    Next clone

Open in new window


Edit. Missing End If inserted
0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 39703116
Private Sub Transfer_Click()
    'clone_store
    Dim clone As Long
  For clone = 0 To MSHFlexGrid1.Rows - 1
        If Trim(MSHFlexGrid1.TextMatrix(clone, 1)) <> "" Then ' no spaces between the quotes
            If clone = 0 Then
                clone_store = MSHFlexGrid1.TextMatrix(clone, 1)
            Else
                clone_store = clone_store & vbCrLf & MSHFlexGrid1.TextMatrix(clone, 1)
            End If
        End If
    Next clone
End Sub

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39703123
Thanks a lot for your help

It all works.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39703126
You're welcome and I'm glad I was able to help.

Select the 'About Me' tab in my profile and you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2013
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Use closed file on desktop in vba 6 67
VB6 - Compare and highlight cell not the same 3 44
Exit a vb6 apps when a calling it apps closes 15 43
Advice in Xamarin 21 57
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now