البرمجة

تخزين مصفوفات في ملف تكوين INI

To achieve this, you can use an INI file format to store your arrays. However, note that the INI file format doesn’t directly support arrays. You can simulate arrays by using section names to represent the indices and then storing the values as key-value pairs within each section. Here’s how you can modify your VBScript code to read the arrays from a config.ini file:

  1. Create a config.ini file with the following content:

    ini
    [cars] 0=Volvo 1=Saab 2=BMW [fruits] 0=Apple 1=Orange 2=Banana
  2. Modify your VBScript code to read the arrays from the config.ini file:

    vbscript
    Dim objShell: Set objShell = CreateObject("WScript.Shell") Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objIniFile: Set objIniFile = objFSO.OpenTextFile("C:\path\to\config.ini") Dim cars: Set cars = CreateObject("Scripting.Dictionary") Dim fruits: Set fruits = CreateObject("Scripting.Dictionary") Dim currentSection Do Until objIniFile.AtEndOfStream Dim line: line = objIniFile.ReadLine() If Left(line, 1) = "[" And Right(line, 1) = "]" Then currentSection = Mid(line, 2, Len(line) - 2) Else Dim parts: parts = Split(line, "=") If UBound(parts) = 1 Then If currentSection = "cars" Then cars.Add parts(0), parts(1) ElseIf currentSection = "fruits" Then fruits.Add parts(0), parts(1) End If End If End If Loop objIniFile.Close For Each key In cars.Keys Call Response.Write(cars(key) & " " & fruits(key) & "
    ") Next

This code reads the config.ini file and stores the values in two dictionaries (cars and fruits). It then iterates over the keys in the cars dictionary and prints the corresponding values from the cars and fruits dictionaries.

المزيد من المعلومات

في هذا السيناريو، يتم استخدام ملف تهيئة INI لتخزين متغيرات الصف والعمود في شكل مصفوفة. ومع ذلك، يجب أن يتم تخزين كل قيمة في مفتاح مخصص تحت قسم يمثل السطر أو العمود الخاص به.

يمكنك استخدام السيناريو التالي لتخزين مصفوفتين في ملف تهيئة INI:

  1. قم بإنشاء ملف config.ini بالمحتوى التالي:

    ini
    [row0] col0=Volvo col1=Apple [row1] col0=Saab col1=Orange [row2] col0=BMW col1=Banana
  2. قم بتعديل الكود لقراءة المصفوفتين من ملف config.ini:

    vbscript
    Dim objShell: Set objShell = CreateObject("WScript.Shell") Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objIniFile: Set objIniFile = objFSO.OpenTextFile("C:\path\to\config.ini") Dim matrix: Set matrix = CreateObject("Scripting.Dictionary") Dim currentSection, currentRow Do Until objIniFile.AtEndOfStream Dim line: line = objIniFile.ReadLine() If Left(line, 1) = "[" And Right(line, 1) = "]" Then currentSection = Mid(line, 2, Len(line) - 2) currentRow = currentSection Set matrix(currentRow) = CreateObject("Scripting.Dictionary") Else Dim parts: parts = Split(line, "=") If UBound(parts) = 1 Then matrix(currentRow).Add parts(0), parts(1) End If End If Loop objIniFile.Close For Each rowKey In matrix.Keys Dim rowValues: rowValues = matrix(rowKey) For Each colKey In rowValues.Keys Call Response.Write(rowValues(colKey) & " ") Next Call Response.Write("
    ") Next

هذا الكود يقرأ المصفوفتين من ملف config.ini ويقوم بطباعة القيم المقابلة لكل صف وعمود في المصفوفة.

مقالات ذات صلة

زر الذهاب إلى الأعلى

هذا المحتوى محمي من النسخ لمشاركته يرجى استعمال أزرار المشاركة السريعة أو تسخ الرابط !!