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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
PePiConnect With a Mentor Commented:
ooops

yes,

here's the one line


if iCols = 7 or iCols = 9 then .TextMatrix(.Row, iCols) = Val(.TextMatrix(.Row, iCols)) * -1
0
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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:
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
All Courses

From novice to tech pro — start learning today.