Solved

Flex Grid and Images for Cliff

Posted on 1998-06-17
1
234 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
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

825 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