msflexgrid question

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
zachvaldezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dbrckoviCommented:
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
zachvaldezAuthor Commented:
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
zachvaldezAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PePiCommented:
'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
zachvaldezAuthor Commented:
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
PePiCommented:
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
zachvaldezAuthor Commented:
When it hits this line it exits...

 If fCol = 7 Or fCol = 9 Then
0
PePiCommented:
add this line before the if statement

MsgBox "fCol = " & fCol


tell me what column you cliked and what was displayed
0
PePiCommented:
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
zachvaldezAuthor Commented:
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
PePiCommented:
i thought you want it to change only when the row is clicked? which event did you put this code in?
0
zachvaldezAuthor Commented:
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
PePiCommented:
yes,

if iCols = 7 or iCols = 9 then

end if
0
PePiCommented:
ooops

yes,

here's the one line


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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PePiCommented:
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
zachvaldezAuthor Commented:
Thanks! Thas was a great learning tip!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.