Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private Sub ReadMatrix(X, M As Integer, N As Integer)
- Dim i%, j%
- Dim Fname As String
- Fname = InputBox("Insert File name:")
- Open Fname For Input As #1
- Input #1, M, N
- ReDim X(1 To M, 1 To N)
- For i = 1 To M
- For j = 1 To N
- Input #1, X(i, j)
- Next j
- Next i
- Close #1
- End Sub
- Private Sub DisplayMatrix(SheetStr$, X, M As Integer, N As Integer)
- Dim i%, j%, numText As String, toDouble As Integer, cel As Range
- For i = 1 To M
- For j = 1 To N
- Set cel = Worksheets(SheetStr).Cells(i + 1, j)
- cel.Value = X(i, j)
- cel.NumberFormat = "0.00"
- Next j
- Next i
- End Sub
- Private Sub AddMatrixTitle(SheetStr$)
- Range("A1").Value = "Matrix A"
- Range("A1").Font.Bold = True
- Range("A1:C1").Merge
- End Sub
- Private Sub PositiveOrNegative(X, M As Integer, N As Integer)
- Dim positiveCount%, negativeCount%, i%, j%, Max As Double
- positiveCount = 0
- negativeCount = 0
- For i = 1 To M
- For j = 1 To N
- If 0 <= X(i, j) Then positiveCount = positiveCount + 1
- If 0 > X(i, j) Then negativeCount = negativeCount + 1
- Next j
- Next i
- If positiveCount > negativeCount Then MsgBox ("Positive") Else MsgBox ("Negative")
- End Sub
- Sub Main()
- Dim i%, j%, M%, N%
- Dim X() As Double
- Call ReadMatrix(X, M, N)
- Call DisplayMatrix("Sheet1", X, M, N)
- Call AddMatrixTitle("Sheet1")
- Dim Max As Double, Min As Double, SA As Double
- Call PositiveOrNegative(X, M, N)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement