Solved

Flex Grid and Images for Cliff

Posted on 1998-06-17
1
235 Views
Last Modified: 2008-02-20
Cliff,

Your code seemed to work but I need it on columns 3, 4, and 5.  I tried to change the col nums in the code but with my limited ability can't seem to change the right numbers to make your code work on columns 3, 4, and 5.  Can you help for my remaining points?

Warren
0
Comment
Question by:clarwc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
clifABB earned 40 total points
ID: 1463553
Using my previous example, I'll change the column number to a variable, then you can just change the value of the variable as you need:

  Dim nCnt1     As Integer
  Dim sPicFile  As String
  Dim nColNum   As Integer

  nColNum = 3 'or 4 or 5
   
  For nCnt1 = 1 To MSFlexGrid1.Rows - 1
    Select Case MSFlexGrid1.TextMatrix(nCnt1, nColNum)
      Case "Red"
        sPicFile = "c:\temp\Redball.gif"
      Case "Green"
        sPicFile = "c:\temp\Greenball.gif"
      Case "Blue"
        sPicFile = "c:\temp\Blueball.gif"
      Case Else
        sPicFile = "" 
    End Select
    If sPicFile <> "" Then
      MSFlexGrid1.Col = nColNum
      MSFlexGrid1.Row = nCnt1
      Set MSFlexGrid1.CellPicture = LoadPicture(sPicFile)
      MSFlexGrid1.TextMatrix(nCnt1, nColNum) = "" 
    End If
  Next nCnt1


Or better yet, if you are going to always use 3, 4, and 5, we can make a loop:
  Dim nCnt1     As Integer
  Dim sPicFile  As String
  Dim nColNum   As Integer

  For nCnt1 = 1 To MSFlexGrid1.Rows - 1
    For nColNum = 3 To 5
      Select Case MSFlexGrid1.TextMatrix(nCnt1, nColNum)
        Case "Red"
          sPicFile = "c:\temp\Redball.gif"
        Case "Green"
          sPicFile = "c:\temp\Greenball.gif"
        Case "Blue"
          sPicFile = "c:\temp\Blueball.gif"
        Case Else
          sPicFile = "" 
      End Select
      If sPicFile <> "" Then
        MSFlexGrid1.Col = nColNum
        MSFlexGrid1.Row = nCnt1
        Set MSFlexGrid1.CellPicture = LoadPicture(sPicFile)
        MSFlexGrid1.TextMatrix(nCnt1, nColNum) = "" 
      End If
    Next nColNum
  Next nCnt1

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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