Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 20th, 2004, 01:03 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default FLEXGRID...HELP!!!

i have a flexgrid...
lets say i have 3 columns..and 3 rows..
there are items such as letter G and L in each cell of the grid...
i want my system to analyze every rows..
the analyze here means:

if theres a G/L(or more) on a row,the system will count the G/L that as
1.
its the same for the second row,if theres a G/L(or more),the system
will
increase the count to 2...
and so on....

even if the row has more than one G/L
it count it as one

and the result of this count will be displayed...

from my flexgrid tht i enclosed here, i want the result to be like this :
L = 1, G = 2

my problem is how to the calculation of the G/L in the flexgrid???
i'm really new in VB and i really wanna use flexgrid...

i enclose my code here (that is not work)
Code:
visual basic code:
For X = 0 To MSFlexGrid1.Rows - 1
    For K = 0 To MSFlexGrid1.Cols - 1
'        If MSFlexGrid1.TextMatrix(X, K) = "L" Then
'            l = l + 1
'        ElseIf MSFlexGrid1.TextMatrix(X, K) = "G" Then
'            m = m + 1
'        End If
        For i = 0 To i = 1
            If MSFlexGrid1.TextMatrix(X, K) = "L" Then
                i = i + 1
            End
        For j = 0 To j = 1
            If MSFlexGrid1.TextMatrix(X, K) = "G" Then
            j = j + 1
            End If
                    Next
           Next
Next
Reply With Quote
  #2 (permalink)  
Old January 20th, 2004, 01:12 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

the second part of your code is horrible.. how can you try to loop the same variables that you are adding???

anyway.. the commented part is okay.. just add the next..

For X = 0 To MSFlexGrid1.Rows - 1
    bL = false
    bG = false
    For K = 0 To MSFlexGrid1.Cols - 1
        If MSFlexGrid1.TextMatrix(X, K) = "L" Then
            if not bL then
                l = l + 1
                bL = True
            end if
        ElseIf MSFlexGrid1.TextMatrix(X, K) = "G" Then
            if not bG then
                m = m + 1
                bG = True
            end if
        End If
    next
next

Gonzalo Bianchi
Reply With Quote
  #3 (permalink)  
Old January 20th, 2004, 01:37 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

so do u mean i have to use back the commented part+your code like this?

Code:
        If MSFlexGrid1.TextMatrix(X, K) = "L" Then
            l = l + 1
        ElseIf MSFlexGrid1.TextMatrix(X, K) = "G" Then
            m = m + 1
        End If

For X = 0 To MSFlexGrid1.Rows - 1
    bL = false
    bG = false
    For K = 0 To MSFlexGrid1.Cols - 1
        If MSFlexGrid1.TextMatrix(X, K) = "L" Then
            if not bL then
                l = l + 1
                bL = True
            end if
        ElseIf MSFlexGrid1.TextMatrix(X, K) = "G" Then
            if not bG then
                m = m + 1
                bG = True
            end if
        End If
    next
next
Reply With Quote
  #4 (permalink)  
Old January 20th, 2004, 01:42 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

just my code will do the trick...

Gonzalo Bianchi
Reply With Quote
  #5 (permalink)  
Old January 20th, 2004, 05:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I understood correctly, you want to count how many rows contain at least one letter G and how many a letter L.
This is what I would do:

dim Lcount as long
dim GCount as long

with flexgrid
  for k = 0 to .rows-1
    for j = 0 to .cols -1
       if .textmatrix(k,j) = "L" then
          lCount =lCount+1
          exit for
       endif
    next
    for j = 0 to .cols -1
       if .textmatrix(k,j) = "G" then
          GCount =GCount+1
          exit for
       endif
    next
  next

The two loops avoid the use of boolean flags, make the code a little more readable and it will be eaiser to update.
Marco
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FlexGrid amlesh Beginning VB 6 0 July 26th, 2007 01:31 AM
Vs-flexgrid MathLearner Beginning VB 6 0 June 4th, 2007 01:52 AM
Flexgrid umeshtheone Beginning VB 6 1 May 30th, 2007 06:02 AM
Sendmessage in flexgrid areejan2000 Crystal Reports 0 November 12th, 2005 02:18 AM
AllowDrop in FlexGrid agarwalmk C# 0 September 15th, 2003 09:20 AM



All times are GMT -4. The time now is 10:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.