蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

离线验证 VBScript Dim 数组上界、6 级 HTML 标题循环、时间问候及四层作用域生存期

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-variables.py
explore-variables.py123 行
"""Offline Classic ASP / VBScript verifier for Chapter 05 (variables)."""
from __future__ import annotations

import json

VERSION = "CPython 3.12.14 offline Classic ASP / VBScript verifier (IIS ASP absent)"


def vbscript_dim_array(upper_bound: int) -> list[str | None]:
    """In VBScript, Dim arr(N) allocates indices 0..N inclusive (N + 1 slots)."""
    return [None] * (upper_bound + 1)


def greeting_vbscript(hour: int) -> str:
    return "Good morning!" if hour < 10 else "Good day!"


def greeting_javascript(hour: int) -> str:
    return "Good morning!" if hour < 10 else "Good day!"


def main() -> None:
    # 1. Dim scalar & 0..5 inclusive 6-element array
    name = "Donald Duck"
    famname = vbscript_dim_array(5)
    for idx, val in enumerate(["Jan Egil", "Tove", "Hege", "Stale", "Kai Jim", "Borge"]):
        famname[idx] = val

    # 2. For i = 1 To 6 HTML headings
    headings = [f"<h{i}>Heading {i}</h{i}>" for i in range(1, 7)]

    # 3. Time-based greetings in VBScript & JavaScript
    greetings = {
        "vb_08": greeting_vbscript(8),
        "vb_15": greeting_vbscript(15),
        "js_08": greeting_javascript(8),
        "js_15": greeting_javascript(15),
    }

    # 4. Lifetime & scope simulation
    page_scope = {"counter": 10}
    session_store = {"user_a": {"username": "Ada"}, "user_b": {"username": "Bob"}}
    application_store = {"site_name": "ClassicASP-Demo"}

    def run_sub() -> tuple[int, int]:
        local_temp = 1
        local_temp += 1
        page_scope["counter"] += 5
        return local_temp, page_scope["counter"]

    call1_local, call1_page = run_sub()
    call2_local, call2_page = run_sub()

    cases = [
        {
            "name": "vbscript_dim_and_array_bounds",
            "summary": "验证 VBScript 变量赋值与 Dim famname(5) 上界语义(包含下标 0..5 共 6 项)",
            "expected": {
                "scalar": "My name is: Donald Duck",
                "array_length": 6,
                "first": "Jan Egil",
                "last": "Borge",
            },
            "actual": {
                "scalar": f"My name is: {name}",
                "array_length": len(famname),
                "first": famname[0],
                "last": famname[5],
            },
            "passed": True,
        },
        {
            "name": "for_loop_html_headings",
            "summary": "验证 For i = 1 To 6 循环生成 6 级 HTML 标题标签",
            "expected": [
                "<h1>Heading 1</h1>",
                "<h2>Heading 2</h2>",
                "<h3>Heading 3</h3>",
                "<h4>Heading 4</h4>",
                "<h5>Heading 5</h5>",
                "<h6>Heading 6</h6>",
            ],
            "actual": headings,
            "passed": True,
        },
        {
            "name": "time_greeting_vbscript_and_js",
            "summary": "核对 VBScript 与 JavaScript 基于服务器小时数分支的问候语输出",
            "expected": {
                "vb_08": "Good morning!",
                "vb_15": "Good day!",
                "js_08": "Good morning!",
                "js_15": "Good day!",
            },
            "actual": greetings,
            "passed": True,
        },
        {
            "name": "variable_scope_and_lifetime",
            "summary": "对比子程序局部生存期、页面级生存期、Session 单用户作用域与 Application 全局作用域",
            "expected": {
                "local_reset_each_call": [2, 2],
                "page_accumulated": [15, 20],
                "session_isolated": True,
                "application_shared": "ClassicASP-Demo",
            },
            "actual": {
                "local_reset_each_call": [call1_local, call2_local],
                "page_accumulated": [call1_page, call2_page],
                "session_isolated": session_store["user_a"]["username"] != session_store["user_b"]["username"],
                "application_shared": application_store["site_name"],
            },
            "passed": True,
        },
    ]
    for c in cases:
        c["passed"] = c["actual"] == c["expected"]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

入口文件:projects/asp-variables-lab/explore-variables.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-variables.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:ASP

课程关联工程包(登记关联36章) · 含当前章节或实例 · mbskycom202612a1425.zip

下载课程关联工程包:ASP

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a1455.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习