SHARE
TWEET

Mitaka UASG

ivan4ov4 Feb 15th, 2020 259 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Private Sub ReadMatrix(X, M As Integer, N As Integer)
  4.     Dim i%, j%
  5.     Dim Fname As String
  6.     Fname = InputBox("Insert File name:")
  7.     Open Fname For Input As #1
  8.     Input #1, M, N
  9.     ReDim X(1 To M, 1 To N)
  10.     For i = 1 To M
  11.         For j = 1 To N
  12.             Input #1, X(i, j)
  13.         Next j
  14.     Next i
  15.     Close #1
  16. End Sub
  17.  
  18.  
  19. Private Sub DisplayMatrix(SheetStr$, X, M As Integer, N As Integer)
  20.     Dim i%, j%, numText As String, toDouble As Integer, cel As Range
  21.     For i = 1 To M
  22.         For j = 1 To N
  23.             Set cel = Worksheets(SheetStr).Cells(i + 1, j)
  24.             cel.Value = X(i, j)
  25.             cel.NumberFormat = "0.00"
  26.         Next j
  27.     Next i
  28. End Sub
  29.  
  30. Private Sub AddMatrixTitle(SheetStr$)
  31.     Range("A1").Value = "Matrix A"
  32.     Range("A1").Font.Bold = True
  33.     Range("A1:C1").Merge
  34. End Sub
  35.  
  36. Private Sub PositiveOrNegative(X, M As Integer, N As Integer)
  37.     Dim positiveCount%, negativeCount%, i%, j%, Max As Double
  38.     positiveCount = 0
  39.     negativeCount = 0
  40.     For i = 1 To M
  41.         For j = 1 To N
  42.             If 0 <= X(i, j) Then positiveCount = positiveCount + 1
  43.             If 0 > X(i, j) Then negativeCount = negativeCount + 1
  44.         Next j
  45.     Next i
  46.    
  47.     If positiveCount > negativeCount Then MsgBox ("Positive") Else MsgBox ("Negative")
  48. End Sub
  49.  
  50. Sub Main()
  51.     Dim i%, j%, M%, N%
  52.     Dim X() As Double
  53.     Call ReadMatrix(X, M, N)
  54.     Call DisplayMatrix("Sheet1", X, M, N)
  55.     Call AddMatrixTitle("Sheet1")
  56.     Dim Max As Double, Min As Double, SA As Double
  57.     Call PositiveOrNegative(X, M, N)
  58. End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top