16.12.2022, 15:45
(Dieser Beitrag wurde zuletzt bearbeitet: 18.12.2022, 17:05 von WillWissen.
Bearbeitungsgrund: Unnötige Leerzeilen entfernt und Codetags gesetzt
)
Hallo Zusammen,
ich habe folgenden Code gefunden und kopiert und dieser funktioniert auch.
Allerdings möchte ich die Zahl 1001 im Code variabel halten, sprich ich möchte auf meinem Excel Worksheet
in einer Zelle eine Zahl eingeben z.B. 1002 und dadurch wird überall wo jetzt im Code 1001 steht eine 1002.
Ich habe dafür eine neue Variable erstellt die den Wert der Zelle annimmt aber wenn ich dann zB
Dim arr_107_neueVariable() schreibe funktioniert das nicht.
Ich bin leider ein Excel VBA Amateur...
ich habe folgenden Code gefunden und kopiert und dieser funktioniert auch.
Allerdings möchte ich die Zahl 1001 im Code variabel halten, sprich ich möchte auf meinem Excel Worksheet
in einer Zelle eine Zahl eingeben z.B. 1002 und dadurch wird überall wo jetzt im Code 1001 steht eine 1002.
Ich habe dafür eine neue Variable erstellt die den Wert der Zelle annimmt aber wenn ich dann zB
Dim arr_107_neueVariable() schreibe funktioniert das nicht.
Ich bin leider ein Excel VBA Amateur...
Code:
Public Sub readDesignresults()
Dim Filename As String
Dim Index, datalen As Long
Dim row, pos As Long
Dim arr_107_1001() As Variant
ReDim arr_107_1001(40, 0)
Dim Destination1 As Range
'Lets clear the sheet first
tab1.Cells.Clear
'The path of the file
Filename = tab1.TextBox1.Text
'To connect to the CDB we will use
Index = sof_cdb_init(Filename, 99)
'Get the data from CDB
Dim data As CBEAM_DE0
datalen = Len(data)
Do While sof_cdb_get(Index, 107, 1001, data, datalen, pos) = 0
row = row + 1
pos = pos + 1
'Redim the array for the output
ReDim Preserve arr_107_1001(40, row)
'Copy the values to array
arr_107_1001(0, row) = data.m_NR
arr_107_1001(1, row) = data.m_X
arr_107_1001(2, row) = data.m_NI
arr_107_1001(3, row) = data.m_MYI
arr_107_1001(4, row) = data.m_MZI
arr_107_1001(5, row) = data.m_SCF
arr_107_1001(6, row) = data.m_E0
arr_107_1001(7, row) = data.m_EY
arr_107_1001(8, row) = data.m_EZ
arr_107_1001(9, row) = data.m_E1
arr_107_1001(10, row) = data.m_E2
arr_107_1001(11, row) = data.m_HL
arr_107_1001(12, row) = data.m_HVM
arr_107_1001(13, row) = data.m_HX
arr_107_1001(14, row) = data.m_EDCMIN
arr_107_1001(15, row) = data.m_EDCMAX
arr_107_1001(16, row) = data.m_FCHK
arr_107_1001(17, row) = data.m_TCF
arr_107_1001(18, row) = data.m_SCN
arr_107_1001(19, row) = data.m_SCVY
arr_107_1001(20, row) = data.m_SCVZ
arr_107_1001(21, row) = data.m_SCMT
arr_107_1001(22, row) = data.m_SCMY
arr_107_1001(23, row) = data.m_SCMZ
arr_107_1001(24, row) = data.m_SCMB
arr_107_1001(25, row) = data.m_SCT2
arr_107_1001(26, row) = data.m_SCCOMB
arr_107_1001(27, row) = data.m_SCBN
arr_107_1001(28, row) = data.m_CSIGC
arr_107_1001(29, row) = data.m_CSIGT
arr_107_1001(30, row) = data.m_CTAU
arr_107_1001(31, row) = data.m_CSGV
arr_107_1001(32, row) = data.m_CSGR
arr_107_1001(33, row) = data.m_CAS
arr_107_1001(34, row) = data.m_CASL
arr_107_1001(35, row) = data.m_CCW
arr_107_1001(36, row) = data.m_CSGD
arr_107_1001(37, row) = data.m_CTAU0
arr_107_1001(38, row) = data.m_C2T
arr_107_1001(39, row) = data.m_CLASS
'Get the length of the data. This is very important!!!
datalen = Len(data)
Loop
'Set the names of header row and columns
arr_107_1001(0, 0) = "Stabnummer"
arr_107_1001(1, 0) = "Abstand zum Stabanfang"
arr_107_1001(2, 0) = "Normalkraft"
arr_107_1001(3, 0) = "Biegemoment um Y-Achse"
arr_107_1001(4, 0) = "MZI"
arr_107_1001(5, 0) = "SCF"
arr_107_1001(6, 0) = "Dehnung im Schwerpunkt"
arr_107_1001(7, 0) = "EY"
arr_107_1001(8, 0) = "EZ"
arr_107_1001(9, 0) = "Druckdehnung"
arr_107_1001(10, 0) = "Zugdehnung"
arr_107_1001(11, 0) = "Hebelarm innerer Kräfte"
arr_107_1001(12, 0) = "Versatzmaß"
arr_107_1001(13, 0) = "Druckzonenhöhe"
arr_107_1001(14, 0) = "EDCMIN"
arr_107_1001(15, 0) = "EDCMAX"
arr_107_1001(16, 0) = "FCHK"
arr_107_1001(17, 0) = "TCF"
arr_107_1001(18, 0) = "SCN"
arr_107_1001(19, 0) = "SCVY"
arr_107_1001(20, 0) = "SCVZ"
arr_107_1001(21, 0) = "SCMT"
arr_107_1001(22, 0) = "SCMY"
arr_107_1001(23, 0) = "SCMZ"
arr_107_1001(24, 0) = "SCMB"
arr_107_1001(25, 0) = "SCT2"
arr_107_1001(26, 0) = "SCCOMB"
arr_107_1001(27, 0) = "SCBN"
arr_107_1001(28, 0) = "CSIGC"
arr_107_1001(29, 0) = "CSIGT"
arr_107_1001(30, 0) = "CTAU"
arr_107_1001(31, 0) = "CSGV"
arr_107_1001(32, 0) = "CSGR"
arr_107_1001(33, 0) = "CAS"
arr_107_1001(34, 0) = "CASL"
arr_107_1001(35, 0) = "CCW"
arr_107_1001(36, 0) = "CSGD"
arr_107_1001(37, 0) = "CTAU0"
arr_107_1001(38, 0) = "C2T"
arr_107_1001(39, 0) = "CLASS"
'Output the values to range
Set Destination1 = tab1.Range("A4")
Destination1.Resize(UBound(arr_107_1001, 2) + 1, UBound(arr_107_1001, 1) + 1).Value = Application.Transpose(arr_107_1001)
'Center the output -> this is just for better looking
tab1.Cells.HorizontalAlignment = xlCenter
'Close the CDB
Call sof_cdb_close(0)
Range("E1,F1,H1,I1,O:AN").EntireColumn.Delete
Range("A5").EntireRow.Delete
End Sub