Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

msflexgrid question

Posted on 2004-10-28
16
Medium Priority
?
181 Views
Last Modified: 2013-12-26
I have a grid  with the ff columns

unit cost
total cost
unit price
total price

I want to make the values -numbers negative in that row alone

How is that done?

Thanks
0
Comment
Question by:zachvaldez
[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
  • 8
  • 7
16 Comments
 
LVL 11

Expert Comment

by:dbrckovi
ID: 12441679
Hi!

If I inderstood properly, you want to make all values in single row negative.
If so, then try this:
'------------------------------------------------
Private Sub Command1_Click()
    MakeNegative MSFlexGrid1, 3
End Sub

Sub MakeNegative(GridName As MSFlexGrid, RowNumber As Long)
   
    If RowNumber >= GridName.Rows Then
        MsgBox "Invalid Row"
    Else
        For X = 0 To GridName.Cols - 1
            GridName.TextMatrix(RowNumber, X) = 0 - Val(GridName.TextMatrix(RowNumber, X))
        Next X
    End If
End Sub
'---------------------------------------------------

If this is not what you need, then please explain a bit more.
 - What is 'ff' ?
 - Are unit cost, total cost, etc.,  Column headers or Row headers?
 - What does "values -numbers" mean?
0
 

Author Comment

by:zachvaldez
ID: 12443846
Are unit cost, total cost, etc.,  Column headers or Row headers? -- Columnheaders

What does "values -numbers" mean - input are numbers

I idea is to make the numbers appear negative in that row selected as if you are giving a discount for that row


0
 

Author Comment

by:zachvaldez
ID: 12443961
Why am is the rownumber hardocoded here?

Private Sub Command1_Click()
    MakeNegative MSFlexGrid1, 3 ---->    Can it be identified based on row selected instead of hardcodind it...?
End Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Expert Comment

by:PePi
ID: 12445454
'declare a modulelevel variable
Private fRow as Integer, fCol as Integer


Private Sub flxGrid_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    With flxGrid
        If .MouseRow = 0 Then fRow = 0: Exit Sub

        fRow = .MouseRow: fCol = .MouseCol
    End With
End Sub

Private Sub flxGrid_Click()
    If fRow = 0 Then Exit Sub       'don't process if header was clicked

    With flexGrid
        If Not IsNumeric(.TextMatrix(fRrow, fCol)) Then
            MsgBox "Cannot Convert! Data Not Numeric.", vbOkOnly+vbExclamation, "Conversion Error"
            Exit Sub
        End if

        'continue with conversion
        .Redraw = False
        .TextMatrix(fRow, fCol) = "-" & .TextMatrix(fRow, fCol)
        .Redraw = True
    End With
End Sub

HTH!!!

0
 

Author Comment

by:zachvaldez
ID: 12445743
Specifically, the location I want to convert are in col 7 & col 9

col 7 is unit cost col 9  unit price

However I do not make all of the values in this column negative only The selected line row.

col 1 to 6 are text ::
0
 
LVL 6

Expert Comment

by:PePi
ID: 12445819
when you mean Columns 7 or 9, is that 0 based? i mean in your flexgrid, the first column is actually Col = 0. I assumed that by columns 7 and 9, they are 0 based. If not, just change 7 to 6 and 9 to 8

Private Sub flxGrid_Click()
    If fRow = 0 Then Exit Sub       'don't process if header was clicked

    With flexGrid
        If fCol = 7 Or fCol = 9 Then
            If Not IsNumeric(.TextMatrix(fRrow, fCol)) Then
                MsgBox "Cannot Convert! Data Not Numeric.", vbOkOnly+vbExclamation, "Conversion Error"
                Exit Sub
            End if

            'continue with conversion
            .Redraw = False
            .TextMatrix(fRow, fCol) = "-" & .TextMatrix(fRow, fCol)
            .Redraw = True
        End If
    End With
End Sub
0
 

Author Comment

by:zachvaldez
ID: 12446141
When it hits this line it exits...

 If fCol = 7 Or fCol = 9 Then
0
 
LVL 6

Expert Comment

by:PePi
ID: 12446253
add this line before the if statement

MsgBox "fCol = " & fCol


tell me what column you cliked and what was displayed
0
 
LVL 6

Expert Comment

by:PePi
ID: 12446322
i guess Col 7 is actually Col 6 in 0 base, and Col 9 is Col 8 also in 0 base. to verify this, click on column 7 and if the display is "fCol = 6" then change the IF statement to:

If fCol = 6 Or fCol = 8 Then


0
 

Author Comment

by:zachvaldez
ID: 12446784
This is what I improvise out of your code and let me know if you can improve it...

It seems that it is changing those numbers!


 Dim iCols As Integer
 
   
    For iCols = 0 To Grid1.Cols - 1
        With Grid1
           
            If iCols = 7 Then
                .TextMatrix(.row, 7) = .TextMatrix(.row, iCols) * -1
               
            End If
            If iCols = 9 Then
                .TextMatrix(.row, 9) = .TextMatrix(.row, iCols) * -1
               
            End If
        End With
    Next iCols
0
 
LVL 6

Expert Comment

by:PePi
ID: 12446836
i thought you want it to change only when the row is clicked? which event did you put this code in?
0
 

Author Comment

by:zachvaldez
ID: 12447025
command_click

Call ChangeNumtoNegative


end sub

Isa it possible to do this in one line...

         If iCols = 7 Then
                .TextMatrix(.row, 7) = .TextMatrix(.row, iCols) * -1
               
            End If
            If iCols = 9 Then
                .TextMatrix(.row, 9) = .TextMatrix(.row, iCols) * -1
               
            End If
        End With
0
 
LVL 6

Expert Comment

by:PePi
ID: 12448035
yes,

if iCols = 7 or iCols = 9 then

end if
0
 
LVL 6

Accepted Solution

by:
PePi earned 500 total points
ID: 12448056
ooops

yes,

here's the one line


if iCols = 7 or iCols = 9 then .TextMatrix(.Row, iCols) = Val(.TextMatrix(.Row, iCols)) * -1
0
 
LVL 6

Expert Comment

by:PePi
ID: 12448094
you can also change your for next loop statement to:


For iCols = 7 To 9 Step 2

Next iCols

coz you know for a fact that you only need to process columns 7 and 9. you don't have to go thru every column
0
 

Author Comment

by:zachvaldez
ID: 12448155
Thanks! Thas was a great learning tip!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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